From d8ee482022552d19de4e64d20a8ecd35558e6774 Mon Sep 17 00:00:00 2001 From: devil Date: Thu, 23 Apr 2020 16:30:18 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E4=BB=85=E5=95=86=E5=93=81?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=8E=BB=E9=99=A4=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/service/GoodsService.php | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/application/service/GoodsService.php b/application/service/GoodsService.php index eb06bb246..7081f6d94 100755 --- a/application/service/GoodsService.php +++ b/application/service/GoodsService.php @@ -179,7 +179,6 @@ class GoodsService // 缓存 $key = config('shopxo.cache_goods_floor_list_key'); $data = cache($key); - if(empty($data)) { // 商品大分类 @@ -190,15 +189,37 @@ class GoodsService // 根据分类获取楼层商品 foreach($data as &$v) { + // 获取分类ids $category_ids = self::GoodsCategoryItemsIds([$v['id']], 1); - $goods = self::CategoryGoodsList(['where'=>['gci.category_id'=>$category_ids, 'g.is_home_recommended'=>1, 'g.is_shelves'=>1], 'm'=>0, 'n'=>8, 'field'=>'g.*']); - $v['goods'] = $goods['data']; + + // 获取商品ids + $where = [ + 'gci.category_id' => $category_ids, + 'g.is_home_recommended' => 1, + 'g.is_shelves' => 1, + ]; + $v['goods_ids'] = Db::name('Goods')->alias('g')->join(['__GOODS_CATEGORY_JOIN__'=>'gci'], 'g.id=gci.goods_id')->where($where)->group('g.id')->order('g.id desc')->limit(8)->column('g.id'); + $v['goods'] = []; } } // 存储缓存 cache($key, $data, 3600*24); } + + // 商品读取、商品不缓存、商品价格会根据用户等级可能会不一样 + if(!empty($data) && is_array($data)) + { + // 根据分类获取楼层商品 + foreach($data as &$v) + { + if(!empty($v['goods_ids']) && is_array($v['goods_ids'])) + { + $res = self::GoodsList(['where'=>['id'=>$v['goods_ids'], 'is_home_recommended'=>1, 'is_shelves'=>1], 'm'=>0, 'n'=>8, 'field'=>'*']); + $v['goods'] = $res['data']; + } + } + } return $data; }