123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422 |
- <?php
- namespace app\home\controller;
- use app\common\model\Cache;
- use think\facade\View;
- use think\facade\Lang;
- use think\middleware\SessionInit;
- /**
-
- *
-
- *
- * ----------------------------------------------------------------------------
- *
-
- * 控制器
- */
- class Sellerjoininc2c extends BaseMember
- {
- private $joinin_detail = NULL;
- public function initialize()
- {
- parent::initialize();
- Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerjoinin.lang.php');
- $this->checkLogin();
- $seller_model = model('seller');
- $seller_info = $seller_model->getSellerInfo(array('member_id' => session('member_id')));
- if (!empty($seller_info)) {
- $this->success(lang('already_sub_account'), (string) url('Sellerlogin/login'));
- exit;
- }
- if (request()->action() != 'checkname') {
- $this->check_joinin_state();
- }
- $store_joinin_open = config('ds_config.store_joinin_open');
- if (!$this->joinin_detail || !$this->joinin_detail['joinin_state']) { //已经填写过入驻资料的则不跳转
- if ($store_joinin_open == 0) {
- $this->error(lang('store_joinin_close'));
- } elseif ($store_joinin_open == 2) {
- $this->redirect('Sellerjoinin/' . request()->action());
- }
- }
- $phone_array = explode(',', config('ds_config.site_phone'));
- View::assign('phone_array', $phone_array);
- $help_model = model('help');
- $condition = array();
- $condition[] = array('helptype_id', '=', '99'); //默认显示入驻流程;
- $help_list = $help_model->getShowStoreHelpList($condition);
- View::assign('help_list', $help_list); //左侧帮助类型及帮助
- View::assign('show_sign', 'joinin');
- View::assign('html_title', config('ds_config.site_name') . ' - ' . lang('tenants'));
- View::assign('article_list', ''); //底部不显示文章分类
- }
- private function check_joinin_state()
- {
- $storejoinin_model = model('storejoinin');
- $joinin_detail = $storejoinin_model->getOneStorejoinin(array('member_id' => session('member_id')));
- if (!empty($joinin_detail)) {
- $this->joinin_detail = $joinin_detail;
- switch (intval($joinin_detail['joinin_state'])) {
- case STORE_JOIN_STATE_NEW:
- $this->dostep4();
- $this->show_join_message(lang('apply_submit_success'), FALSE, '3');
- break;
- case STORE_JOIN_STATE_PAY:
- $this->show_join_message(lang('pay_submit_success'), FALSE, '4');
- break;
- case STORE_JOIN_STATE_VERIFY_SUCCESS:
- if (!in_array(request()->action(), array('pay', 'pay_save'))) {
- $this->pay();
- }
- break;
- case STORE_JOIN_STATE_VERIFY_FAIL:
- if (!in_array(request()->action(), array('step1', 'step2', 'step3', 'step4'))) {
- $this->show_join_message(lang('verify_fail') . ':' . $joinin_detail['joinin_message'], HOME_SITE_URL . DIRECTORY_SEPARATOR . '/sellerjoininc2c/step1');
- }
- break;
- case STORE_JOIN_STATE_PAY_FAIL:
- if (!in_array(request()->action(), array('pay', 'pay_save'))) {
- $this->show_join_message(lang('pay_verify_fail') . ':' . $joinin_detail['joinin_message'], HOME_SITE_URL . DIRECTORY_SEPARATOR . '/sellerjoininc2c/pay');
- }
- break;
- case STORE_JOIN_STATE_FINAL:
- $this->success(lang('store_already_open'), (string) url('Sellerlogin/login'));
- break;
- }
- }
- }
- public function index()
- {
- $this->step0();
- }
- public function step0()
- {
- $document_model = model('document');
- $document_info = $document_model->getOneDocumentByCode('open_store');
- View::assign('agreement', htmlspecialchars_decode($document_info['document_content']));
- View::assign('step', 'step1');
- View::assign('sub_step', 'step0');
- echo View::fetch($this->template_dir . 'step0');
- exit;
- }
- public function step1()
- {
- View::assign('step', 'step2');
- View::assign('sub_step', 'step1');
- return View::fetch($this->template_dir . 'step1');
- }
- public function step2()
- {
- if (request()->isPost()) {
- $param = array();
- $param['member_name'] = session('member_name');
- $param['company_name'] = input('post.company_name');
- $param['company_address'] = input('post.company_address');
- $param['store_longitude'] = input('post.longitude');
- $param['store_latitude'] = input('post.latitude');
- $param['company_address_detail'] = input('post.company_address_detail');
- $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));
- $param['contacts_name'] = input('post.contacts_name');
- $param['contacts_phone'] = input('post.contacts_phone');
- $param['contacts_email'] = input('post.contacts_email');
- $param['business_licence_number'] = input('post.business_licence_number');
- $param['business_licence_address'] = input('post.business_licence_address');
- $param['business_licence_start'] = input('post.business_licence_start');
- $param['business_licence_end'] = input('post.business_licence_end');
- $param['business_sphere'] = input('post.business_sphere');
- // $param['business_licence_number_electronic'] = $this->upload_image('business_licence_number_electronic');
- $param['business_licence_number_electronic'] = input('post.member_idcard_image2');
- // $param['business_author_letter'] = $this->upload_image('business_author_letter');
- $param['business_author_letter'] = input('post.member_idcard_image3');
- $this->step2_save_valid($param);
- $res = $this->getIdCardInfo2($param);
- if ($res['code'] == 200) {
- $info = $res['data'];
- if ($param['business_licence_number'] != $info['idcard'] || $param['contacts_name'] !== $info['name']) {
- //缓存图片
- $memberId = session('member_id');
- session('member_image2_'.$memberId,$param);
- session('member_image3_'.$memberId,$param);
- // dd();
- $this->error('您提交的身份信息或身份证照片未通过校验,请仔细核对后提交');
- // ds_json_encode(10001, '您提交的身份信息或身份证照片未通过校验,请仔细核对后提交');
- }
- } else {
- $memberId = session('member_id');
- session('member_image2_'.$memberId,$param);
- session('member_image3_'.$memberId,$param);
- $this->error($res['msg']);
- // ds_json_encode(10001, $res['msg']);
- }
- $storejoinin_model = model('storejoinin');
- $joinin_info = $storejoinin_model->getOneStorejoinin(array('member_id' => session('member_id')));
- if (empty($joinin_info)) {
- $param['member_id'] = session('member_id');
- $storejoinin_model->addStorejoinin($param);
- } else {
- $storejoinin_model->editStorejoinin($param, array('member_id' => session('member_id')));
- }
- }
- View::assign('step', 'step2');
- View::assign('sub_step', 'step2');
- echo View::fetch($this->template_dir . 'step2');
- exit;
- }
- private function step2_save_valid($param)
- {
- $sellerjoinin_validate = ds_validate('sellerjoinin');
- if (!$sellerjoinin_validate->scene('step2_save_valid2')->check($param)) {
- $this->error($sellerjoinin_validate->getError());
- }
- }
- public function step3()
- {
- if (request()->isPost()) {
- $param = array();
- $param['settlement_bank_account_name'] = input('post.settlement_bank_account_name');
- $param['settlement_bank_account_number'] = input('post.settlement_bank_account_number');
- $this->step3_save_valid($param);
- $storejoinin_model = model('storejoinin');
- $storejoinin_model->editStorejoinin($param, array('member_id' => session('member_id')));
- }
- //商品分类
- $gc = model('goodsclass');
- $gc_list = $gc->getGoodsclassListByParentId(0);
- View::assign('gc_list', $gc_list);
- //店铺等级
- $grade_list = rkcache('storegrade', true);
- View::assign('grade_list', $grade_list);
- //店铺分类
- $storeclass_model = model('storeclass');
- $store_class = $storeclass_model->getStoreclassList(array(), '', false);
- View::assign('store_class', $store_class);
- View::assign('step', '3');
- View::assign('sub_step', 'step3');
- echo View::fetch($this->template_dir . 'step3');
- exit;
- }
- private function step3_save_valid($param)
- {
- $sellerjoinin_validate = ds_validate('sellerjoinin');
- if (!$sellerjoinin_validate->scene('step3_save_valid3')->check($param)) {
- $this->error($sellerjoinin_validate->getError());
- }
- }
- public function step4()
- {
- $store_class_ids = array();
- $store_class_names = array();
- $store_class_ids_array = input('post.store_class_ids/a'); #获取数组
- if (!empty($store_class_ids_array)) {
- foreach ($store_class_ids_array as $value) {
- $store_class_ids[] = $value;
- }
- }
- $store_class_names_array = input('post.store_class_names/a'); #获取数组
- if (!empty($store_class_names_array)) {
- foreach ($store_class_names_array as $value) {
- $store_class_names[] = $value;
- }
- }
- //取最小级分类最新分佣比例
- $sc_ids = array();
- foreach ($store_class_ids as $v) {
- $v = explode(',', trim($v, ','));
- if (!empty($v) && is_array($v)) {
- $sc_ids[] = end($v);
- }
- }
- $store_class_commis_rates = array();
- if (!empty($sc_ids)) {
- $goods_class_list = model('goodsclass')->getGoodsclassListByIds($sc_ids);
- if (!empty($goods_class_list) && is_array($goods_class_list)) {
- $sc_ids = array();
- foreach ($goods_class_list as $v) {
- $store_class_commis_rates[] = $v['commis_rate'];
- }
- }
- }
- $param = array();
- $param['seller_name'] = $this->member_info['member_name'];
- $param['store_name'] = trim(input('post.store_name'));
- $param['store_type'] = 1;
- $param['store_class_ids'] = serialize($store_class_ids);
- $param['store_class_names'] = serialize($store_class_names);
- $param['joinin_year'] = intval(input('post.joinin_year'));
- $param['joinin_state'] = STORE_JOIN_STATE_NEW;
- $param['store_class_commis_rates'] = implode(',', $store_class_commis_rates);
- //取店铺等级信息
- $grade_list = rkcache('storegrade', true);
- $storegrade_id = intval(input('post.storegrade_id'));
- if ($storegrade_id <= 0) {
- $this->error(lang('param_error'));
- }
- if (!empty($grade_list[$storegrade_id])) {
- $param['storegrade_id'] = $storegrade_id;
- $param['storegrade_name'] = $grade_list[$storegrade_id]['storegrade_name'];
- $param['sg_info'] = serialize(array('storegrade_price' => $grade_list[$storegrade_id]['storegrade_price']));
- }
- //取最新店铺分类信息
- $store_class_info = model('storeclass')->getStoreclassInfo(array('storeclass_id' => intval(input('post.storeclass_id'))));
- if ($store_class_info) {
- $param['storeclass_id'] = $store_class_info['storeclass_id'];
- $param['storeclass_name'] = $store_class_info['storeclass_name'];
- $param['storeclass_bail'] = $store_class_info['storeclass_bail'];
- }
- //店铺应付款
- $param['paying_amount'] = floatval($grade_list[$storegrade_id]['storegrade_price']) * $param['joinin_year'] + floatval($param['storeclass_bail']);
- $this->step4_save_valid($param);
- $storejoinin_model = model('storejoinin');
- $storejoinin_model->editStorejoinin($param, array('member_id' => session('member_id')));
- header('location:' . (string) url('Sellerjoininc2c/index'));
- exit;
- }
- private function step4_save_valid($param)
- {
- $sellerjoinin_validate = ds_validate('sellerjoinin');
- if (!$sellerjoinin_validate->scene('step4_save_valid4')->check($param)) {
- $this->error($sellerjoinin_validate->getError());
- }
- }
- public function pay()
- {
- if (!empty($this->joinin_detail['sg_info'])) {
- $store_grade_info = model('storegrade')->getOneStoregrade($this->joinin_detail['storegrade_id']);
- $this->joinin_detail['storegrade_price'] = $store_grade_info['storegrade_price'];
- } else {
- $this->joinin_detail['sg_info'] = @unserialize($this->joinin_detail['sg_info']);
- if (is_array($this->joinin_detail['sg_info'])) {
- $this->joinin_detail['storegrade_price'] = $this->joinin_detail['sg_info']['storegrade_price'];
- }
- }
- View::assign('joinin_detail', $this->joinin_detail);
- View::assign('step', '4');
- View::assign('sub_step', 'pay');
- echo View::fetch($this->template_dir . 'pay');
- exit;
- }
- public function pay_save()
- {
- $param = array();
- $param['paying_money_certificate'] = $this->upload_image('paying_money_certificate');
- $param['paying_money_certificate_explain'] = input('post.paying_money_certificate_explain');
- $param['joinin_state'] = STORE_JOIN_STATE_PAY;
- if (empty($param['paying_money_certificate'])) {
- $this->error(lang('paying_money_certificate_empty'));
- }
- $storejoinin_model = model('storejoinin');
- $storejoinin_model->editStorejoinin($param, array('member_id' => session('member_id')));
- header('location:' . (string) url('Sellerjoininc2c/index'));
- exit;
- }
- private function dostep4()
- {
- if (!empty($this->joinin_detail['sg_info'])) {
- $store_grade_info = model('storegrade')->getOneStoregrade($this->joinin_detail['storegrade_id']);
- $this->joinin_detail['storegrade_price'] = $store_grade_info['storegrade_price'];
- } else {
- $this->joinin_detail['sg_info'] = @unserialize($this->joinin_detail['sg_info']);
- if (is_array($this->joinin_detail['sg_info'])) {
- $this->joinin_detail['storegrade_price'] = $this->joinin_detail['sg_info']['storegrade_price'];
- }
- }
- View::assign('joinin_detail', $this->joinin_detail);
- }
- private function show_join_message($message, $btn_next = FALSE, $step = 'step2')
- {
- View::assign('joinin_detail', $this->joinin_detail);
- View::assign('joinin_message', $message);
- View::assign('btn_next', $btn_next);
- View::assign('step', $step);
- View::assign('sub_step', 'step4');
- echo View::fetch($this->template_dir . 'step4');
- exit;
- }
- private function upload_image($file)
- {
- $pic_name = '';
- if (!empty($_FILES[$file]['name'])) {
- //设置特殊图片名称
- $file_name = session('member_id') . '_' . date('YmdHis') . rand(10000, 99999) . '.png';
- $res = ds_upload_pic('home' . DIRECTORY_SEPARATOR . 'store_joinin', $file, $file_name);
- if ($res['code']) {
- $pic_name = $res['data']['file_name'];
- } else {
- $this->error($res['msg']);
- }
- }
- return $pic_name;
- }
- /**
- * 检查店铺名称是否存在
- *
- * @param
- * @return
- */
- public function checkname()
- {
- /**
- * 实例化卖家模型
- */
- $store_model = model('store');
- $store_name = input('get.store_name');
- $store_info = $store_model->getStoreInfo(array('store_name' => $store_name));
- if (!empty($store_info['store_name']) && $store_info['member_id'] != session('member_id')) {
- echo 'false';
- } else {
- echo 'true';
- }
- }
- }
|