Sellerjoinin.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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. $res = $this->getCompanyInfo($param['business_licence_number_electronic']);
  129. if ($res['code'] == 200) {
  130. $info = $res['data'];
  131. if ($param['company_name'] != $info['company'] || $param['business_licence_number'] !== $info['reg_num']) {
  132. $this->error('您提交的企业信息或营业执照照片未通过校验,请仔细核对后提交');
  133. }
  134. } else {
  135. $this->error($res['msg']);
  136. }
  137. }
  138. if ($param['store_type'] == 1) {
  139. if (empty($param['business_author_letter'])) {
  140. ds_json_encode(10001,'请上传身份证背面照片');
  141. }
  142. $res = $this->getIdCardInfo2($param);
  143. if ($res['code'] == 200) {
  144. $info = $res['data'];
  145. if ($param['business_licence_number'] != $info['idcard'] || $param['contacts_name'] !== $info['name']) {
  146. ds_json_encode(10001,'您提交的身份信息或身份证照片未通过校验,请仔细核对后提交');
  147. }
  148. } else {
  149. ds_json_encode(10001,$res['msg']);
  150. }
  151. }
  152. $storejoinin_model = model('storejoinin');
  153. if (empty($this->joinin_detail)) {
  154. $param['member_id'] = $this->member_info['member_id'];
  155. $storejoinin_model->addStorejoinin($param);
  156. } else {
  157. $storejoinin_model->editStorejoinin($param, array('member_id' => $this->member_info['member_id']));
  158. }
  159. ds_json_encode(10000);
  160. }
  161. private function step2_save_valid($param)
  162. {
  163. $sellerjoinin_validate = ds_validate('sellerjoinin');
  164. if (!$sellerjoinin_validate->scene(input('post.store_type') ? 'step2_save_valid2' : 'step2_save_valid')->check($param)) {
  165. ds_json_encode(10001, $sellerjoinin_validate->getError());
  166. }
  167. }
  168. /**
  169. * @api {POST} api/Sellerjoinin/step3 商家入驻第三步
  170. * @apiVersion 1.0.0
  171. * @apiGroup Sellerjoinin
  172. *
  173. * @apiHeader {String} X-DS-KEY 用户授权token
  174. *
  175. * @apiParam {Int} store_type 入驻类型(0企业1个人)
  176. * @apiParam {String} settlement_bank_account_name 结算银行账户名
  177. * @apiParam {Int} settlement_bank_account_number 结算银行账号
  178. * @apiParam {String} bank_account_name 银行账户名
  179. * @apiParam {String} bank_account_number 银行账号
  180. * @apiParam {String} bank_name 银行名
  181. * @apiParam {String} bank_address 银行地区名
  182. * @apiParam {String} is_settlement_account 是否结算银行同号(0否1是)
  183. * @apiParam {String} settlement_bank_name 结算银行名
  184. * @apiParam {String} settlement_bank_address 结算银行地区名
  185. *
  186. * @apiSuccess {String} code 返回码,10000为成功
  187. * @apiSuccess {String} message 返回消息
  188. * @apiSuccess {Object} result 返回数据
  189. */
  190. public function step3()
  191. {
  192. $param = array();
  193. if (input('post.store_type')) {
  194. $param['settlement_bank_account_name'] = input('post.settlement_bank_account_name');
  195. $param['settlement_bank_account_number'] = input('post.settlement_bank_account_number');
  196. } else {
  197. $param['bank_account_name'] = input('post.bank_account_name');
  198. $param['bank_account_number'] = input('post.bank_account_number');
  199. $param['bank_name'] = input('post.bank_name');
  200. $param['bank_address'] = input('post.bank_address');
  201. $is_settlement_account = input('post.is_settlement_account');
  202. if (!empty($is_settlement_account)) {
  203. $param['is_settlement_account'] = 1;
  204. $param['settlement_bank_account_name'] = input('post.bank_account_name');
  205. $param['settlement_bank_account_number'] = input('post.bank_account_number');
  206. $param['settlement_bank_name'] = input('post.bank_name');
  207. $param['settlement_bank_address'] = input('post.bank_address');
  208. } else {
  209. $param['is_settlement_account'] = 2;
  210. $param['settlement_bank_account_name'] = input('post.settlement_bank_account_name');
  211. $param['settlement_bank_account_number'] = input('post.settlement_bank_account_number');
  212. $param['settlement_bank_name'] = input('post.settlement_bank_name');
  213. $param['settlement_bank_address'] = input('post.settlement_bank_address');
  214. }
  215. }
  216. $this->step3_save_valid($param);
  217. $storejoinin_model = model('storejoinin');
  218. $storejoinin_model->editStorejoinin($param, array('member_id' => $this->member_info['member_id']));
  219. ds_json_encode(10000);
  220. }
  221. private function step3_save_valid($param)
  222. {
  223. $sellerjoinin_validate = ds_validate('sellerjoinin');
  224. if (!$sellerjoinin_validate->scene(input('post.store_type') ? 'step3_save_valid3' : 'step3_save_valid')->check($param)) {
  225. ds_json_encode(10001, $sellerjoinin_validate->getError());
  226. }
  227. }
  228. /**
  229. * @api {POST} api/Sellerjoinin/step4 商家入驻第四步
  230. * @apiVersion 1.0.0
  231. * @apiGroup Sellerjoinin
  232. *
  233. * @apiHeader {String} X-DS-KEY 用户授权token
  234. *
  235. * @apiParam {String} seller_name 账号名
  236. * @apiParam {Int[]} store_class_ids 经营分类id
  237. * @apiParam {String[]} store_class_names 经营分类名
  238. * @apiParam {String} store_name 店铺名
  239. * @apiParam {String} store_type 店铺类型
  240. * @apiParam {Int} joinin_year 入驻年限
  241. * @apiParam {String} storegrade_id 店铺等级
  242. * @apiParam {Int} storeclass_id 店铺分类id
  243. *
  244. * @apiSuccess {String} code 返回码,10000为成功
  245. * @apiSuccess {String} message 返回消息
  246. * @apiSuccess {Object} result 返回数据
  247. */
  248. public function step4()
  249. {
  250. $store_class_ids = array();
  251. $store_class_names = array();
  252. $store_class_ids_array = input('post.store_class_ids/a'); #获取数组
  253. if (!empty($store_class_ids_array)) {
  254. foreach ($store_class_ids_array as $value) {
  255. $store_class_ids[] = $value;
  256. }
  257. }
  258. $store_class_names_array = input('post.store_class_names/a'); #获取数组
  259. if (!empty($store_class_names_array)) {
  260. foreach ($store_class_names_array as $value) {
  261. if (empty($value)) {
  262. continue;
  263. } else {
  264. $store_class_names[] = $value;
  265. }
  266. }
  267. }
  268. //取最小级分类最新分佣比例
  269. $sc_ids = array();
  270. foreach ($store_class_ids as $v) {
  271. $v = explode(',', trim($v, ','));
  272. if (!empty($v) && is_array($v)) {
  273. $sc_ids[] = end($v);
  274. }
  275. }
  276. $store_class_commis_rates = array();
  277. if (!empty($sc_ids)) {
  278. $goods_class_list = model('goodsclass')->getGoodsclassListByIds($sc_ids);
  279. if (!empty($goods_class_list) && is_array($goods_class_list)) {
  280. $sc_ids = array();
  281. foreach ($goods_class_list as $v) {
  282. $store_class_commis_rates[] = $v['commis_rate'];
  283. }
  284. }
  285. }
  286. $param = array();
  287. $param['store_type'] = input('post.store_type');
  288. $param['seller_name'] = $this->member_info['member_name'];
  289. $param['store_name'] = trim(input('post.store_name'));
  290. $param['store_class_ids'] = serialize($store_class_ids);
  291. $param['store_class_names'] = serialize($store_class_names);
  292. $param['joinin_year'] = intval(input('post.joinin_year'));
  293. $param['joinin_state'] = STORE_JOIN_STATE_NEW;
  294. $param['store_class_commis_rates'] = implode(',', $store_class_commis_rates);
  295. //取店铺等级信息
  296. $grade_list = rkcache('storegrade', true);
  297. $storegrade_id = intval(input('post.storegrade_id'));
  298. if ($storegrade_id <= 0) {
  299. ds_json_encode(10001, lang('select_store_level'));
  300. }
  301. if (!empty($grade_list[$storegrade_id])) {
  302. $param['storegrade_id'] = $storegrade_id;
  303. $param['storegrade_name'] = $grade_list[$storegrade_id]['storegrade_name'];
  304. $param['sg_info'] = serialize(array('storegrade_price' => $grade_list[$storegrade_id]['storegrade_price']));
  305. }
  306. //取最新店铺分类信息
  307. $storeclass_id = intval(input('post.storeclass_id'));
  308. if ($storeclass_id <= 0) {
  309. ds_json_encode(10001, lang('select_store_category'));
  310. }
  311. $store_class_info = model('storeclass')->getStoreclassInfo(array('storeclass_id' => $storeclass_id));
  312. if ($store_class_info) {
  313. $param['storeclass_id'] = $store_class_info['storeclass_id'];
  314. $param['storeclass_name'] = $store_class_info['storeclass_name'];
  315. $param['storeclass_bail'] = $store_class_info['storeclass_bail'];
  316. }
  317. //店铺应付款
  318. $param['paying_amount'] = floatval($grade_list[$storegrade_id]['storegrade_price']) * $param['joinin_year'] + floatval($param['storeclass_bail']);
  319. $this->step4_save_valid($param);
  320. $storejoinin_model = model('storejoinin');
  321. $storejoinin_model->editStorejoinin($param, array('member_id' => $this->member_info['member_id']));
  322. ds_json_encode(10000);
  323. }
  324. private function step4_save_valid($param)
  325. {
  326. $sellerjoinin_validate = ds_validate('sellerjoinin');
  327. if (!$sellerjoinin_validate->scene(input('post.store_type') ? 'step4_save_valid4' : 'step4_save_valid')->check($param)) {
  328. ds_json_encode(10001, $sellerjoinin_validate->getError());
  329. }
  330. }
  331. /**
  332. * @api {POST} api/Sellerjoinin/pay_save 保存付款凭证
  333. * @apiVersion 1.0.0
  334. * @apiGroup Sellerjoinin
  335. *
  336. * @apiHeader {String} X-DS-KEY 用户授权token
  337. *
  338. * @apiParam {String} paying_money_certificate 付款截图
  339. * @apiParam {String} paying_money_certificate_explain 付款备注
  340. *
  341. * @apiSuccess {String} code 返回码,10000为成功
  342. * @apiSuccess {String} message 返回消息
  343. * @apiSuccess {Object} result 返回数据
  344. */
  345. public function pay_save()
  346. {
  347. $param = array();
  348. $param['paying_money_certificate'] = input('post.paying_money_certificate');
  349. $param['paying_money_certificate_explain'] = input('post.paying_money_certificate_explain');
  350. $param['joinin_state'] = STORE_JOIN_STATE_PAY;
  351. if (empty($param['paying_money_certificate'])) {
  352. ds_json_encode(10001, lang('paying_money_certificate_empty'));
  353. }
  354. $storejoinin_model = model('storejoinin');
  355. $storejoinin_model->editStorejoinin($param, array('member_id' => $this->member_info['member_id']));
  356. ds_json_encode(10000);
  357. }
  358. /**
  359. * @api {POST} api/Sellerjoinin/upload_image 上传图片
  360. * @apiVersion 1.0.0
  361. * @apiGroup Sellerjoinin
  362. *
  363. * @apiHeader {String} X-DS-KEY 用户授权token
  364. *
  365. * @apiParam {File} file 图片
  366. *
  367. * @apiSuccess {String} code 返回码,10000为成功
  368. * @apiSuccess {String} message 返回消息
  369. * @apiSuccess {Object} result 返回数据
  370. *
  371. */
  372. public function upload_image()
  373. {
  374. $file = 'file';
  375. //上传文件保存路径
  376. $pic_name = '';
  377. if (!empty($_FILES[$file]['name'])) {
  378. //设置特殊图片名称
  379. $file_name = $this->member_info['member_id'] . '_' . date('YmdHis') . rand(10000, 99999) . '.png';
  380. $res = ds_upload_pic('home' . DIRECTORY_SEPARATOR . 'store_joinin', $file, $file_name);
  381. if ($res['code']) {
  382. $pic_name = $res['data']['file_name'];
  383. } else {
  384. ds_json_encode(10001, $res['msg']);
  385. }
  386. }
  387. ds_json_encode(10000, '', array('path' => $pic_name, 'url' => get_store_joinin_imageurl($pic_name)));
  388. }
  389. }