Sellerjoinin.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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. * ============================================================================
  13. * 控制器
  14. */
  15. class Sellerjoinin extends BaseMember {
  16. private $joinin_detail = NULL;
  17. public function initialize() {
  18. parent::initialize();
  19. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerjoinin.lang.php');
  20. $this->checkLogin();
  21. $seller_model = model('seller');
  22. $seller_info = $seller_model->getSellerInfo(array('member_id' => session('member_id')));
  23. if (!empty($seller_info)) {
  24. $this->success(lang('already_sub_account'), (string) url('Sellerlogin/login'));
  25. exit;
  26. }
  27. if (request()->action() != 'checkname') {
  28. $this->check_joinin_state();
  29. }
  30. $store_joinin_open = config('ds_config.store_joinin_open');
  31. if (!$this->joinin_detail || !$this->joinin_detail['joinin_state']) {//已经填写过入驻资料的则不跳转
  32. if ($store_joinin_open == 0) {
  33. $this->error(lang('store_joinin_close'));
  34. } elseif ($store_joinin_open == 3) {
  35. $this->redirect('Sellerjoininc2c/' . request()->action());
  36. }
  37. }
  38. $phone_array = explode(',', config('ds_config.site_phone'));
  39. View::assign('phone_array', $phone_array);
  40. $help_model = model('help');
  41. $condition = array();
  42. $condition[] = array('helptype_id', '=', '99'); //默认显示入驻流程;
  43. $help_list = $help_model->getShowStoreHelpList($condition);
  44. View::assign('help_list', $help_list); //左侧帮助类型及帮助
  45. View::assign('show_sign', 'joinin');
  46. View::assign('html_title', config('ds_config.site_name') . ' - ' . lang('tenants'));
  47. View::assign('article_list', ''); //底部不显示文章分类
  48. }
  49. private function check_joinin_state() {
  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. echo $this->step0();
  85. exit;
  86. }
  87. public function step0() {
  88. $document_model = model('document');
  89. $document_info = $document_model->getOneDocumentByCode('open_store');
  90. View::assign('agreement', htmlspecialchars_decode($document_info['document_content']));
  91. View::assign('step', '0');
  92. View::assign('sub_step', 'step0');
  93. echo View::fetch($this->template_dir . 'step0');
  94. exit;
  95. }
  96. public function step1() {
  97. View::assign('step', '1');
  98. View::assign('sub_step', 'step1');
  99. View::assign('baidu_ak', config('ds_config.baidu_ak'));
  100. echo View::fetch($this->template_dir . 'step1');
  101. exit;
  102. }
  103. public function step2() {
  104. if (request()->isPost()) {
  105. $param = array();
  106. $param['member_name'] = session('member_name');
  107. $param['company_name'] = input('post.company_name');
  108. $param['store_longitude'] = input('post.longitude');
  109. $param['store_latitude'] = input('post.latitude');
  110. $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)));
  111. $param['company_address'] = input('post.company_address');
  112. $param['company_address_detail'] = input('post.company_address_detail');
  113. $param['company_registered_capital'] = intval(input('post.company_registered_capital'));
  114. $param['contacts_name'] = input('post.contacts_name');
  115. $param['contacts_phone'] = input('post.contacts_phone');
  116. $param['contacts_email'] = input('post.contacts_email');
  117. $param['business_licence_number'] = input('post.business_licence_number');
  118. $param['business_licence_address'] = input('post.business_licence_address');
  119. $param['business_licence_start'] = input('post.business_licence_start');
  120. $param['business_licence_end'] = input('post.business_licence_end');
  121. $param['business_sphere'] = input('post.business_sphere');
  122. $param['business_licence_number_electronic'] = $this->upload_image('business_licence_number_electronic');
  123. $this->step2_save_valid($param);
  124. $storejoinin_model = model('storejoinin');
  125. $joinin_info = $storejoinin_model->getOneStorejoinin(array('member_id' => session('member_id')));
  126. if (empty($joinin_info)) {
  127. $param['member_id'] = session('member_id');
  128. $storejoinin_model->addStorejoinin($param);
  129. } else {
  130. $storejoinin_model->editStorejoinin($param, array('member_id' => session('member_id')));
  131. }
  132. }
  133. View::assign('step', '2');
  134. View::assign('sub_step', 'step2');
  135. echo View::fetch($this->template_dir . 'step2');
  136. exit;
  137. }
  138. private function step2_save_valid($param) {
  139. $sellerjoinin_validate = ds_validate('sellerjoinin');
  140. if (!$sellerjoinin_validate->scene('step2_save_valid')->check($param)) {
  141. $this->error($sellerjoinin_validate->getError());
  142. }
  143. }
  144. public function step3() {
  145. if (request()->isPost()) {
  146. $param = array();
  147. $param['bank_account_name'] = input('post.bank_account_name');
  148. $param['bank_account_number'] = input('post.bank_account_number');
  149. $param['bank_name'] = input('post.bank_name');
  150. $param['bank_address'] = input('post.bank_address');
  151. $is_settlement_account = input('post.is_settlement_account');
  152. if (!empty($is_settlement_account)) {
  153. $param['is_settlement_account'] = 1;
  154. $param['settlement_bank_account_name'] = input('post.bank_account_name');
  155. $param['settlement_bank_account_number'] = input('post.bank_account_number');
  156. $param['settlement_bank_name'] = input('post.bank_name');
  157. $param['settlement_bank_address'] = input('post.bank_address');
  158. } else {
  159. $param['is_settlement_account'] = 2;
  160. $param['settlement_bank_account_name'] = input('post.settlement_bank_account_name');
  161. $param['settlement_bank_account_number'] = input('post.settlement_bank_account_number');
  162. $param['settlement_bank_name'] = input('post.settlement_bank_name');
  163. $param['settlement_bank_address'] = input('post.settlement_bank_address');
  164. }
  165. $this->step3_save_valid($param);
  166. $storejoinin_model = model('storejoinin');
  167. $storejoinin_model->editStorejoinin($param, array('member_id' => session('member_id')));
  168. }
  169. //商品分类
  170. $gc = model('goodsclass');
  171. $gc_list = $gc->getGoodsclassListByParentId(0);
  172. View::assign('gc_list', $gc_list);
  173. //店铺等级
  174. $grade_list = rkcache('storegrade', true);
  175. View::assign('grade_list', $grade_list);
  176. //店铺分类
  177. $storeclass_model = model('storeclass');
  178. $store_class = $storeclass_model->getStoreclassList(array(), '', false);
  179. View::assign('store_class', $store_class);
  180. View::assign('step', '3');
  181. View::assign('sub_step', 'step3');
  182. echo View::fetch($this->template_dir . 'step3');
  183. exit;
  184. }
  185. private function step3_save_valid($param) {
  186. $sellerjoinin_validate = ds_validate('sellerjoinin');
  187. if (!$sellerjoinin_validate->scene('step3_save_valid')->check($param)) {
  188. $this->error($sellerjoinin_validate->getError());
  189. }
  190. }
  191. public function step4() {
  192. $store_class_ids = array();
  193. $store_class_names = array();
  194. $store_class_ids_array = input('post.store_class_ids/a'); #获取数组
  195. if (!empty($store_class_ids_array)) {
  196. foreach ($store_class_ids_array as $value) {
  197. $store_class_ids[] = $value;
  198. }
  199. }
  200. $store_class_names_array = input('post.store_class_names/a'); #获取数组
  201. if (!empty($store_class_names_array)) {
  202. foreach ($store_class_names_array as $value) {
  203. $store_class_names[] = $value;
  204. }
  205. }
  206. //取最小级分类最新分佣比例
  207. $sc_ids = array();
  208. foreach ($store_class_ids as $v) {
  209. $v = explode(',', trim($v, ','));
  210. if (!empty($v) && is_array($v)) {
  211. $sc_ids[] = end($v);
  212. }
  213. }
  214. $store_class_commis_rates = array();
  215. if (!empty($sc_ids)) {
  216. $goods_class_list = model('goodsclass')->getGoodsclassListByIds($sc_ids);
  217. if (!empty($goods_class_list) && is_array($goods_class_list)) {
  218. $sc_ids = array();
  219. foreach ($goods_class_list as $v) {
  220. $store_class_commis_rates[] = $v['commis_rate'];
  221. }
  222. }
  223. }
  224. $param = array();
  225. $param['seller_name'] = $this->member_info['member_name'];
  226. $param['store_name'] = trim(input('post.store_name'));
  227. $param['store_type'] = 0;
  228. $param['store_class_ids'] = serialize($store_class_ids);
  229. $param['store_class_names'] = serialize($store_class_names);
  230. $param['joinin_year'] = intval(input('post.joinin_year'));
  231. $param['joinin_state'] = STORE_JOIN_STATE_NEW;
  232. $param['store_class_commis_rates'] = implode(',', $store_class_commis_rates);
  233. //取店铺等级信息
  234. $grade_list = rkcache('storegrade', true);
  235. $storegrade_id = intval(input('post.storegrade_id'));
  236. if ($storegrade_id <= 0) {
  237. $this->error(lang('param_error'));
  238. }
  239. if (!empty($grade_list[$storegrade_id])) {
  240. $param['storegrade_id'] = $storegrade_id;
  241. $param['storegrade_name'] = $grade_list[$storegrade_id]['storegrade_name'];
  242. $param['sg_info'] = serialize(array('storegrade_price' => $grade_list[$storegrade_id]['storegrade_price']));
  243. }
  244. //取最新店铺分类信息
  245. $store_class_info = model('storeclass')->getStoreclassInfo(array('storeclass_id' => intval(input('post.storeclass_id'))));
  246. if ($store_class_info) {
  247. $param['storeclass_id'] = $store_class_info['storeclass_id'];
  248. $param['storeclass_name'] = $store_class_info['storeclass_name'];
  249. $param['storeclass_bail'] = $store_class_info['storeclass_bail'];
  250. }
  251. //店铺应付款
  252. $param['paying_amount'] = floatval($grade_list[$storegrade_id]['storegrade_price']) * $param['joinin_year'] + floatval($param['storeclass_bail']);
  253. $this->step4_save_valid($param);
  254. $storejoinin_model = model('storejoinin');
  255. $storejoinin_model->editStorejoinin($param, array('member_id' => session('member_id')));
  256. @header('location: ' . (string) url('Sellerjoinin/index'));
  257. exit;
  258. }
  259. private function step4_save_valid($param) {
  260. $sellerjoinin_validate = ds_validate('sellerjoinin');
  261. if (!$sellerjoinin_validate->scene('step4_save_valid')->check($param)) {
  262. $this->error($sellerjoinin_validate->getError());
  263. }
  264. }
  265. public function pay() {
  266. if (!empty($this->joinin_detail['sg_info'])) {
  267. $store_grade_info = model('storegrade')->getOneStoregrade($this->joinin_detail['storegrade_id']);
  268. $this->joinin_detail['storegrade_price'] = $store_grade_info['storegrade_price'];
  269. } else {
  270. $this->joinin_detail['sg_info'] = @unserialize($this->joinin_detail['sg_info']);
  271. if (is_array($this->joinin_detail['sg_info'])) {
  272. $this->joinin_detail['storegrade_price'] = $this->joinin_detail['sg_info']['storegrade_price'];
  273. }
  274. }
  275. View::assign('joinin_detail', $this->joinin_detail);
  276. View::assign('step', '4');
  277. View::assign('sub_step', 'pay');
  278. echo View::fetch($this->template_dir . 'pay');
  279. exit;
  280. }
  281. public function pay_save() {
  282. $param = array();
  283. $param['paying_money_certificate'] = $this->upload_image('paying_money_certificate');
  284. $param['paying_money_certificate_explain'] = input('post.paying_money_certificate_explain');
  285. $param['joinin_state'] = STORE_JOIN_STATE_PAY;
  286. if (empty($param['paying_money_certificate'])) {
  287. $this->error(lang('paying_money_certificate_empty'));
  288. }
  289. $storejoinin_model = model('storejoinin');
  290. $storejoinin_model->editStorejoinin($param, array('member_id' => session('member_id')));
  291. @header('location:' . (string) url('Sellerjoinin/index'));
  292. exit;
  293. }
  294. private function dostep4() {
  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. }
  306. private function show_join_message($message, $btn_next = FALSE, $step = '2') {
  307. View::assign('joinin_detail', $this->joinin_detail);
  308. View::assign('joinin_message', $message);
  309. View::assign('btn_next', $btn_next);
  310. View::assign('step', $step);
  311. View::assign('sub_step', 'step4');
  312. echo View::fetch($this->template_dir . 'step4');
  313. exit;
  314. }
  315. private function upload_image($file) {
  316. //上传文件保存路径
  317. $pic_name = '';
  318. if (!empty($_FILES[$file]['name'])) {
  319. //设置特殊图片名称
  320. $file_name = session('member_id') . '_' . date('YmdHis') . rand(10000, 99999) . '.png';
  321. $res = ds_upload_pic('home' . DIRECTORY_SEPARATOR . 'store_joinin', $file, $file_name);
  322. if ($res['code']) {
  323. $pic_name = $res['data']['file_name'];
  324. } else {
  325. $this->error($res['msg']);
  326. }
  327. }
  328. return $pic_name;
  329. }
  330. /**
  331. * 检查店铺名称是否存在
  332. *
  333. * @param
  334. * @return
  335. */
  336. public function checkname() {
  337. /**
  338. * 实例化卖家模型
  339. */
  340. $store_model = model('store');
  341. $store_name = input('get.store_name');
  342. $store_info = $store_model->getStoreInfo(array('store_name' => $store_name));
  343. if (!empty($store_info['store_name']) && $store_info['member_id'] != session('member_id')) {
  344. echo 'false';
  345. } else {
  346. echo 'true';
  347. }
  348. }
  349. }