Sellerjoinin.php 20 KB

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