From fb3019f1c41cd893caa5ac2c19ab5944525080bf Mon Sep 17 00:00:00 2001 From: yin5th <541304803@qq.com> Date: Mon, 23 Oct 2023 15:29:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=A6=96=E9=A1=B5=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/app/api/logic/IndexLogic.php | 45 +++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/server/app/api/logic/IndexLogic.php b/server/app/api/logic/IndexLogic.php index e4fd42ff..a8502980 100644 --- a/server/app/api/logic/IndexLogic.php +++ b/server/app/api/logic/IndexLogic.php @@ -48,12 +48,12 @@ class IndexLogic extends Logic $shopRecommend = self::getShopRecommend(); // 秒杀商品 - $seckillTimes = SeckillGoodsLogic::seckillTime(); - $seckillGoods = []; - foreach($seckillTimes as $item) { - $item['goods'] = SeckillGoodsLogic::getSeckillGoodsTwo($item['id'],$terminal); - $seckillGoods[] = $item; - } +// $seckillTimes = SeckillGoodsLogic::seckillTime(); +// $seckillGoods = []; +// foreach($seckillTimes as $item) { +// $item['goods'] = SeckillGoodsLogic::getSeckillGoodsTwo($item['id'],$terminal); +// $seckillGoods[] = $item; +// } //活动专区 $activity_area = ActivityArea::field('id,name,synopsis as title,image')->where(['del'=>0,'status'=>1])->select(); foreach ($activity_area as &$area_item){ @@ -61,7 +61,7 @@ class IndexLogic extends Logic } // 种草社区文章 - $communityArticle = self::getCommunityArticle(); +// $communityArticle = self::getCommunityArticle(); return [ 'headlines' => $headlines, @@ -70,8 +70,8 @@ class IndexLogic extends Logic 'activity_area' => $activity_area, 'shop_lists' => $shopLists, 'shop_recommend' => $shopRecommend, - 'seckill_goods' => $seckillGoods, - 'community_article' => $communityArticle +// 'seckill_goods' => $seckillGoods, +// 'community_article' => $communityArticle ]; } @@ -101,6 +101,13 @@ class IndexLogic extends Logic */ public static function getHots() { + $hots = session('home_hosts'); + if (!empty($hots)) { + // 有缓存且未过期 + if (!empty($hots['expire']) && $hots['expire'] > time()) { + return $hots['list']; + } + } // 销售中商品:未删除/审核通过/已上架 $onSaleWhere = [ 'del' => GoodsEnum::DEL_NORMAL, // 未删除 @@ -113,12 +120,15 @@ class IndexLogic extends Logic 'sort_weight' => 'asc', // 商品权重 'id' => 'desc' ]; - $hots = Goods::field('id,name,image,min_price,market_price,sales_actual,create_time,sales_virtual,(sales_actual + sales_virtual) as sales_total') + $hots = []; + $hots['list'] = Goods::field('id,name,image,min_price,market_price,sales_actual,create_time,sales_virtual,(sales_actual + sales_virtual) as sales_total') ->where($onSaleWhere) ->order($order) ->limit(9) ->select() ->toArray(); + $hots['expire'] = time() + 600;//10分钟过期 + session('home_hosts', $hots); return $hots; } @@ -128,6 +138,13 @@ class IndexLogic extends Logic */ public static function getNews() { + $news = session('home_news'); + if (!empty($news)) { + // 有缓存且未过期 + if (!empty($news['expire']) && $news['expire'] > time()) { + return $news['list']; + } + } // 销售中商品:未删除/审核通过/已上架 $onSaleWhere = [ 'del' => GoodsEnum::DEL_NORMAL, // 未删除 @@ -140,12 +157,16 @@ class IndexLogic extends Logic 'sort_weight' => 'asc', // 商品权重 'id' => 'desc' ]; - $news = Goods::field('id,name,image,min_price,market_price,sales_actual,create_time,sales_virtual,(sales_actual + sales_virtual) as sales_total') + + $news = []; + $news['list'] = Goods::field('id,name,image,min_price,market_price,sales_actual,create_time,sales_virtual,(sales_actual + sales_virtual) as sales_total') ->where($onSaleWhere) ->order($order) ->limit(3) ->select() ->toArray(); + $news['expire'] = time() + 600;//10分钟过期 + session('home_news', $news); return $news; } @@ -480,7 +501,7 @@ class IndexLogic extends Logic return $other_qualifications; } - + /** * @notes 首页社区文章 * @return array