Sellerjoinin.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  10. * 网站地址: https://www.valimart.net/
  11. * ----------------------------------------------------------------------------
  12. *
  13. * ============================================================================
  14. * 控制器
  15. */
  16. class Sellerjoinin extends BaseMember {
  17. private $joinin_detail = NULL;
  18. public function initialize() {
  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 == 3) {
  36. $this->redirect('Sellerjoininc2c/' . 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. $storejoinin_model = model('storejoinin');
  52. $joinin_detail = $storejoinin_model->getOneStorejoinin(array('member_id' => session('member_id')));
  53. if (!empty($joinin_detail)) {
  54. $this->joinin_detail = $joinin_detail;
  55. switch (intval($joinin_detail['joinin_state'])) {
  56. case STORE_JOIN_STATE_NEW:
  57. $this->dostep4();
  58. $this->show_join_message(lang('apply_submit_success'), FALSE, '3');
  59. break;
  60. case STORE_JOIN_STATE_PAY:
  61. $this->show_join_message(lang('pay_submit_success'), FALSE, '4');
  62. break;
  63. case STORE_JOIN_STATE_VERIFY_SUCCESS:
  64. if (!in_array(request()->action(), array('pay', 'pay_save'))) {
  65. $this->pay();
  66. }
  67. break;
  68. case STORE_JOIN_STATE_VERIFY_FAIL:
  69. if (!in_array(request()->action(), array('step1', 'step2', 'step3', 'step4'))) {
  70. $this->show_join_message(lang('verify_fail') . ':' . $joinin_detail['joinin_message'], (string) url('Sellerjoinin/step1'));
  71. }
  72. break;
  73. case STORE_JOIN_STATE_PAY_FAIL:
  74. if (!in_array(request()->action(), array('pay', 'pay_save'))) {
  75. $this->show_join_message(lang('pay_verify_fail') . ':' . $joinin_detail['joinin_message'], (string) url('Sellerjoinin/pay'));
  76. }
  77. break;
  78. case STORE_JOIN_STATE_FINAL:
  79. $this->success(lang('store_already_open'), (string) url('Sellerlogin/login'));
  80. break;
  81. }
  82. }
  83. }
  84. public function index() {
  85. echo $this->step0();
  86. exit;
  87. }
  88. public function step0() {
  89. $document_model = model('document');
  90. $document_info = $document_model->getOneDocumentByCode('open_store');
  91. View::assign('agreement', htmlspecialchars_decode($document_info['document_content']));
  92. View::assign('step', '0');
  93. View::assign('sub_step', 'step0');
  94. echo View::fetch($this->template_dir . 'step0');
  95. exit;
  96. }
  97. public function step1() {
  98. View::assign('step', '1');
  99. View::assign('sub_step', 'step1');
  100. View::assign('baidu_ak', config('ds_config.baidu_ak'));
  101. echo View::fetch($this->template_dir . 'step1');
  102. exit;
  103. }
  104. public function step2() {
  105. if (request()->isPost()) {
  106. $param = array();
  107. $param['member_name'] = session('member_name');
  108. $param['company_name'] = input('post.company_name');
  109. $param['store_longitude'] = input('post.longitude');
  110. $param['store_latitude'] = input('post.latitude');
  111. $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)));
  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'] = $this->upload_image('business_licence_number_electronic');
  124. $this->step2_save_valid($param);
  125. $storejoinin_model = model('storejoinin');
  126. $joinin_info = $storejoinin_model->getOneStorejoinin(array('member_id' => session('member_id')));
  127. if (empty($joinin_info)) {
  128. $param['member_id'] = session('member_id');
  129. $storejoinin_model->addStorejoinin($param);
  130. } else {
  131. $storejoinin_model->editStorejoinin($param, array('member_id' => session('member_id')));
  132. }
  133. }
  134. View::assign('step', '2');
  135. View::assign('sub_step', 'step2');
  136. echo View::fetch($this->template_dir . 'step2');
  137. exit;
  138. }
  139. private function step2_save_valid($param) {
  140. $sellerjoinin_validate = ds_validate('sellerjoinin');
  141. if (!$sellerjoinin_validate->scene('step2_save_valid')->check($param)) {
  142. $this->error($sellerjoinin_validate->getError());
  143. }
  144. }
  145. public function step3() {
  146. if (request()->isPost()) {
  147. $param = array();
  148. $param['bank_account_name'] = input('post.bank_account_name');
  149. $param['bank_account_number'] = input('post.bank_account_number');
  150. $param['bank_name'] = input('post.bank_name');
  151. $param['bank_address'] = input('post.bank_address');
  152. $is_settlement_account = input('post.is_settlement_account');
  153. if (!empty($is_settlement_account)) {
  154. $param['is_settlement_account'] = 1;
  155. $param['settlement_bank_account_name'] = input('post.bank_account_name');
  156. $param['settlement_bank_account_number'] = input('post.bank_account_number');
  157. $param['settlement_bank_name'] = input('post.bank_name');
  158. $param['settlement_bank_address'] = input('post.bank_address');
  159. } else {
  160. $param['is_settlement_account'] = 2;
  161. $param['settlement_bank_account_name'] = input('post.settlement_bank_account_name');
  162. $param['settlement_bank_account_number'] = input('post.settlement_bank_account_number');
  163. $param['settlement_bank_name'] = input('post.settlement_bank_name');
  164. $param['settlement_bank_address'] = input('post.settlement_bank_address');
  165. }
  166. $this->step3_save_valid($param);
  167. $storejoinin_model = model('storejoinin');
  168. $storejoinin_model->editStorejoinin($param, array('member_id' => session('member_id')));
  169. }
  170. //商品分类
  171. $gc = model('goodsclass');
  172. $gc_list = $gc->getGoodsclassListByParentId(0);
  173. View::assign('gc_list', $gc_list);
  174. //店铺等级
  175. $grade_list = rkcache('storegrade', true);
  176. View::assign('grade_list', $grade_list);
  177. //店铺分类
  178. $storeclass_model = model('storeclass');
  179. $store_class = $storeclass_model->getStoreclassList(array(), '', false);
  180. View::assign('store_class', $store_class);
  181. View::assign('step', '3');
  182. View::assign('sub_step', 'step3');
  183. echo View::fetch($this->template_dir . 'step3');
  184. exit;
  185. }
  186. private function step3_save_valid($param) {
  187. $sellerjoinin_validate = ds_validate('sellerjoinin');
  188. if (!$sellerjoinin_validate->scene('step3_save_valid')->check($param)) {
  189. $this->error($sellerjoinin_validate->getError());
  190. }
  191. }
  192. public function step4() {
  193. $store_class_ids = array();
  194. $store_class_names = array();
  195. $store_class_ids_array = input('post.store_class_ids/a'); #获取数组
  196. if (!empty($store_class_ids_array)) {
  197. foreach ($store_class_ids_array as $value) {
  198. $store_class_ids[] = $value;
  199. }
  200. }
  201. $store_class_names_array = input('post.store_class_names/a'); #获取数组
  202. if (!empty($store_class_names_array)) {
  203. foreach ($store_class_names_array as $value) {
  204. $store_class_names[] = $value;
  205. }
  206. }
  207. //取最小级分类最新分佣比例
  208. $sc_ids = array();
  209. foreach ($store_class_ids as $v) {
  210. $v = explode(',', trim($v, ','));
  211. if (!empty($v) && is_array($v)) {
  212. $sc_ids[] = end($v);
  213. }
  214. }
  215. $store_class_commis_rates = array();
  216. if (!empty($sc_ids)) {
  217. $goods_class_list = model('goodsclass')->getGoodsclassListByIds($sc_ids);
  218. if (!empty($goods_class_list) && is_array($goods_class_list)) {
  219. $sc_ids = array();
  220. foreach ($goods_class_list as $v) {
  221. $store_class_commis_rates[] = $v['commis_rate'];
  222. }
  223. }
  224. }
  225. $param = array();
  226. $param['seller_name'] = $this->member_info['member_name'];
  227. $param['store_name'] = trim(input('post.store_name'));
  228. $param['store_type'] = 0;
  229. $param['store_class_ids'] = serialize($store_class_ids);
  230. $param['store_class_names'] = serialize($store_class_names);
  231. $param['joinin_year'] = intval(input('post.joinin_year'));
  232. $param['joinin_state'] = STORE_JOIN_STATE_NEW;
  233. $param['store_class_commis_rates'] = implode(',', $store_class_commis_rates);
  234. //取店铺等级信息
  235. $grade_list = rkcache('storegrade', true);
  236. $storegrade_id = intval(input('post.storegrade_id'));
  237. if ($storegrade_id <= 0) {
  238. $this->error(lang('param_error'));
  239. }
  240. if (!empty($grade_list[$storegrade_id])) {
  241. $param['storegrade_id'] = $storegrade_id;
  242. $param['storegrade_name'] = $grade_list[$storegrade_id]['storegrade_name'];
  243. $param['sg_info'] = serialize(array('storegrade_price' => $grade_list[$storegrade_id]['storegrade_price']));
  244. }
  245. //取最新店铺分类信息
  246. $store_class_info = model('storeclass')->getStoreclassInfo(array('storeclass_id' => intval(input('post.storeclass_id'))));
  247. if ($store_class_info) {
  248. $param['storeclass_id'] = $store_class_info['storeclass_id'];
  249. $param['storeclass_name'] = $store_class_info['storeclass_name'];
  250. $param['storeclass_bail'] = $store_class_info['storeclass_bail'];
  251. }
  252. //店铺应付款
  253. $param['paying_amount'] = floatval($grade_list[$storegrade_id]['storegrade_price']) * $param['joinin_year'] + floatval($param['storeclass_bail']);
  254. $this->step4_save_valid($param);
  255. $storejoinin_model = model('storejoinin');
  256. $storejoinin_model->editStorejoinin($param, array('member_id' => session('member_id')));
  257. @header('location: ' . (string) url('Sellerjoinin/index'));
  258. exit;
  259. }
  260. private function step4_save_valid($param) {
  261. $sellerjoinin_validate = ds_validate('sellerjoinin');
  262. if (!$sellerjoinin_validate->scene('step4_save_valid')->check($param)) {
  263. $this->error($sellerjoinin_validate->getError());
  264. }
  265. }
  266. public function pay() {
  267. if (!empty($this->joinin_detail['sg_info'])) {
  268. $store_grade_info = model('storegrade')->getOneStoregrade($this->joinin_detail['storegrade_id']);
  269. $this->joinin_detail['storegrade_price'] = $store_grade_info['storegrade_price'];
  270. } else {
  271. $this->joinin_detail['sg_info'] = @unserialize($this->joinin_detail['sg_info']);
  272. if (is_array($this->joinin_detail['sg_info'])) {
  273. $this->joinin_detail['storegrade_price'] = $this->joinin_detail['sg_info']['storegrade_price'];
  274. }
  275. }
  276. View::assign('joinin_detail', $this->joinin_detail);
  277. View::assign('step', '4');
  278. View::assign('sub_step', 'pay');
  279. echo View::fetch($this->template_dir . 'pay');
  280. exit;
  281. }
  282. public function pay_save() {
  283. $param = array();
  284. $param['paying_money_certificate'] = $this->upload_image('paying_money_certificate');
  285. $param['paying_money_certificate_explain'] = input('post.paying_money_certificate_explain');
  286. $param['joinin_state'] = STORE_JOIN_STATE_PAY;
  287. if (empty($param['paying_money_certificate'])) {
  288. $this->error(lang('paying_money_certificate_empty'));
  289. }
  290. $storejoinin_model = model('storejoinin');
  291. $storejoinin_model->editStorejoinin($param, array('member_id' => session('member_id')));
  292. @header('location:' . (string) url('Sellerjoinin/index'));
  293. exit;
  294. }
  295. private function dostep4() {
  296. if (!empty($this->joinin_detail['sg_info'])) {
  297. $store_grade_info = model('storegrade')->getOneStoregrade($this->joinin_detail['storegrade_id']);
  298. $this->joinin_detail['storegrade_price'] = $store_grade_info['storegrade_price'];
  299. } else {
  300. $this->joinin_detail['sg_info'] = @unserialize($this->joinin_detail['sg_info']);
  301. if (is_array($this->joinin_detail['sg_info'])) {
  302. $this->joinin_detail['storegrade_price'] = $this->joinin_detail['sg_info']['storegrade_price'];
  303. }
  304. }
  305. View::assign('joinin_detail', $this->joinin_detail);
  306. }
  307. private function show_join_message($message, $btn_next = FALSE, $step = '2') {
  308. View::assign('joinin_detail', $this->joinin_detail);
  309. View::assign('joinin_message', $message);
  310. View::assign('btn_next', $btn_next);
  311. View::assign('step', $step);
  312. View::assign('sub_step', 'step4');
  313. echo View::fetch($this->template_dir . 'step4');
  314. exit;
  315. }
  316. private function upload_image($file) {
  317. //上传文件保存路径
  318. $pic_name = '';
  319. if (!empty($_FILES[$file]['name'])) {
  320. //设置特殊图片名称
  321. $file_name = session('member_id') . '_' . date('YmdHis') . rand(10000, 99999) . '.png';
  322. $res = ds_upload_pic('home' . DIRECTORY_SEPARATOR . 'store_joinin', $file, $file_name);
  323. if ($res['code']) {
  324. $pic_name = $res['data']['file_name'];
  325. } else {
  326. $this->error($res['msg']);
  327. }
  328. }
  329. return $pic_name;
  330. }
  331. /**
  332. * 检查店铺名称是否存在
  333. *
  334. * @param
  335. * @return
  336. */
  337. public function checkname() {
  338. /**
  339. * 实例化卖家模型
  340. */
  341. $store_model = model('store');
  342. $store_name = input('get.store_name');
  343. $store_info = $store_model->getStoreInfo(array('store_name' => $store_name));
  344. if (!empty($store_info['store_name']) && $store_info['member_id'] != session('member_id')) {
  345. echo 'false';
  346. } else {
  347. echo 'true';
  348. }
  349. }
  350. }
  351. ?>