Sellerjoininc2c.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. <?php
  2. namespace app\home\controller;
  3. use app\common\model\Cache;
  4. use think\facade\View;
  5. use think\facade\Lang;
  6. use think\middleware\SessionInit;
  7. /**
  8. *
  9. *
  10. * ----------------------------------------------------------------------------
  11. *
  12. * 控制器
  13. */
  14. class Sellerjoininc2c extends BaseMember
  15. {
  16. private $joinin_detail = NULL;
  17. public function initialize()
  18. {
  19. parent::initialize();
  20. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerjoinin.lang.php');
  21. $this->checkLogin();
  22. $seller_model = model('seller');
  23. $seller_info = $seller_model->getSellerInfo(array('member_id' => session('member_id')));
  24. if (!empty($seller_info)) {
  25. $this->success(lang('already_sub_account'), (string) url('Sellerlogin/login'));
  26. exit;
  27. }
  28. if (request()->action() != 'checkname') {
  29. $this->check_joinin_state();
  30. }
  31. $store_joinin_open = config('ds_config.store_joinin_open');
  32. if (!$this->joinin_detail || !$this->joinin_detail['joinin_state']) { //已经填写过入驻资料的则不跳转
  33. if ($store_joinin_open == 0) {
  34. $this->error(lang('store_joinin_close'));
  35. } elseif ($store_joinin_open == 2) {
  36. $this->redirect('Sellerjoinin/' . request()->action());
  37. }
  38. }
  39. $phone_array = explode(',', config('ds_config.site_phone'));
  40. View::assign('phone_array', $phone_array);
  41. $help_model = model('help');
  42. $condition = array();
  43. $condition[] = array('helptype_id', '=', '99'); //默认显示入驻流程;
  44. $help_list = $help_model->getShowStoreHelpList($condition);
  45. View::assign('help_list', $help_list); //左侧帮助类型及帮助
  46. View::assign('show_sign', 'joinin');
  47. View::assign('html_title', config('ds_config.site_name') . ' - ' . lang('tenants'));
  48. View::assign('article_list', ''); //底部不显示文章分类
  49. }
  50. private function check_joinin_state()
  51. {
  52. $storejoinin_model = model('storejoinin');
  53. $joinin_detail = $storejoinin_model->getOneStorejoinin(array('member_id' => session('member_id')));
  54. if (!empty($joinin_detail)) {
  55. $this->joinin_detail = $joinin_detail;
  56. switch (intval($joinin_detail['joinin_state'])) {
  57. case STORE_JOIN_STATE_NEW:
  58. $this->dostep4();
  59. $this->show_join_message(lang('apply_submit_success'), FALSE, '3');
  60. break;
  61. case STORE_JOIN_STATE_PAY:
  62. $this->show_join_message(lang('pay_submit_success'), FALSE, '4');
  63. break;
  64. case STORE_JOIN_STATE_VERIFY_SUCCESS:
  65. if (!in_array(request()->action(), array('pay', 'pay_save'))) {
  66. $this->pay();
  67. }
  68. break;
  69. case STORE_JOIN_STATE_VERIFY_FAIL:
  70. if (!in_array(request()->action(), array('step1', 'step2', 'step3', 'step4'))) {
  71. $this->show_join_message(lang('verify_fail') . ':' . $joinin_detail['joinin_message'], HOME_SITE_URL . DIRECTORY_SEPARATOR . '/sellerjoininc2c/step1');
  72. }
  73. break;
  74. case STORE_JOIN_STATE_PAY_FAIL:
  75. if (!in_array(request()->action(), array('pay', 'pay_save'))) {
  76. $this->show_join_message(lang('pay_verify_fail') . ':' . $joinin_detail['joinin_message'], HOME_SITE_URL . DIRECTORY_SEPARATOR . '/sellerjoininc2c/pay');
  77. }
  78. break;
  79. case STORE_JOIN_STATE_FINAL:
  80. $this->success(lang('store_already_open'), (string) url('Sellerlogin/login'));
  81. break;
  82. }
  83. }
  84. }
  85. public function index()
  86. {
  87. $this->step0();
  88. }
  89. public function step0()
  90. {
  91. $document_model = model('document');
  92. $document_info = $document_model->getOneDocumentByCode('open_store');
  93. View::assign('agreement', htmlspecialchars_decode($document_info['document_content']));
  94. View::assign('step', 'step1');
  95. View::assign('sub_step', 'step0');
  96. echo View::fetch($this->template_dir . 'step0');
  97. exit;
  98. }
  99. public function step1()
  100. {
  101. View::assign('step', 'step2');
  102. View::assign('sub_step', 'step1');
  103. return View::fetch($this->template_dir . 'step1');
  104. }
  105. public function step2()
  106. {
  107. if (request()->isPost()) {
  108. $param = array();
  109. $param['member_name'] = session('member_name');
  110. $param['company_name'] = input('post.company_name');
  111. $param['company_address'] = input('post.company_address');
  112. $param['store_longitude'] = input('post.longitude');
  113. $param['store_latitude'] = input('post.latitude');
  114. $param['company_address_detail'] = input('post.company_address_detail');
  115. $param['company_province_id'] = input('post.district_id') ? input('post.district_id') : (input('post.city_id') ? input('post.city_id') : (input('post.province_id') ? input('post.province_id') : 0));
  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'] = $this->upload_image('business_licence_number_electronic');
  125. $param['business_licence_number_electronic'] = input('post.member_idcard_image2');
  126. // $param['business_author_letter'] = $this->upload_image('business_author_letter');
  127. $param['business_author_letter'] = input('post.member_idcard_image3');
  128. $this->step2_save_valid($param);
  129. $res = $this->getIdCardInfo2($param);
  130. if ($res['code'] == 200) {
  131. $info = $res['data'];
  132. if ($param['business_licence_number'] != $info['idcard'] || $param['contacts_name'] !== $info['name']) {
  133. //缓存图片
  134. $memberId = session('member_id');
  135. session('member_image2_'.$memberId,$param);
  136. session('member_image3_'.$memberId,$param);
  137. // dd();
  138. $this->error('您提交的身份信息或身份证照片未通过校验,请仔细核对后提交');
  139. // ds_json_encode(10001, '您提交的身份信息或身份证照片未通过校验,请仔细核对后提交');
  140. }
  141. } else {
  142. $memberId = session('member_id');
  143. session('member_image2_'.$memberId,$param);
  144. session('member_image3_'.$memberId,$param);
  145. $this->error($res['msg']);
  146. // ds_json_encode(10001, $res['msg']);
  147. }
  148. $storejoinin_model = model('storejoinin');
  149. $joinin_info = $storejoinin_model->getOneStorejoinin(array('member_id' => session('member_id')));
  150. if (empty($joinin_info)) {
  151. $param['member_id'] = session('member_id');
  152. $storejoinin_model->addStorejoinin($param);
  153. } else {
  154. $storejoinin_model->editStorejoinin($param, array('member_id' => session('member_id')));
  155. }
  156. }
  157. View::assign('step', 'step2');
  158. View::assign('sub_step', 'step2');
  159. echo View::fetch($this->template_dir . 'step2');
  160. exit;
  161. }
  162. private function step2_save_valid($param)
  163. {
  164. $sellerjoinin_validate = ds_validate('sellerjoinin');
  165. if (!$sellerjoinin_validate->scene('step2_save_valid2')->check($param)) {
  166. $this->error($sellerjoinin_validate->getError());
  167. }
  168. }
  169. public function step3()
  170. {
  171. if (request()->isPost()) {
  172. $param = array();
  173. $param['settlement_bank_account_name'] = input('post.settlement_bank_account_name');
  174. $param['settlement_bank_account_number'] = input('post.settlement_bank_account_number');
  175. $this->step3_save_valid($param);
  176. $storejoinin_model = model('storejoinin');
  177. $storejoinin_model->editStorejoinin($param, array('member_id' => session('member_id')));
  178. }
  179. //商品分类
  180. $gc = model('goodsclass');
  181. $gc_list = $gc->getGoodsclassListByParentId(0);
  182. View::assign('gc_list', $gc_list);
  183. //店铺等级
  184. $grade_list = rkcache('storegrade', true);
  185. View::assign('grade_list', $grade_list);
  186. //店铺分类
  187. $storeclass_model = model('storeclass');
  188. $store_class = $storeclass_model->getStoreclassList(array(), '', false);
  189. View::assign('store_class', $store_class);
  190. View::assign('step', '3');
  191. View::assign('sub_step', 'step3');
  192. echo View::fetch($this->template_dir . 'step3');
  193. exit;
  194. }
  195. private function step3_save_valid($param)
  196. {
  197. $sellerjoinin_validate = ds_validate('sellerjoinin');
  198. if (!$sellerjoinin_validate->scene('step3_save_valid3')->check($param)) {
  199. $this->error($sellerjoinin_validate->getError());
  200. }
  201. }
  202. public function step4()
  203. {
  204. $store_class_ids = array();
  205. $store_class_names = array();
  206. $store_class_ids_array = input('post.store_class_ids/a'); #获取数组
  207. if (!empty($store_class_ids_array)) {
  208. foreach ($store_class_ids_array as $value) {
  209. $store_class_ids[] = $value;
  210. }
  211. }
  212. $store_class_names_array = input('post.store_class_names/a'); #获取数组
  213. if (!empty($store_class_names_array)) {
  214. foreach ($store_class_names_array as $value) {
  215. $store_class_names[] = $value;
  216. }
  217. }
  218. //取最小级分类最新分佣比例
  219. $sc_ids = array();
  220. foreach ($store_class_ids as $v) {
  221. $v = explode(',', trim($v, ','));
  222. if (!empty($v) && is_array($v)) {
  223. $sc_ids[] = end($v);
  224. }
  225. }
  226. $store_class_commis_rates = array();
  227. if (!empty($sc_ids)) {
  228. $goods_class_list = model('goodsclass')->getGoodsclassListByIds($sc_ids);
  229. if (!empty($goods_class_list) && is_array($goods_class_list)) {
  230. $sc_ids = array();
  231. foreach ($goods_class_list as $v) {
  232. $store_class_commis_rates[] = $v['commis_rate'];
  233. }
  234. }
  235. }
  236. $param = array();
  237. $param['seller_name'] = $this->member_info['member_name'];
  238. $param['store_name'] = trim(input('post.store_name'));
  239. $param['store_type'] = 1;
  240. $param['store_class_ids'] = serialize($store_class_ids);
  241. $param['store_class_names'] = serialize($store_class_names);
  242. $param['joinin_year'] = intval(input('post.joinin_year'));
  243. $param['joinin_state'] = STORE_JOIN_STATE_NEW;
  244. $param['store_class_commis_rates'] = implode(',', $store_class_commis_rates);
  245. //取店铺等级信息
  246. $grade_list = rkcache('storegrade', true);
  247. $storegrade_id = intval(input('post.storegrade_id'));
  248. if ($storegrade_id <= 0) {
  249. $this->error(lang('param_error'));
  250. }
  251. if (!empty($grade_list[$storegrade_id])) {
  252. $param['storegrade_id'] = $storegrade_id;
  253. $param['storegrade_name'] = $grade_list[$storegrade_id]['storegrade_name'];
  254. $param['sg_info'] = serialize(array('storegrade_price' => $grade_list[$storegrade_id]['storegrade_price']));
  255. }
  256. //取最新店铺分类信息
  257. $store_class_info = model('storeclass')->getStoreclassInfo(array('storeclass_id' => intval(input('post.storeclass_id'))));
  258. if ($store_class_info) {
  259. $param['storeclass_id'] = $store_class_info['storeclass_id'];
  260. $param['storeclass_name'] = $store_class_info['storeclass_name'];
  261. $param['storeclass_bail'] = $store_class_info['storeclass_bail'];
  262. }
  263. //店铺应付款
  264. $param['paying_amount'] = floatval($grade_list[$storegrade_id]['storegrade_price']) * $param['joinin_year'] + floatval($param['storeclass_bail']);
  265. $this->step4_save_valid($param);
  266. $storejoinin_model = model('storejoinin');
  267. $storejoinin_model->editStorejoinin($param, array('member_id' => session('member_id')));
  268. header('location:' . (string) url('Sellerjoininc2c/index'));
  269. exit;
  270. }
  271. private function step4_save_valid($param)
  272. {
  273. $sellerjoinin_validate = ds_validate('sellerjoinin');
  274. if (!$sellerjoinin_validate->scene('step4_save_valid4')->check($param)) {
  275. $this->error($sellerjoinin_validate->getError());
  276. }
  277. }
  278. public function pay()
  279. {
  280. if (!empty($this->joinin_detail['sg_info'])) {
  281. $store_grade_info = model('storegrade')->getOneStoregrade($this->joinin_detail['storegrade_id']);
  282. $this->joinin_detail['storegrade_price'] = $store_grade_info['storegrade_price'];
  283. } else {
  284. $this->joinin_detail['sg_info'] = @unserialize($this->joinin_detail['sg_info']);
  285. if (is_array($this->joinin_detail['sg_info'])) {
  286. $this->joinin_detail['storegrade_price'] = $this->joinin_detail['sg_info']['storegrade_price'];
  287. }
  288. }
  289. View::assign('joinin_detail', $this->joinin_detail);
  290. View::assign('step', '4');
  291. View::assign('sub_step', 'pay');
  292. echo View::fetch($this->template_dir . 'pay');
  293. exit;
  294. }
  295. public function pay_save()
  296. {
  297. $param = array();
  298. $param['paying_money_certificate'] = $this->upload_image('paying_money_certificate');
  299. $param['paying_money_certificate_explain'] = input('post.paying_money_certificate_explain');
  300. $param['joinin_state'] = STORE_JOIN_STATE_PAY;
  301. if (empty($param['paying_money_certificate'])) {
  302. $this->error(lang('paying_money_certificate_empty'));
  303. }
  304. $storejoinin_model = model('storejoinin');
  305. $storejoinin_model->editStorejoinin($param, array('member_id' => session('member_id')));
  306. header('location:' . (string) url('Sellerjoininc2c/index'));
  307. exit;
  308. }
  309. private function dostep4()
  310. {
  311. if (!empty($this->joinin_detail['sg_info'])) {
  312. $store_grade_info = model('storegrade')->getOneStoregrade($this->joinin_detail['storegrade_id']);
  313. $this->joinin_detail['storegrade_price'] = $store_grade_info['storegrade_price'];
  314. } else {
  315. $this->joinin_detail['sg_info'] = @unserialize($this->joinin_detail['sg_info']);
  316. if (is_array($this->joinin_detail['sg_info'])) {
  317. $this->joinin_detail['storegrade_price'] = $this->joinin_detail['sg_info']['storegrade_price'];
  318. }
  319. }
  320. View::assign('joinin_detail', $this->joinin_detail);
  321. }
  322. private function show_join_message($message, $btn_next = FALSE, $step = 'step2')
  323. {
  324. View::assign('joinin_detail', $this->joinin_detail);
  325. View::assign('joinin_message', $message);
  326. View::assign('btn_next', $btn_next);
  327. View::assign('step', $step);
  328. View::assign('sub_step', 'step4');
  329. echo View::fetch($this->template_dir . 'step4');
  330. exit;
  331. }
  332. private function upload_image($file)
  333. {
  334. $pic_name = '';
  335. if (!empty($_FILES[$file]['name'])) {
  336. //设置特殊图片名称
  337. $file_name = session('member_id') . '_' . date('YmdHis') . rand(10000, 99999) . '.png';
  338. $res = ds_upload_pic('home' . DIRECTORY_SEPARATOR . 'store_joinin', $file, $file_name);
  339. if ($res['code']) {
  340. $pic_name = $res['data']['file_name'];
  341. } else {
  342. $this->error($res['msg']);
  343. }
  344. }
  345. return $pic_name;
  346. }
  347. /**
  348. * 检查店铺名称是否存在
  349. *
  350. * @param
  351. * @return
  352. */
  353. public function checkname()
  354. {
  355. /**
  356. * 实例化卖家模型
  357. */
  358. $store_model = model('store');
  359. $store_name = input('get.store_name');
  360. $store_info = $store_model->getStoreInfo(array('store_name' => $store_name));
  361. if (!empty($store_info['store_name']) && $store_info['member_id'] != session('member_id')) {
  362. echo 'false';
  363. } else {
  364. echo 'true';
  365. }
  366. }
  367. }