Sellerjoinin.php 18 KB

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