You've already forked qlg.tsgz.moe
Init Repo
This commit is contained in:
227
hyhproject/app/model/Index.php
Executable file
227
hyhproject/app/model/Index.php
Executable file
@ -0,0 +1,227 @@
|
||||
<?php
|
||||
namespace wstmart\app\model;
|
||||
use wstmart\common\model\Tags as T;
|
||||
use think\Db;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 默认类
|
||||
*/
|
||||
class Index extends Base{
|
||||
/**
|
||||
* 楼层
|
||||
*/
|
||||
public function pageQuery(){
|
||||
$limit = (int)input('post.currPage');//楼层页码
|
||||
if($limit>9)return;
|
||||
$cacheData = cache('MO_CATS_ADS'.$limit);
|
||||
if($cacheData)return $cacheData;
|
||||
$rs = Db::name('goods_cats')->where(['dataFlag'=>1,'isShow'=>1,'parentId'=>0,'isFloor'=>1])->field('catId,catName')->order('catSort asc')->limit($limit,1)->select();//按设定排序获取分类名称,异步下拉加载,传输楼层的层楼
|
||||
if($rs){
|
||||
$rs= $rs[0];//用select就选第一个,其实可以改成find
|
||||
$t = new T();
|
||||
$rs['ads'] = $t->listAds('mo-ads-'.$limit,'1');//获取手机版楼层页面的广告图
|
||||
$rs['goods'] = Db::name('goods')->alias('g')->join('__RECOMMENDS__ r','g.goodsId=r.dataId')
|
||||
->where(['r.goodsCatId'=>$rs['catId'],'g.isSale'=>1,'g.dataFlag'=>1,'g.goodsStatus'=>1,'r.dataSrc'=>0,'r.dataType'=>1])
|
||||
->field('g.goodsId,g.goodsName,g.goodsImg,g.shopPrice,g.saleNum')->order('r.dataSort asc')->limit(6)->select();
|
||||
if(empty($rs['goods'])){
|
||||
$rs['goods'] = Db::name('goods')->alias('g')
|
||||
->where(['g.goodsCatIdPath'=>['like',$rs['catId'].'_%'],'g.isSale'=>1,'g.dataFlag'=>1,'g.goodsStatus'=>1,'g.isHot'=>1])
|
||||
->field('g.goodsId,g.goodsName,g.goodsImg,g.shopPrice,g.saleNum')
|
||||
->order('saleNum desc,goodsId asc')->limit(6)->select();
|
||||
}
|
||||
$rs['currPage'] = $limit;
|
||||
}
|
||||
cache('MO_CATS_ADS'.$limit,$rs,86400);
|
||||
return $rs;
|
||||
}
|
||||
/**
|
||||
* 猜你喜欢
|
||||
*/
|
||||
public function guess_like(){
|
||||
$userId=(int)session('WST_USER.userId');
|
||||
//$userId=50;
|
||||
$page = (int)input('post.page/d');
|
||||
$cacheData = cache('APP_CATS_LIKE_'.$page.'_'.$userId);
|
||||
if($cacheData)return $cacheData;
|
||||
$pagesize = input('pagesize/d');
|
||||
$childId=[];
|
||||
$parentId=[];
|
||||
//$goods_result["Rows"]= '';//Db::name('goods')->alias('g')->join('__RECOMMENDS__ r','g.goodsId=r.dataId')
|
||||
//->where(['g.isSale'=>1,'g.dataFlag'=>1,'g.goodsStatus'=>1,'r.dataSrc'=>0,'r.dataType'=>1])
|
||||
//->field('g.goodsId,g.goodsName,g.goodsImg,g.shopPrice,g.saleNum')->order('rand()')->paginate($pagesize)->toArray();
|
||||
//用户登录状态
|
||||
// if($userId){
|
||||
// //查找登录账号浏览过的记录
|
||||
// $goods_ids=db('page_view')->where('userId',$userId)->field('count(goodsId)num,goodsId')
|
||||
// ->group('goodsId')->order('num desc')->limit('18')->select();
|
||||
// if($goods_ids){
|
||||
// foreach($goods_ids as $key=>$value){
|
||||
// $childId[]=$value['goodsId'];
|
||||
// }
|
||||
// //根据查找到的商品分类,寻找最顶级商品分类
|
||||
// $goods_parents=$this->getParentIs($childId);
|
||||
// foreach($goods_parents as $k=>$v){
|
||||
// $parentId[]=$v;
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
//用户未登录或顶级商品分类过少时进行全表查询
|
||||
if(!$userId || count($parentId)<3){
|
||||
|
||||
$goods_ids=db('page_view')->where('1=1')->field('count(goodsId)num,goodsId')
|
||||
->group('goodsId')->order('num desc,id desc')->limit('18')->select();
|
||||
foreach($goods_ids as $key=>$value){
|
||||
$childId[]=$value['goodsId'];
|
||||
}
|
||||
////根据查找到的商品分类,寻找最顶级商品分类
|
||||
$goods_parents=$this->getParentIs($childId);
|
||||
foreach($goods_parents as $k=>$v){
|
||||
$parentId[]=$v;
|
||||
}
|
||||
}
|
||||
//根据父级分类查找所有子级商品
|
||||
$goods_child=$this->getChild('',$parentId);
|
||||
$pagesize = input('pagesize/d');
|
||||
//展现顶级分类下所有子级分类的商品
|
||||
$goods_result=db('goods')->whereIn('goodsCatId',$goods_child)->order('visitNum desc')
|
||||
->where(['isSale'=>1,'dataFlag'=>1,'goodsStatus'=>1,'isHot'=>1])
|
||||
->field('goodsId,goodsName,goodsImg,shopPrice,saleNum')
|
||||
->paginate($pagesize)->toArray();
|
||||
// if(empty($goods_result["Rows"])){
|
||||
// $goods_result = Db::name('goods')->alias('g')
|
||||
// ->where(['g.isSale'=>1,'g.dataFlag'=>1,'g.goodsStatus'=>1,'g.isHot'=>1])
|
||||
// ->field('g.goodsId,g.goodsName,g.goodsImg,g.shopPrice,g.saleNum')
|
||||
// ->order('rand()')->paginate($pagesize)->toArray();
|
||||
// }
|
||||
|
||||
cache('APP_CATS_LIKE_'.$page.'_'.$userId,$goods_result,3600);
|
||||
return $goods_result;
|
||||
}
|
||||
/**
|
||||
* 热卖推荐
|
||||
*/
|
||||
public function getHotGoods(){
|
||||
$page = (int)input('page',1);
|
||||
$cacheData = cache('QLG_HOT_GOODS_'.$page);
|
||||
if($cacheData)return $cacheData;
|
||||
$rs = Db::name('goods')
|
||||
->where(['isSale'=>1,'dataFlag'=>1,'goodsStatus'=>1])
|
||||
->field('goodsId,goodsName,goodsImg,shopPrice,saleNum,discountRate')
|
||||
->order('discountRate DESC,goodsId DESC')
|
||||
->paginate(input('pageSize/d',10))->toArray();
|
||||
cache('QLG_HOT_GOODS_'.$page,$rs,3600);
|
||||
return $rs;
|
||||
}
|
||||
/**
|
||||
* 迭代获取下级
|
||||
* 获取一个分类下的所有子级分类id
|
||||
*/
|
||||
public function getChild($data,$pid){
|
||||
if(!$pid){
|
||||
return;
|
||||
}
|
||||
$childId = db('goods_cats')->where("dataFlag=1")->whereIn('parentId',$pid)->field('catId,parentId')->select();
|
||||
//获取该分类id下的所有子级分类id
|
||||
foreach($childId as $key=>$value){
|
||||
$child[]=$value['catId'];
|
||||
}
|
||||
static $ids = array();
|
||||
foreach($childId as $k=>$v){
|
||||
//dump($childId);
|
||||
$ids[] = $v['catId'];//将找到的下级分类id放入静态数组
|
||||
//再找下当前id是否还存在下级id
|
||||
$this->getChild($childId, $v['catId']);
|
||||
}
|
||||
return $ids;
|
||||
}
|
||||
/**
|
||||
* 根据子分类获取其父级分类
|
||||
*/
|
||||
public function getParentIs($id,$data = array()){
|
||||
$data[] = $id;
|
||||
$parentId = db('goods_cats')->where("dataFlag=1")->whereIn('catId',$id)->field('parentId')->select();
|
||||
foreach($parentId as $key=>$value){
|
||||
$parent[]=$value['parentId'];
|
||||
}
|
||||
|
||||
if(!isset($parent)){
|
||||
krsort($data);
|
||||
//判断是否有值为0的数组元素;
|
||||
foreach ($data as $k => $v) {
|
||||
foreach ($v as $key => $value) {
|
||||
if(!$value){
|
||||
unset($v[$key]);
|
||||
}
|
||||
}
|
||||
if(!$v){
|
||||
unset($data[$k]);
|
||||
}
|
||||
}
|
||||
$da=array_unique(current($data));
|
||||
return $da;
|
||||
}else{
|
||||
return $this->getParentIs($parent,$data);
|
||||
}
|
||||
}
|
||||
//获取所有小广告位
|
||||
public function getIndexAds(){
|
||||
$cacheData = cache('APP_CATS_ADS');
|
||||
if($cacheData)return $cacheData;
|
||||
$where['positionCode'] = ['LIKE','%mo-ads-index-%'];
|
||||
$where['positionType'] = 3;
|
||||
$where['dataFlag'] = 1;
|
||||
$positions_list = Db::name('ad_positions')->where($where)->field('positionId,positionName')->cache(true,86400)->select();
|
||||
unset($where['positionCode'] );
|
||||
$date = date('Y-m-d');
|
||||
$where['adStartDate'] = ['<=',$date];
|
||||
$where['adEndDate'] = ['>=',$date];
|
||||
$list=[];
|
||||
foreach($positions_list as &$v){
|
||||
$where['adPositionId'] = $v['positionId'];
|
||||
$list[$v['positionId']]['name'] = $v['positionName'];
|
||||
$ads_list = Db::name('ads')->where($where)->field('adFile,adURL,targetType')->cache(true,86400)->select();
|
||||
$list[$v['positionId']]['list'] = $ads_list;
|
||||
}
|
||||
cache('APP_CATS_ADS',$list,86400);
|
||||
return $list;
|
||||
}
|
||||
//获取首页轮播图
|
||||
public function getIndexTopImg(){
|
||||
$cacheData = cache('APP_TOP_IMG');
|
||||
if($cacheData)return $cacheData;
|
||||
$ads_list=[];
|
||||
$ads_list = listAds('mo-ads-index',9,86400);
|
||||
cache('APP_TOP_IMG',$ads_list,86400);
|
||||
return $ads_list;
|
||||
}
|
||||
//获取首页横图
|
||||
public function getIndexCrossImg(){
|
||||
$cacheData = cache('APP_CROSS_IMG');
|
||||
if($cacheData)return $cacheData;
|
||||
$ads_list=[];
|
||||
$ads_list['cross_top'] = listAds('mo-index-cross-top',6,86400);
|
||||
$ads_list['cross_bottom'] = listAds('mo-index-cross-down',6,86400);
|
||||
cache('APP_CROSS_IMG',$ads_list,86400);
|
||||
return $ads_list;
|
||||
}
|
||||
/**
|
||||
* 获取系统消息
|
||||
*/
|
||||
function getSysMsg($msg='',$order=''){
|
||||
$data = [];
|
||||
$userId = (int)session('WST_USER.userId');
|
||||
if($msg!=''){
|
||||
$data['message']['num'] = Db::name('messages')->where(['receiveUserId'=>$userId,'msgStatus'=>0,'dataFlag'=>1])->count();
|
||||
}
|
||||
if($order!=''){
|
||||
$data['order']['waitPay'] = Db::name('orders')->where(['userId'=>$userId,'orderStatus'=>-2,'dataFlag'=>1])->count();
|
||||
$data['order']['waitSend'] = Db::name('orders')->where(['userId'=>$userId,'orderStatus'=>0,'dataFlag'=>1])->count();
|
||||
$data['order']['waitReceive'] = Db::name('orders')->where(['userId'=>$userId,'orderStatus'=>1,'dataFlag'=>1])->count();
|
||||
$data['order']['waitAppraise'] = Db::name('orders')->where(['userId'=>$userId,'orderStatus'=>2,'isAppraise'=>0,'dataFlag'=>1])->count();
|
||||
$data['order']['cancelNum'] = 0;//Db::name('orders')->where('userId='.$userId.' AND (orderStatus=-1 OR orderStatus=-3)')->count();
|
||||
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user