['except'=>'login'], //在除login之外的其他方法执行前先执行islogin方法 // 'removesession' => ['only'=>'logout'], //在logout执行前先执行removesession // ]; protected $beforeActionList = [ 'checkAuth'=>['except'=>'pagequery'], 'checkDataAuth'=>['only'=>'setspecs,getspecs,getspeccats,delspecset,getgoodsspeccats,addgoods,editgoods,getgoodsinfo,uploadshopimg,delgoods,delshop,shopinfo,getsellerorderlist,orderconfirm,getgoodslist,viewcertificate,userupdate,getshopimg,getbank'], 'checkShopAuth' => ['except'=>'shopjoin,getshopjoininfo,usershoplist,pagequery'], ]; /** * 获取商家入驻信息 */ public function getShopJoinInfo(){ $where['userId'] = $this->getUserId(); $where['shopId'] = (int)input('post.shopId'); $where['dataFlag'] = 1; $m = new M(); $m->setTable('shops'); $shopInfo = $m->getInfo($where,'shopName,userName,phone,provinceId,cityId,countyId,townId,villageId,shopAddress,lng,lat,bankName,accountName,bankNo,idCardFrontImg,idCardBackImg,commissionImg,businessLicenceImg,confirmationImg'); if($shopInfo){ exit(jsonReturn('',1,$shopInfo)); } exit(jsonReturn('获取失败!')); } /** * 商家入驻 */ public function shopJoin(){ $data = input('post.'); $validate = \think\Loader::validate('Shops'); if(!$validate->scene('join')->check($data)){ exit(jsonReturn($validate->getError())); } $data['shopType'] = (int)input('post.shopType',1); $data['userId'] = $this->getUserId(); $data['status']=0; $m = new M(); $m->setTable('shops'); $shopId = isset($data['shopId']) ? $data['shopId'] : 0; if($shopId){ //unset($data['shopId']); $isSuccess = $m->updateInfo(['shopId'=>$shopId,'userId'=>$data['userId']],$data); //$m->insertInfo($data); }else{ if($m->getField(['userId'=>$data['userId'],'shopName'=>$data['shopName'],'dataFlag'=>1],'shopId')){ exit(jsonReturn('请不要重复提交')); } $data['createTime'] = time(); $isSuccess = $m->insertInfo($data); } if(false !== $isSuccess){ $userPhone = getAdminPhone(); $tpl = WSTMsgTemplates('PHONE_ADMIN_SHOP_APPLAY_NOTICE'); if( $tpl['tplContent']!='' && $tpl['status']=='1'){ $params = ['tpl'=>$tpl,'params'=>['name'=>$this->user['loginName']]]; $m = Model('common/LogSms'); $rv = $m->sendSMS(0,$userPhone,$params,'PHONE_ADMIN_SHOP_APPLAY_NOTICE',0); } exit(jsonReturn('提交成功,请等待系统审核',1)); }else{ exit(jsonReturn('操作失败,请重试')); } } /** * 商家列表 * @return [type] [description] */ public function userShopList(){ $m = new M(); $m->setTable('shops'); $where['userId'] = $this->getUserId(); $where['shopType'] = (int)input('post.shopType',1); //$where['status']=1; $where['dataFlag']=1; $shops = $m->getList($where,'shopId,shopName,shopImg,status'); exit(jsonReturn('',1,$shops)); } /** * 获取商家信息 * @return [type] [description] */ public function shopInfo(){ $m = new SM(); $rs = $m->shopInfo(); exit(json_encode($rs)); } /** * 获取商家图片 * @return [type] [description] */ public function getShopImg(){ $m = new SM(); $rs = $m->getShopImg(); exit(json_encode($rs)); } /** * [删除店铺] * @return [type] [description] */ public function delShop(){ $shopId=(int)input('post.shopId'); if($shopId){ $payPwd = input('post.payPwd'); if(md5($payPwd) != $this->user['payPwd']){ exit(jsonReturn('密码错误')); } $m = new M(); $m->setTable('shops'); $rs = $m->updateInfo(['shopId'=>(int)$shopId,'userId'=>$this->getUserId()],['dataFlag'=>-1]); if(false !== $rs){ exit(jsonReturn('删除店铺成功',1)); } } exit(jsonReturn('删除店铺失败')); } /** * 添加规格 * @return [type] [description] */ public function setSpecs(){ $m = new SM(); $rs = $m->setSpecs($this->getUserId()); exit(json_encode($rs)); } /** * 获名总规格名 * @return [type] [description] */ public function getSpecs(){ $m = new SM(); $rs = $m->getSpecs(); exit(json_encode($rs)); } /** * 删除总规格名 * @return [type] [description] */ public function delSpecSet(){ $m = new M(); $m->setTable('spec_set'); $rs = $m->updateInfo(['id'=>(int)input('post.id'),'userId'=>$this->getUserId()],['dataFlag'=>-1]); if(false !== $rs){ exit(jsonReturn('删除成功!',1)); } exit(jsonReturn('删除失败!')); } /** * 获名总规格下属性名和属性值 */ public function getSpecCats(){ $m = new SM(); $rs = $m->getSpecCats($this->getUserId()); exit(json_encode($rs)); } /** * 获名商品总规格下属性名和属性值 */ public function getGoodsSpecCats(){ $m = new SM(); $rs = $m->getGoodsSpecCats($this->getUserId()); exit(json_encode($rs)); } /** * 获名商品分类 */ public function getGoodsCats(){ $pid = (int)input('post.pid'); $m = Model('common/GoodsCats'); $rs = $m->listQuery($pid,-1,'catId,catName'); exit(jsonReturn('',1,$rs)); } /** * 添加商品 */ public function addGoods(){ $m = new SM(); $rs = $m->addGoods(); exit(json_encode($rs)); } /** * 编辑商品 */ public function editGoods(){ $m = new SM(); $rs = $m->editGoods(); exit(json_encode($rs)); } /** * 申请商超/商厦/商都 * @param [type] $userId [description] * @return [type] [description] */ public function userUpdate(){ $m = new SM(); if(2 == $this->user['authType'] && 1 == $this->user['userType'] ){ $rs = $m->userUpdate($this->getUserId()); }else{ $rs = WSTReturn('仅合作认证用户并开店成功后可申请'); } exit(json_encode($rs)); } /** * 获取申请商超/商厦/商都信息 * @param [type] $userId [description] * @return [type] [description] */ public function getUserUpdate(){ $m = new SM(); if(2 == $this->user['authType'] && 1 == $this->user['userType'] ){ $rs = $m->getUserUpdate($this->getUserId()); }else{ $rs = WSTReturn('仅合作认证用户并开店成功后可申请'.$this->user['authType']); } exit(json_encode($rs)); } public function getBank(){ $m = new M(); $m->setTable('shops'); $bankInfo = $m->getInfo(['shopId'=>(int)input('post.shopId')],'bankName,accountName,bankNo'); exit(jsonReturn('',1,$bankInfo)); } //商家申请提现 public function withdrawal(){ $rs = Model('Common/CashDraws')->drawWangByShop(); exit(json_encode($rs)); } /** * 获取商品信息 */ public function getGoodsInfo(){ $m = new SM(); $rs = $m->getGoodsInfo(); exit(json_encode($rs)); } /** * 上传店铺主图和轮播图 */ public function uploadShopImg(){ $m = new SM(); $rs = $m->uploadShopImg(); exit(json_encode($rs)); } /** * 获取商品列表 */ public function getGoodsList(){ $m = new SM(); $rs = $m->getGoodsList(); exit(json_encode($rs)); } /** * 获取店铺首页商品列表 */ public function getShopIndexGoodsList(){ $m = new SM(); $rs = $m->getShopIndexGoodsList(0,'goodsImg,goodsName,shopPrice,saleNum','goodsOrder DESC,saleNum DESC'); exit(json_encode($rs)); } /** * 删除商品 */ public function delGoods(){ $goodsId = (int)input('post.goodsId/d'); if($goodsId){ $m = new M(); $m->setTable('goods'); if(false !== $m->updateInfo(['goodsId'=>$goodsId],['dataFlag'=>-1])){ exit(jsonReturn('删除成功',1)); } } exit(jsonReturn('删除失败')); } /** * 店铺公告页 */ public function notice(){ $notice = model('shops')->getNotice(); $this->assign('notice',$notice); return $this->fetch('shops/shops/notice'); } /** * 修改店铺公告 */ public function editNotice(){ $s = model('shops'); return $s->editNotice(); } /** * 商家登录 */ public function login(){ $USER = session('WST_USER'); if(!empty($USER) && isset($USER['shopId'])){ $this->redirect("shops/index"); } $loginName = cookie("loginName"); if(!empty($loginName)){ $this->assign('loginName',cookie("loginName")); }else{ $this->assign('loginName',''); } return $this->fetch('shop_login'); } /** * 商家中心 */ public function index(){ session('WST_MENID1',null); session('WST_MENUID31',null); $s = model('shops'); $data = $s->getShopSummary((int)session('WST_USER.shopId')); $this->assign('data',$data); return $this->fetch('shops/index'); } /** * 店铺列表 */ public function pageQuery(){ $m = model('shops'); $rs = $m->pageQuery(input('pagesize/d')); foreach ($rs['Rows'] as $key =>$v){ $rs['Rows'][$key]['shopImg'] = WSTImg($v['shopImg'],3); } exit(jsonReturn('',1,$rs)); } /** * 店铺街 */ public function shopStreet(){ $g = new GoodsCats(); $goodsCats = $g->listQuery(0); $this->assign('goodscats',$goodsCats); //店铺街列表 $s = model('shops'); $pagesize = 10; $selectedId = input("get.id/d"); $this->assign('selectedId',$selectedId); $list = $s->pageQuery($pagesize); $this->assign('list',$list); $this->assign('keyword',input('keyword')); $this->assign('keytype',1); return $this->fetch('shop_street'); } /** * 店铺详情 */ public function home(){ $shopId = (int)input("param.shopId/d"); hook("homeBeforeGoShopHome",["shopId"=>$shopId]); hook("goShopAfterAddView",["shopId"=>$shopId,'path'=>1]); $s = model('shops'); $data['shop'] = $s->getShopInfo($shopId); $ct1 = input("param.ct1/d",0); $ct2 = input("param.ct2/d",0); $goodsName = input("param.goodsName"); if(1778 != $shopId && !empty($this->is_icp)) return $this->fetch('error_lost'); if(($data['shop']['shopId']==1 || $shopId==0) && $ct1==0 && !isset($goodsName)){ $params = input(); unset($params["shopId"]); $this->redirect(Url('home/shops/selfShop'),$params); } if(empty($data['shop']))return $this->fetch('error_lost'); $data['shopcats'] = $f = model('ShopCats','model')->getShopCats($shopId); $g = model('goods'); $data['list'] = $g->shopGoods($shopId); //dump($data['list']);die; $this->assign('msort',input("param.msort/d",0));//筛选条件 $this->assign('mdesc',input("param.mdesc/d",1));//升降序 $this->assign('sprice',input("param.sprice"));//价格范围 $this->assign('eprice',input("param.eprice")); $this->assign('ct1',$ct1);//一级分类 $this->assign('ct2',$ct2);//二级分类 $this->assign('goodsName',urldecode($goodsName));//搜索 $this->assign('data',$data); return $this->fetch('shop_home'); } /** * 店铺分类 */ public function cat(){ $s = model('shops'); $shopId = (int)input("param.shopId/d"); $data['shop'] = $s->getShopInfo($shopId); $ct1 = input("param.ct1/d",0); $ct2 = input("param.ct2/d",0); $goodsName = input("param.goodsName"); if(($data['shop']['shopId']==1 || $shopId==0) && $ct1==0 && !isset($goodsName)){ $params = input(); unset($params["shopId"]); $this->redirect('shops/selfShop',$params); } if(empty($data['shop']))return $this->fetch('error_lost'); $data['shopcats'] = $f = model('ShopCats','model')->getShopCats($shopId); $g = model('goods'); $data['list'] = $g->shopGoods($shopId); $this->assign('msort',input("param.msort/d",0));//筛选条件 $this->assign('mdesc',input("param.mdesc/d",1));//升降序 $this->assign('sprice',input("param.sprice"));//价格范围 $this->assign('eprice',input("param.eprice")); $this->assign('ct1',$ct1);//一级分类 $this->assign('ct2',$ct2);//二级分类 $this->assign('goodsName',urldecode($goodsName));//搜索 $this->assign('data',$data); return $this->fetch('shop_home'); } /** * 查看店铺设置 */ public function info(){ $s = model('shops'); $object = $s->getByView((int)session('WST_USER.shopId')); $bankList= model('banks')->listQuery(); $this->assign('bankList',$bankList); $this->assign('object',$object); return $this->fetch('shops/shops/view'); } /** * 自营店铺 */ public function selfShop(){ hook("homeBeforeGoSelfShop",["shopId"=>1]); $s = model('shops'); $data['shop'] = $s->getShopInfo(1); if(empty($data['shop']))return $this->fetch('error_lost'); $this->assign('selfShop',1); $data['shopcats'] = model('ShopCats')->getShopCats(1); $this->assign('goodsName',urldecode(input("param.goodsName")));//搜索 // 店长推荐 $data['rec'] = $s->getRecGoods('rec',6); // 热销商品 $data['hot'] = $s->getRecGoods('hot',6); $this->assign('data',$data); return $this->fetch('self_shop'); } /** * 编辑店铺资料 */ public function editInfo(){ $rs = model('shops')->editInfo(); return $rs; } /** * 获取店铺金额 */ public function getShopMoney(){ $rs = model('shops')->getFieldsById((int)session('WST_USER.shopId'),'shopMoney,lockMoney,rechargeMoney'); $urs = model('users')->getFieldsById((int)session('WST_USER.userId'),'payPwd'); $rs['isSetPayPwd'] = ($urs['payPwd']=='')?0:1; $rs['isDraw'] = ((float)WSTConf('CONF.drawCashShopLimit')<=$rs['shopMoney'])?1:0; unset($urs); return WSTReturn('',1,$rs); } /** * 跳去商家入驻 */ public function join(){ $rs = model('shops')->checkApply(); $this->assign('isApply',(!empty($rs) && $rs['applyStatus']>=1)?1:0); $this->assign('applyStep',empty($rs)?1:$rs['applyStep']); $articles = model('Articles')->getArticlesByCat(53); // 防止不存在入驻文章时报错 if(!isset($articles['105']))$articles['105']['articleContent'] = '无相关说明,请咨询商城客服~'; if(!isset($articles['106']))$articles['106']['articleContent'] = '无相关说明,请咨询商城客服~'; if(!isset($articles['107']))$articles['107']['articleContent'] = '无相关说明,请咨询商城客服~'; if(!isset($articles['108']))$articles['108']['articleContent'] = '无相关说明,请咨询商城客服~'; $this->assign('artiles',$articles); return $this->fetch('shop_join'); } public function joinStep1(){ session('apply_step',1); $rs = model('shops')->checkApply(); $articles = model('Articles')->getArticlesByCat(53); // 防止不存在入驻文章时报错 if(!isset($articles['109']))$articles['109']['articleContent'] = '无相关说明,请咨询商城客服~'; $this->assign('artiles',$articles); return $this->fetch('shop_join_step1'); } public function joinStep2(){ $step = (int)session('apply_step'); if($step<1){ $this->redirect(Url('home/shops/joinStep1')); exit(); } session('apply_step',2); $apply = model('shops')->getShopApply(); $this->assign('apply',$apply); return $this->fetch('shop_join_step2'); } public function saveStep2(){ $step = (int)session('apply_step'); if($step<2){ return WSTReturn('请勿跳过申请步骤'); } $data = input('post.'); $validate = \think\Loader::validate('Shops'); if(!$validate->check($data,[],'applyStep1')){ return WSTReturn($validate->getError()); }else{ return model('shops')->saveStep2($data); } } public function joinStep3(){ $step = (int)session('apply_step'); if($step<2){ $this->redirect(Url('home/shops/joinStep1')); exit(); } session('apply_step',3); $areas = model('Areas')->listQuery(); $this->assign('areaList',$areas); $apply = model('shops')->getShopApply(); $this->assign('apply',$apply); return $this->fetch('shop_join_step3'); } public function saveStep3(){ $step = (int)session('apply_step'); if($step<3){ return WSTReturn('请勿跳过申请步骤'); } $data = input('post.'); $validate = \think\Loader::validate('Shops'); if(!$validate->check($data,[],'applyStep2')){ return WSTReturn($validate->getError()); }else{ return model('shops')->saveStep3($data); } } public function joinStep4(){ $step = (int)session('apply_step'); if($step<3){ $this->redirect(Url('home/shops/joinStep4')); exit(); } session('apply_step',4); $areas = model('Areas')->listQuery(); $this->assign('areaList',$areas); $banks = model('banks')->listQuery(); $this->assign('bankList',$banks); $apply = model('shops')->getShopApply(); $this->assign('apply',$apply); return $this->fetch('shop_join_step4'); } public function saveStep4(){ $step = (int)session('apply_step'); if($step<4){ return WSTReturn('请勿跳过申请步骤'); } $data = input('post.'); $validate = \think\Loader::validate('Shops'); if(!$validate->check($data,[],'applyStep3')){ return WSTReturn($validate->getError()); }else{ return model('shops')->saveStep4($data); } } public function joinStep5(){ $step = (int)session('apply_step'); if($step<4){ $this->redirect(Url('home/shops/joinStep1')); exit(); } session('apply_step',5); $shopLicense=db('shop_license')->alias('a') ->join('shops b','b.shopId= a.shopId') ->where('b.userId',(int)session("WST_USER.userId"))->find(); $this->assign('shopLicense',$shopLicense); $goodsCatList = model('goodsCats')->listQuery(0); $this->assign('goodsCatList',$goodsCatList); $apply = model('shops')->getShopApply(); $this->assign('apply',$apply); return $this->fetch('shop_join_step5'); } public function saveStep5(){ $step = (int)session('apply_step'); if($step<5){ return WSTReturn('请勿跳过申请步骤'); } $data = input('post.'); $validate = think\Loader::validate('Shops'); if(!$validate->check($data,[],'applyStep4')){ return WSTReturn($validate->getError()); }else{ return model('shops')->saveStep5($data); } } public function joinSuccess(){ $step = (int)session('apply_step'); if($step<5){ $this->redirect(Url('home/shops/joinStep1')); } session('apply_step',5); $apply = model('shops')->getShopApply(); $this->assign('apply',$apply); return $this->fetch('shop_join_success'); } /** * 入驻进度查询 */ public function checkapplystatus(){ $apply = model('shops')->getShopApply(); if(empty($apply)){ $this->redirect(Url('home/shops/joinStep1')); exit(); }else{ if($apply['applyStatus']==0){ session('apply_step',$apply['applyStep']); $this->redirect(Url('home/shops/joinStep'.$apply['applyStep'])); exit(); }else{ $this->assign('apply',$apply); return $this->fetch('shop_join_success'); } } } }