|
@@ -9,7 +9,9 @@ use app\admin\model\shopro\decorate\Page;
|
|
|
use app\common\library\Sms as Smslib;
|
|
|
use app\admin\model\shopro\user\User as UserModel;
|
|
|
use addons\shopro\facade\Wechat;
|
|
|
+use Symfony\Component\Cache\Adapter\NullAdapter;
|
|
|
use think\Hook;
|
|
|
+use think\Db;
|
|
|
|
|
|
class Index extends Common
|
|
|
{
|
|
@@ -21,6 +23,150 @@ class Index extends Common
|
|
|
//首页:搜索,购物车数量,轮播,分类列表,3个秒杀,2个团购,2个砍价,6个精品推荐商品。
|
|
|
public function index(){
|
|
|
|
|
|
+ //购物车数量
|
|
|
+ $cart_num = 0;
|
|
|
+ if($this->auth->isLogin()){
|
|
|
+ $where = [
|
|
|
+ 'user_id'=>$this->auth->id
|
|
|
+ ];
|
|
|
+ $cart_num = Db::name('shopro_cart')->where($where)->sum('goods_num');
|
|
|
+ }
|
|
|
+
|
|
|
+ //轮播
|
|
|
+ $where = [
|
|
|
+ 'status' => 1,
|
|
|
+ 'type' => 2
|
|
|
+ ];
|
|
|
+ $banner = Db::name('banner')->field('id, title, image, url')->where($where)->order('weigh', 'desc')->select();
|
|
|
+ $banner = list_domain_image($banner, ['image']);
|
|
|
+
|
|
|
+ //分类列表
|
|
|
+ $where = [
|
|
|
+ 'status' => 'normal',
|
|
|
+ 'parent_id' => 1
|
|
|
+ ];
|
|
|
+ $category = Db::name('shopro_category')->field('id, name, image')->where($where)->order('weigh', 'desc')->select();
|
|
|
+ $category = list_domain_image($category, ['image']);
|
|
|
+
|
|
|
+ //3个秒杀
|
|
|
+ $seckill_product = [];
|
|
|
+ $where = [
|
|
|
+ 'type' => 'seckill',
|
|
|
+ 'deletetime' => NULL,
|
|
|
+ ];
|
|
|
+ $seckill = Db::name('shopro_activity')->field('id,title,start_time,end_time')->where($where)
|
|
|
+ ->where('start_time', '<=', time())->where('end_time', '>=', time())->order('starttime asc')->find();
|
|
|
+ $seckill['seconds'] = $seckill['end_time'] - time();
|
|
|
+ if($seckill){
|
|
|
+ $seckill_product = $this->seckill_productsku_list($seckill['id']);
|
|
|
+ }
|
|
|
+
|
|
|
+ //2个团购
|
|
|
+ $groupon_product = $this->groupon_productsku_list('groupon');
|
|
|
+
|
|
|
+
|
|
|
+ //2个砍价
|
|
|
+ $kan_product = $this->groupon_productsku_list('kan');
|
|
|
+
|
|
|
+
|
|
|
+ //6个精品推荐商品。
|
|
|
+ $where = [
|
|
|
+ 'status' => 'up',
|
|
|
+ 'deletetime' => Null,
|
|
|
+ ];
|
|
|
+ $filed = ['id','title','image','price',];
|
|
|
+ $tuijian_product = Db::name('shopro_goods')->where($where)->field($filed)->order('show_sales','desc')->limit(6)->select();
|
|
|
+ $tuijian_product = list_domain_image($tuijian_product,['image']);
|
|
|
+
|
|
|
+ //结果
|
|
|
+ $result = [
|
|
|
+ 'cart_num' => $cart_num,
|
|
|
+ 'banner' => $banner,
|
|
|
+ 'category' => $category,
|
|
|
+ 'seckill_product' => $seckill_product,
|
|
|
+ 'groupon_product' => $groupon_product,
|
|
|
+ 'kan_product' => $kan_product,
|
|
|
+ 'tuijian_product' => $tuijian_product,
|
|
|
+ ];
|
|
|
+ $this->success(1,$result);
|
|
|
+ }
|
|
|
+
|
|
|
+ //某秒杀的商品列表
|
|
|
+ private function seckill_productsku_list($activity_id){
|
|
|
+
|
|
|
+ $map = [
|
|
|
+ 'asp.activity_id' => $activity_id,
|
|
|
+ ];
|
|
|
+
|
|
|
+ $list = Db::name('shopro_activity_sku_price')->alias('asp')
|
|
|
+ ->field([
|
|
|
+ 'asp.activity_id','asp.goods_sku_price_id','asp.goods_id','asp.stock','asp.sales','asp.price',
|
|
|
+ 'g.title','g.image',
|
|
|
+ 'gsp.goods_sku_text','gsp.image as sku_image','gsp.price as old_price']
|
|
|
+ )
|
|
|
+ ->join('shopro_activity a','asp.activity_id = a.id','LEFT')
|
|
|
+ ->join('shopro_goods g' ,'asp.goods_id = g.id','LEFT')
|
|
|
+ ->join('shopro_goods_sku_price gsp','asp.goods_sku_price_id = gsp.id','LEFT')
|
|
|
+ ->where('asp.status','up')
|
|
|
+ ->where('a.deletetime',NULL)->where('a.type','seckill')
|
|
|
+ ->where('g.deletetime',NULL)->whereIn('g.status', ['up', 'hidden'])
|
|
|
+ ->where('gsp.status','up')
|
|
|
+ ->where($map)
|
|
|
+ ->limit(3)->select();
|
|
|
+ $list = list_domain_image($list,['image','sku_image']);
|
|
|
+ foreach($list as $key => $val){
|
|
|
+ //sku图片代替主图
|
|
|
+ if(!empty($val['sku_image'])){
|
|
|
+ $val['image'] = $val['sku_image'];
|
|
|
+ }
|
|
|
+ unset($val['sku_image']);
|
|
|
+
|
|
|
+ //折扣
|
|
|
+ $val['zhekou'] = bcdiv($val['price'],$val['old_price'],2);
|
|
|
+
|
|
|
+ //已抢百分比
|
|
|
+ $val['bili'] = bcdiv($val['sales'],$val['stock'],0).'%';
|
|
|
+
|
|
|
+ $list[$key] = $val;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $list;
|
|
|
+ }
|
|
|
+
|
|
|
+ //团购商品列表
|
|
|
+ private function groupon_productsku_list($type){
|
|
|
+
|
|
|
+ $list = Db::name('shopro_activity_sku_price')->alias('asp')
|
|
|
+ ->field([
|
|
|
+ 'asp.activity_id','asp.goods_sku_price_id','asp.goods_id','asp.price',
|
|
|
+ 'a.rules',
|
|
|
+ 'g.title','g.image',
|
|
|
+ 'gsp.goods_sku_text','gsp.image as sku_image','gsp.price as old_price']
|
|
|
+ )
|
|
|
+ ->join('shopro_activity a','asp.activity_id = a.id','LEFT')
|
|
|
+ ->join('shopro_goods g' ,'asp.goods_id = g.id','LEFT')
|
|
|
+ ->join('shopro_goods_sku_price gsp','asp.goods_sku_price_id = gsp.id','LEFT')
|
|
|
+ ->where('asp.status','up')
|
|
|
+ ->where('a.deletetime',NULL)->where('a.type',$type)
|
|
|
+ ->where('g.deletetime',NULL)->whereIn('g.status', ['up', 'hidden'])
|
|
|
+ ->where('gsp.status','up')
|
|
|
+ ->order('a.end_time asc')
|
|
|
+ ->limit(2)->select();
|
|
|
+ $list = list_domain_image($list,['image','sku_image']);
|
|
|
+ foreach($list as $key => $val){
|
|
|
+ //sku图片代替主图
|
|
|
+ if(!empty($val['sku_image'])){
|
|
|
+ $val['image'] = $val['sku_image'];
|
|
|
+ }
|
|
|
+ unset($val['sku_image']);
|
|
|
+
|
|
|
+ $val['team_num'] = json_decode($val['rules'],true)['team_num'];
|
|
|
+ unset($val['rules']);
|
|
|
+
|
|
|
+ $list[$key] = $val;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $list;
|
|
|
}
|
|
|
|
|
|
public function init()
|