292 lines
12 KiB
PHP
Executable File
292 lines
12 KiB
PHP
Executable File
<?php
|
|
namespace wstmart\app\model;
|
|
use wstmart\common\model\Shops as CShops;
|
|
use think\Db;
|
|
/**
|
|
* ============================================================================
|
|
* 门店类
|
|
*/
|
|
class Shops extends CShops{
|
|
public function getShopIndex(){
|
|
$shopId = (int)input('shopId');
|
|
$shopInfo = $this->where(['shopId'=>$shopId,'status'=>1,'shopStatus'=>1,'dataFlag'=>1])->field('shopImg,shopName,lat,lng,userName,phone')->find();
|
|
if(!$shopInfo) return WSTReturn('未找到此店铺');
|
|
$shopInfo['shopAds'] = (string)Db::name('shop_configs')->where(['shopId'=>$shopId])->value('shopAds');
|
|
return WSTReturn('',1,$shopInfo);
|
|
}
|
|
/**
|
|
* 店铺街列表
|
|
*/
|
|
public function pageQuery($pagesize){
|
|
$catId = (int)input("id");
|
|
$keyword = input("keyword");
|
|
$condition = input("condition");
|
|
$desc = input("desc");
|
|
$datas = array('sort'=>array('1'=>'ss.totalScore/ss.totalUsers'),'desc'=>array('desc','asc'));
|
|
$rs = $this->alias('s');
|
|
$where = [];
|
|
$where['s.dataFlag'] = 1;
|
|
$where['s.shopStatus'] = 1;
|
|
$where['s.status'] = 1;
|
|
if($keyword!='')$where['s.shopName'] = ['like','%'.$keyword.'%'];
|
|
if($catId>0){
|
|
$rs->join('__CAT_SHOPS__ cs','cs.shopId = s.shopId','left');
|
|
$where['cs.catId'] = $catId;
|
|
}
|
|
$order = ['s.shopId'=>'asc'];
|
|
if($condition>0){
|
|
$order = [$datas['sort'][$condition]=>$datas['desc'][$desc]];
|
|
}
|
|
$page = $rs->join('__SHOP_SCORES__ ss','ss.shopId = s.shopId','left')
|
|
->where($where)->order($order)
|
|
->field('s.shopId,s.shopImg,s.shopName,s.shopCompany,ss.totalScore,ss.totalUsers,ss.goodsScore,ss.goodsUsers,ss.serviceScore,ss.serviceUsers,ss.timeScore,ss.timeUsers,s.areaIdPath')
|
|
->paginate($pagesize)->toArray();
|
|
foreach ($page['Rows'] as $key =>$v){
|
|
//商品列表
|
|
$goods = db('goods')->where(['dataFlag'=> 1,'isSale'=>1,'goodsStatus'=> 1,'shopId'=> $v["shopId"]])->field('goodsId,goodsName,shopPrice,goodsImg')
|
|
->order('saleTime desc')->limit(3)->select();
|
|
$page['Rows'][$key]['goods'] = $goods;
|
|
}
|
|
if(empty($page['Rows']))return $page;
|
|
$shopIds = [];
|
|
$areaIds = [];
|
|
foreach ($page['Rows'] as $key =>$v){
|
|
$shopIds[] = $v['shopId'];
|
|
// $tmp = explode('_',$v['areaIdPath']);
|
|
// $areaIds[] = $tmp[1];
|
|
//$page['Rows'][$key]['areaId'] = $tmp[1];
|
|
//总评分
|
|
$page['Rows'][$key]['totalScore'] = WSTScore($v["totalScore"]/3, $v["totalUsers"]);
|
|
$page['Rows'][$key]['goodsScore'] = WSTScore($v['goodsScore'],$v['goodsUsers']);
|
|
$page['Rows'][$key]['serviceScore'] = WSTScore($v['serviceScore'],$v['serviceUsers']);
|
|
$page['Rows'][$key]['timeScore'] = WSTScore($v['timeScore'],$v['timeUsers']);
|
|
}
|
|
$rccredMap = [];
|
|
$goodsCatMap = [];
|
|
$areaMap = [];
|
|
//认证、地址、分类
|
|
if(!empty($shopIds)){
|
|
$rccreds = Db::name('shop_accreds')->alias('sac')->join('__ACCREDS__ a','a.accredId=sac.accredId and a.dataFlag=1','left')
|
|
->where('shopId','in',$shopIds)->field('sac.shopId,accredName,accredImg')->select();
|
|
foreach ($rccreds as $v){
|
|
$rccredMap[$v['shopId']][] = $v;
|
|
}
|
|
$goodsCats = Db::name('cat_shops')->alias('cs')->join('__GOODS_CATS__ gc','cs.catId=gc.catId and gc.dataFlag=1','left')
|
|
->where('shopId','in',$shopIds)->field('cs.shopId,gc.catName')->select();
|
|
foreach ($goodsCats as $v){
|
|
$goodsCatMap[$v['shopId']][] = $v['catName'];
|
|
}
|
|
$areas = Db::name('areas')->alias('a')->join('__AREAS__ a1','a1.areaId=a.parentId','left')
|
|
->where('a.areaId','in',$areaIds)->field('a.areaId,a.areaName areaName2,a1.areaName areaName1')->select();
|
|
foreach ($areas as $v){
|
|
$areaMap[$v['areaId']] = $v;
|
|
}
|
|
}
|
|
foreach ($page['Rows'] as $key =>$v){
|
|
$page['Rows'][$key]['accreds'] = (isset($rccredMap[$v['shopId']]))?$rccredMap[$v['shopId']]:[];
|
|
$page['Rows'][$key]['catshops'] = (isset($goodsCatMap[$v['shopId']]))?implode(',',$goodsCatMap[$v['shopId']]):'';
|
|
//$page['Rows'][$key]['areas']['areaName1'] = (isset($areaMap[$v['areaId']]['areaName1']))?$areaMap[$v['areaId']]['areaName1']:'';
|
|
//$page['Rows'][$key]['areas']['areaName2'] = (isset($areaMap[$v['areaId']]['areaName2']))?$areaMap[$v['areaId']]['areaName2']:'';
|
|
}
|
|
return $page;
|
|
}
|
|
/**
|
|
* 获取卖家中心信息
|
|
*/
|
|
public function getShopSummary(){
|
|
$shopId = (int)input('shopId',1);
|
|
$shop = $this->alias('s')->join('__SHOP_SCORES__ cs','cs.shopId = s.shopId','left')
|
|
->where(['s.shopId'=>$shopId,'dataFlag'=>1])
|
|
->field('s.shopId,shopImg,shopName,shopkeeper,shopAddress,shopQQ,shopTel,serviceStartTime,serviceEndTime,isInvoice,invoiceRemarks,cs.*')
|
|
->find();
|
|
//评分
|
|
$scores['totalScore'] = WSTScore($shop['totalScore'],$shop['totalUsers']);
|
|
$scores['goodsScore'] = WSTScore($shop['goodsScore'],$shop['goodsUsers']);
|
|
$scores['serviceScore'] = WSTScore($shop['serviceScore'],$shop['serviceUsers']);
|
|
$scores['timeScore'] = WSTScore($shop['timeScore'],$shop['timeUsers']);
|
|
WSTUnset($shop, 'totalUsers,goodsUsers,serviceUsers,timeUsers');
|
|
$shop['scores'] = $scores;
|
|
//认证
|
|
$accreds = $this->shopAccreds($shopId);
|
|
$shop['accreds'] = $accreds;
|
|
return ['shop'=>$shop];
|
|
}
|
|
/**
|
|
* 自营店铺楼层
|
|
*/
|
|
public function getFloorData(){
|
|
$limit = (int)input('post.currPage');
|
|
$cacheData = cache('WX_SHOP_FLOOR'.$limit);
|
|
if($cacheData)return $cacheData;
|
|
$rs = Db::name('shop_cats')->where(['dataFlag'=>1,'isShow'=>1,'parentId'=>0,'shopId'=>1])->field('catId,catName')->order('catSort asc')->limit($limit,1)->select();
|
|
if($rs){
|
|
$rs= $rs[0];
|
|
$goods = Db::name('goods')->where('shopCatId1','=',$rs['catId'])->where(['dataFlag'=>1,'goodsStatus'=>1])->field('goodsId,goodsName,goodsImg,shopPrice,saleNum')->order('isHot desc')->limit(4)->select();
|
|
$rs['goods'] = $goods;
|
|
$rs['currPage'] = $limit;
|
|
}
|
|
cache('WX_SHOP_FLOOR'.$limit,$rs,86400);
|
|
return $rs;
|
|
}
|
|
/**
|
|
* 根据订单id 获取店铺名称
|
|
*/
|
|
public function getShopName($oId){
|
|
return $this->alias('s')
|
|
->join('__ORDERS__ o',"s.shopId=o.shopId",'inner')
|
|
->where("o.orderId=$oId")
|
|
->value('s.shopName');
|
|
|
|
}
|
|
/**
|
|
* 添加查看记数
|
|
* @param [type] $rewardId [description]
|
|
* @param [type] $userId [description]
|
|
*/
|
|
public function setRewardVisit($rewardId,$userId){
|
|
$reward_num = Db::name('reward_num');
|
|
$where['rewardId'] = $rewardId;
|
|
$where['userId'] = $userId;
|
|
if($reward_num->where($where)->find()){
|
|
$reward_num->where($where)->setField('isVisit',1);
|
|
}else{
|
|
$data['rewardId'] = $rewardId;
|
|
$data['userId'] = $userId;
|
|
$data['isVisit'] = 1;
|
|
$reward_num->insert($data);
|
|
}
|
|
Db::name('rewards')->where(['rewardId'=>$rewardId])->setInc('visitNum');
|
|
}
|
|
/**
|
|
* 点赞记数
|
|
* @param [type] $rewardId [description]
|
|
* @param [type] $userId [description]
|
|
*/
|
|
public function setRewardLike($rewardId,$userId,$isLike){
|
|
$reward_num = Db::name('reward_num');
|
|
$where['rewardId'] = $rewardId;
|
|
$where['userId'] = $userId;
|
|
$dbIsLike = $reward_num->where($where)->value('isLike');
|
|
if(isset($dbIsLike)){
|
|
if($dbIsLike != $isLike){
|
|
$reward_num->where($where)->setField('isLike',$isLike);
|
|
if($isLike == 1){
|
|
Db::name('rewards')->where(['rewardId'=>$rewardId])->setInc('likeNum');
|
|
}else{
|
|
Db::name('rewards')->where(['rewardId'=>$rewardId])->setDec('likeNum');
|
|
}
|
|
}
|
|
}else{
|
|
$data['rewardId'] = $rewardId;
|
|
$data['userId'] = $userId;
|
|
$data['isLike'] = $isLike;
|
|
$reward_num->insert($data);
|
|
if($isLike == 1){
|
|
Db::name('rewards')->where(['rewardId'=>$rewardId])->setInc('likeNum');
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* mark 20180518 by zl
|
|
*获取商店特产省份
|
|
*@param $shopId 商店id
|
|
*
|
|
*/
|
|
public function getProv($shopId=1){
|
|
$where['shopId'] = $shopId;
|
|
$where['dataFlag'] = 1;
|
|
$where['provId'] = ['>','0'];
|
|
$prov = Db::name('shop_cats')->distinct(true)->field('provId,provName')->where($where)->order('provId asc')->select();
|
|
return $prov;
|
|
}
|
|
/**
|
|
*获取商店特产省份
|
|
*@param $shopId 商店id
|
|
*@param $provId 省份id
|
|
*/
|
|
public function getShopCats($shopId=1,$provId=0){
|
|
$where['shopId'] = $shopId;
|
|
if($provId)$where['provId'] = $provId;
|
|
$where['parentId'] = 0;
|
|
$where['isShow'] = 1;
|
|
$where['dataFlag'] = 1;
|
|
$cats = Db::name('shop_cats')->where($where)
|
|
->field('catId,catName,shopId,provId,provName,catImg')
|
|
->order("catId asc")->select();
|
|
return $cats;
|
|
}
|
|
/**
|
|
*根据商店分类获取商品列表
|
|
*@param $shopId 商店id
|
|
*@param $shopCatId1 商店一级分类
|
|
*/
|
|
public function getGoodsByShopCats($shopId=1,$shopCatId1,$page=1){
|
|
$cacheData = cache('APP_GOODS_BY_SHOPCAT_'.$shopId.'_'.$shopCatId1.'_'.$page);
|
|
if($cacheData)return $cacheData;
|
|
$where['shopId'] = $shopId;
|
|
$where['shopCatId1'] = $shopCatId1;
|
|
$where['dataFlag'] = 1;
|
|
$where['isSale'] = 1;
|
|
$where['goodsStatus'] = 1;
|
|
$pagesize = 8;
|
|
$offset = ($page-1)*$pagesize;
|
|
$limit = "{$offset},{$pagesize}";
|
|
$goods = Db::name('goods')->where($where)->limit($limit)->order("saleNum desc")->select();
|
|
$list['goods'] = $goods;
|
|
$list['page'] = $page;
|
|
// $list = Db::name('goods')->where($where)->paginate($pagesize)->toArray();
|
|
cache('APP_GOODS_BY_SHOPCAT_'.$shopId.'_'.$shopCatId1.'_'.$page,$list,600);
|
|
return $list;
|
|
}
|
|
/**
|
|
*获取首页热门特产榜单
|
|
*
|
|
*/
|
|
public function getHotList($shopId=1){
|
|
$where['shopId'] = $shopId;
|
|
$where['dataFlag'] = 1;
|
|
$where['isShow'] = 1;
|
|
$cat1 = cache('APP_HOT_LIST');
|
|
if(!empty($cat1))return $cat1;
|
|
//获取一级分类
|
|
$cat1 = Db::name('shop_cats')->field('catId,catName')->where($where)->where(['isHot'=>1,'parentId'=>0])->order('catSort asc')->select();
|
|
if(count($cat1)>0){
|
|
foreach($cat1 as $k=>$v){
|
|
//获取二级分类
|
|
$cat2 = Db::name('shop_cats')->field('catId,catName')->where($where)->where(['parentId'=>$v['catId']])->select();
|
|
if(count($cat2)>0){
|
|
foreach($cat2 as $kk=>$vv){
|
|
//获取二级分类下的商品
|
|
$vv['goods'] = $this->getGoodsByCats($shopId,$v['catId'],$vv['catId']);
|
|
if(isset($vv['goods'])){
|
|
foreach ($vv['goods'] as $key => $value) {
|
|
$vv['goods'][$key]['goodsImg'] = WSTImg($value['goodsImg'],2);
|
|
}
|
|
}
|
|
$cat1[$k]['cat2'][] = $vv;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
cache('APP_HOT_LIST',$cat1,600);
|
|
return $cat1;
|
|
}
|
|
//根据分类获取商品数据
|
|
public function getGoodsByCats($shopId=1,$catId1,$catId2){
|
|
$where['dataFlag'] = 1;
|
|
$where['goodsStatus'] = 1;
|
|
$where['isSale'] = 1;
|
|
$where['shopId'] = $shopId;
|
|
$where['shopCatId1'] = $catId1;
|
|
$where['shopCatId2'] = $catId2;
|
|
|
|
$goods = Db::name('goods')->field('goodsId,goodsName,goodsImg,shopPrice')->where($where)->order('visitNum desc')->limit(2)->select();
|
|
return $goods;
|
|
}
|
|
/**
|
|
* end
|
|
*/
|
|
}
|