Sellerjoinin.php 21 KB

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