Sellerjoinin.php 20 KB

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