Sellerjoinin.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. * ============================================================================
  6. * DSMall多用户商城
  7. * ============================================================================
  8. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  9. * 网站地址: http://www.csdeshang.com
  10. * ----------------------------------------------------------------------------
  11. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  12. * 不允许对程序代码以任何形式任何目的的再发布。
  13. * ============================================================================
  14. * 控制器
  15. */
  16. class Sellerjoinin extends MobileMember {
  17. private $joinin_detail = NULL;
  18. public function initialize() {
  19. parent::initialize();
  20. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerjoinin.lang.php');
  21. $storejoinin_model = model('storejoinin');
  22. $this->joinin_detail = $storejoinin_model->getOneStorejoinin(array('member_id' => $this->member_info['member_id']));
  23. $store_joinin_open = config('ds_config.store_joinin_open');
  24. if (!$this->joinin_detail || !$this->joinin_detail['joinin_state']) {//已经填写过入驻资料的则不跳转
  25. if ($store_joinin_open == 0) {
  26. ds_json_encode(10001, lang('store_joinin_close'));
  27. }
  28. }
  29. }
  30. /**
  31. * @api {POST} api/Sellerjoinin/get_info 获取入驻信息
  32. * @apiVersion 1.0.0
  33. * @apiGroup Sellerjoinin
  34. *
  35. * @apiHeader {String} X-DS-KEY 用户授权token
  36. *
  37. *
  38. * @apiSuccess {String} code 返回码,10000为成功
  39. * @apiSuccess {String} message 返回消息
  40. * @apiSuccess {Object} result 返回数据
  41. * @apiSuccess {Object} result.store_joinin 入驻信息(返回数据参考storejoinin表)
  42. */
  43. public function get_info() {
  44. $storejoinin_model = model('storejoinin');
  45. $joinin_detail = $this->joinin_detail;
  46. if ($joinin_detail) {
  47. $store_class_names = unserialize($joinin_detail['store_class_names']);
  48. $store_class_ids = unserialize($joinin_detail['store_class_ids']);
  49. $joinin_detail['store_class_names'] = $store_class_names ? $store_class_names : array();
  50. $joinin_detail['store_class_ids'] = $store_class_ids ? $store_class_ids : array();
  51. $joinin_detail['store_class_commis_rates'] = explode(',', $joinin_detail['store_class_commis_rates']);
  52. if ($joinin_detail['business_licence_number_electronic']) {
  53. $joinin_detail['business_licence_number_electronic_url'] = get_store_joinin_imageurl($joinin_detail['business_licence_number_electronic']);
  54. }
  55. if (!empty($joinin_detail['sg_info'])) {
  56. $store_grade_info = model('storegrade')->getOneStoregrade($joinin_detail['storegrade_id']);
  57. $joinin_detail['storegrade_price'] = $store_grade_info['storegrade_price'];
  58. } else {
  59. $joinin_detail['sg_info'] = @unserialize($joinin_detail['sg_info']);
  60. if (is_array($joinin_detail['sg_info'])) {
  61. $joinin_detail['storegrade_price'] = $joinin_detail['sg_info']['storegrade_price'];
  62. }
  63. }
  64. if($joinin_detail['joinin_state'] == STORE_JOIN_STATE_VERIFY_SUCCESS){
  65. $joinin_detail['member_available_pd'] = $this->member_info['available_predeposit'];
  66. $joinin_detail['member_available_rcb'] = $this->member_info['available_rc_balance'];
  67. $joinin_detail['member_paypwd'] = true;
  68. if (empty($this->member_info['member_paypwd'])) {
  69. $joinin_detail['member_paypwd'] = false;
  70. }
  71. $joinin_detail['pay_amount'] = round($joinin_detail['paying_amount'] - $joinin_detail['pd_amount'] - $joinin_detail['rcb_amount'],2);
  72. }
  73. }
  74. ds_json_encode(10000, '', array('store_joinin' => $joinin_detail));
  75. }
  76. /**
  77. * @api {POST} api/Sellerjoinin/step2 商家入驻第二步
  78. * @apiVersion 1.0.0
  79. * @apiGroup Sellerjoinin
  80. *
  81. * @apiHeader {String} X-DS-KEY 用户授权token
  82. *
  83. * @apiParam {Int} store_type 入驻类型(0企业1个人)
  84. * @apiParam {String} company_name 公司名
  85. * @apiParam {String} store_longitude 店铺地址纬度
  86. * @apiParam {String} store_latitude 店铺地址经度
  87. * @apiParam {Int} company_province_id 地区id
  88. * @apiParam {String} company_address 公司地区名
  89. * @apiParam {String} company_address_detail 公司地址
  90. * @apiParam {String} company_registered_capital 注册资金
  91. * @apiParam {String} contacts_name 联系人姓名
  92. * @apiParam {String} contacts_phone 联系人电话
  93. * @apiParam {String} contacts_email 联系人邮箱
  94. * @apiParam {String} business_licence_number 营业执照号
  95. * @apiParam {String} business_licence_address 营业执照地区
  96. * @apiParam {String} business_licence_start 营业执照有效期起始
  97. * @apiParam {String} business_licence_end 营业执照有效期结束
  98. * @apiParam {String} business_sphere 营业范围
  99. * @apiParam {String} business_licence_number_electronic 营业执照图片
  100. *
  101. * @apiSuccess {String} code 返回码,10000为成功
  102. * @apiSuccess {String} message 返回消息
  103. * @apiSuccess {Object} result 返回数据
  104. */
  105. public function step2() {
  106. $param = array();
  107. $param['member_name'] = $this->member_info['member_name'];
  108. $param['store_type'] = input('post.store_type');
  109. $param['company_name'] = input('post.company_name');
  110. $param['store_longitude'] = input('post.store_longitude');
  111. $param['store_latitude'] = input('post.store_latitude');
  112. $param['company_province_id'] = intval(input('post.company_province_id'));
  113. $param['company_address'] = input('post.company_address');
  114. $param['company_address_detail'] = input('post.company_address_detail');
  115. $param['company_registered_capital'] = intval(input('post.company_registered_capital'));
  116. $param['contacts_name'] = input('post.contacts_name');
  117. $param['contacts_phone'] = input('post.contacts_phone');
  118. $param['contacts_email'] = input('post.contacts_email');
  119. $param['business_licence_number'] = input('post.business_licence_number');
  120. $param['business_licence_address'] = input('post.business_licence_address');
  121. $param['business_licence_start'] = input('post.business_licence_start');
  122. $param['business_licence_end'] = input('post.business_licence_end');
  123. $param['business_sphere'] = input('post.business_sphere');
  124. $param['business_licence_number_electronic'] = input('post.business_licence_number_electronic');
  125. $this->step2_save_valid($param);
  126. $storejoinin_model = model('storejoinin');
  127. if (empty($this->joinin_detail)) {
  128. $param['member_id'] = $this->member_info['member_id'];
  129. $storejoinin_model->addStorejoinin($param);
  130. } else {
  131. $storejoinin_model->editStorejoinin($param, array('member_id' => $this->member_info['member_id']));
  132. }
  133. ds_json_encode(10000);
  134. }
  135. private function step2_save_valid($param) {
  136. $sellerjoinin_validate = ds_validate('sellerjoinin');
  137. if (!$sellerjoinin_validate->scene(input('post.store_type') ? 'step2_save_valid2' : 'step2_save_valid')->check($param)) {
  138. ds_json_encode(10001, $sellerjoinin_validate->getError());
  139. }
  140. }
  141. /**
  142. * @api {POST} api/Sellerjoinin/step3 商家入驻第三步
  143. * @apiVersion 1.0.0
  144. * @apiGroup Sellerjoinin
  145. *
  146. * @apiHeader {String} X-DS-KEY 用户授权token
  147. *
  148. * @apiParam {Int} store_type 入驻类型(0企业1个人)
  149. * @apiParam {String} settlement_bank_account_name 结算银行账户名
  150. * @apiParam {Int} settlement_bank_account_number 结算银行账号
  151. * @apiParam {String} bank_account_name 银行账户名
  152. * @apiParam {String} bank_account_number 银行账号
  153. * @apiParam {String} bank_name 银行名
  154. * @apiParam {String} bank_address 银行地区名
  155. * @apiParam {String} is_settlement_account 是否结算银行同号(0否1是)
  156. * @apiParam {String} settlement_bank_name 结算银行名
  157. * @apiParam {String} settlement_bank_address 结算银行地区名
  158. *
  159. * @apiSuccess {String} code 返回码,10000为成功
  160. * @apiSuccess {String} message 返回消息
  161. * @apiSuccess {Object} result 返回数据
  162. */
  163. public function step3() {
  164. $param = array();
  165. if (input('post.store_type')) {
  166. $param['settlement_bank_account_name'] = input('post.settlement_bank_account_name');
  167. $param['settlement_bank_account_number'] = input('post.settlement_bank_account_number');
  168. } else {
  169. $param['bank_account_name'] = input('post.bank_account_name');
  170. $param['bank_account_number'] = input('post.bank_account_number');
  171. $param['bank_name'] = input('post.bank_name');
  172. $param['bank_address'] = input('post.bank_address');
  173. $is_settlement_account = input('post.is_settlement_account');
  174. if (!empty($is_settlement_account)) {
  175. $param['is_settlement_account'] = 1;
  176. $param['settlement_bank_account_name'] = input('post.bank_account_name');
  177. $param['settlement_bank_account_number'] = input('post.bank_account_number');
  178. $param['settlement_bank_name'] = input('post.bank_name');
  179. $param['settlement_bank_address'] = input('post.bank_address');
  180. } else {
  181. $param['is_settlement_account'] = 2;
  182. $param['settlement_bank_account_name'] = input('post.settlement_bank_account_name');
  183. $param['settlement_bank_account_number'] = input('post.settlement_bank_account_number');
  184. $param['settlement_bank_name'] = input('post.settlement_bank_name');
  185. $param['settlement_bank_address'] = input('post.settlement_bank_address');
  186. }
  187. }
  188. $this->step3_save_valid($param);
  189. $storejoinin_model = model('storejoinin');
  190. $storejoinin_model->editStorejoinin($param, array('member_id' => $this->member_info['member_id']));
  191. ds_json_encode(10000);
  192. }
  193. private function step3_save_valid($param) {
  194. $sellerjoinin_validate = ds_validate('sellerjoinin');
  195. if (!$sellerjoinin_validate->scene(input('post.store_type') ? 'step3_save_valid3' : 'step3_save_valid')->check($param)) {
  196. ds_json_encode(10001, $sellerjoinin_validate->getError());
  197. }
  198. }
  199. /**
  200. * @api {POST} api/Sellerjoinin/step4 商家入驻第四步
  201. * @apiVersion 1.0.0
  202. * @apiGroup Sellerjoinin
  203. *
  204. * @apiHeader {String} X-DS-KEY 用户授权token
  205. *
  206. * @apiParam {String} seller_name 账号名
  207. * @apiParam {Int[]} store_class_ids 经营分类id
  208. * @apiParam {String[]} store_class_names 经营分类名
  209. * @apiParam {String} store_name 店铺名
  210. * @apiParam {String} store_type 店铺类型
  211. * @apiParam {Int} joinin_year 入驻年限
  212. * @apiParam {String} storegrade_id 店铺等级
  213. * @apiParam {Int} storeclass_id 店铺分类id
  214. *
  215. * @apiSuccess {String} code 返回码,10000为成功
  216. * @apiSuccess {String} message 返回消息
  217. * @apiSuccess {Object} result 返回数据
  218. */
  219. public function step4() {
  220. $store_class_ids = array();
  221. $store_class_names = array();
  222. $store_class_ids_array = input('post.store_class_ids/a'); #获取数组
  223. if (!empty($store_class_ids_array)) {
  224. foreach ($store_class_ids_array as $value) {
  225. $store_class_ids[] = $value;
  226. }
  227. }
  228. $store_class_names_array = input('post.store_class_names/a'); #获取数组
  229. if (!empty($store_class_names_array)) {
  230. foreach ($store_class_names_array as $value) {
  231. if (empty($value)) {
  232. continue;
  233. } else {
  234. $store_class_names[] = $value;
  235. }
  236. }
  237. }
  238. //取最小级分类最新分佣比例
  239. $sc_ids = array();
  240. foreach ($store_class_ids as $v) {
  241. $v = explode(',', trim($v, ','));
  242. if (!empty($v) && is_array($v)) {
  243. $sc_ids[] = end($v);
  244. }
  245. }
  246. $store_class_commis_rates = array();
  247. if (!empty($sc_ids)) {
  248. $goods_class_list = model('goodsclass')->getGoodsclassListByIds($sc_ids);
  249. if (!empty($goods_class_list) && is_array($goods_class_list)) {
  250. $sc_ids = array();
  251. foreach ($goods_class_list as $v) {
  252. $store_class_commis_rates[] = $v['commis_rate'];
  253. }
  254. }
  255. }
  256. $param = array();
  257. $param['store_type'] = input('post.store_type');
  258. $param['seller_name'] = $this->member_info['member_name'];
  259. $param['store_name'] = trim(input('post.store_name'));
  260. $param['store_class_ids'] = serialize($store_class_ids);
  261. $param['store_class_names'] = serialize($store_class_names);
  262. $param['joinin_year'] = intval(input('post.joinin_year'));
  263. $param['joinin_state'] = STORE_JOIN_STATE_NEW;
  264. $param['store_class_commis_rates'] = implode(',', $store_class_commis_rates);
  265. //取店铺等级信息
  266. $grade_list = rkcache('storegrade', true);
  267. $storegrade_id = intval(input('post.storegrade_id'));
  268. if ($storegrade_id <= 0) {
  269. ds_json_encode(10001, lang('select_store_level'));
  270. }
  271. if (!empty($grade_list[$storegrade_id])) {
  272. $param['storegrade_id'] = $storegrade_id;
  273. $param['storegrade_name'] = $grade_list[$storegrade_id]['storegrade_name'];
  274. $param['sg_info'] = serialize(array('storegrade_price' => $grade_list[$storegrade_id]['storegrade_price']));
  275. }
  276. //取最新店铺分类信息
  277. $storeclass_id = intval(input('post.storeclass_id'));
  278. if ($storeclass_id <= 0) {
  279. ds_json_encode(10001, lang('select_store_category'));
  280. }
  281. $store_class_info = model('storeclass')->getStoreclassInfo(array('storeclass_id' => $storeclass_id));
  282. if ($store_class_info) {
  283. $param['storeclass_id'] = $store_class_info['storeclass_id'];
  284. $param['storeclass_name'] = $store_class_info['storeclass_name'];
  285. $param['storeclass_bail'] = $store_class_info['storeclass_bail'];
  286. }
  287. //店铺应付款
  288. $param['paying_amount'] = floatval($grade_list[$storegrade_id]['storegrade_price']) * $param['joinin_year'] + floatval($param['storeclass_bail']);
  289. $this->step4_save_valid($param);
  290. $storejoinin_model = model('storejoinin');
  291. $storejoinin_model->editStorejoinin($param, array('member_id' => $this->member_info['member_id']));
  292. ds_json_encode(10000);
  293. }
  294. private function step4_save_valid($param) {
  295. $sellerjoinin_validate = ds_validate('sellerjoinin');
  296. if (!$sellerjoinin_validate->scene(input('post.store_type') ? 'step4_save_valid4' : 'step4_save_valid')->check($param)) {
  297. ds_json_encode(10001, $sellerjoinin_validate->getError());
  298. }
  299. }
  300. /**
  301. * @api {POST} api/Sellerjoinin/pay_save 保存付款凭证
  302. * @apiVersion 1.0.0
  303. * @apiGroup Sellerjoinin
  304. *
  305. * @apiHeader {String} X-DS-KEY 用户授权token
  306. *
  307. * @apiParam {String} paying_money_certificate 付款截图
  308. * @apiParam {String} paying_money_certificate_explain 付款备注
  309. *
  310. * @apiSuccess {String} code 返回码,10000为成功
  311. * @apiSuccess {String} message 返回消息
  312. * @apiSuccess {Object} result 返回数据
  313. */
  314. public function pay_save() {
  315. $param = array();
  316. $param['paying_money_certificate'] = input('post.paying_money_certificate');
  317. $param['paying_money_certificate_explain'] = input('post.paying_money_certificate_explain');
  318. $param['joinin_state'] = STORE_JOIN_STATE_PAY;
  319. if (empty($param['paying_money_certificate'])) {
  320. ds_json_encode(10001, lang('paying_money_certificate_empty'));
  321. }
  322. $storejoinin_model = model('storejoinin');
  323. $storejoinin_model->editStorejoinin($param, array('member_id' => $this->member_info['member_id']));
  324. ds_json_encode(10000);
  325. }
  326. /**
  327. * @api {POST} api/Sellerjoinin/upload_image 上传图片
  328. * @apiVersion 1.0.0
  329. * @apiGroup Sellerjoinin
  330. *
  331. * @apiHeader {String} X-DS-KEY 用户授权token
  332. *
  333. * @apiParam {File} file 图片
  334. *
  335. * @apiSuccess {String} code 返回码,10000为成功
  336. * @apiSuccess {String} message 返回消息
  337. * @apiSuccess {Object} result 返回数据
  338. *
  339. */
  340. public function upload_image() {
  341. $file = 'file';
  342. //上传文件保存路径
  343. $pic_name = '';
  344. if (!empty($_FILES[$file]['name'])) {
  345. //设置特殊图片名称
  346. $file_name = $this->member_info['member_id'] . '_' . date('YmdHis') . rand(10000, 99999) . '.png';
  347. $res = ds_upload_pic('home' . DIRECTORY_SEPARATOR . 'store_joinin', $file, $file_name);
  348. if ($res['code']) {
  349. $pic_name = $res['data']['file_name'];
  350. } else {
  351. ds_json_encode(10001, $res['msg']);
  352. }
  353. }
  354. ds_json_encode(10000, '', array('path' => $pic_name, 'url' => get_store_joinin_imageurl($pic_name)));
  355. }
  356. }
  357. ?>