Sellerjoininc2c.php 16 KB

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