feat: 首页接口优化

master
yin5th 2023-10-23 15:29:34 +08:00
parent 0c9003b65e
commit fb3019f1c4
1 changed files with 33 additions and 12 deletions

View File

@ -48,12 +48,12 @@ class IndexLogic extends Logic
$shopRecommend = self::getShopRecommend(); $shopRecommend = self::getShopRecommend();
// 秒杀商品 // 秒杀商品
$seckillTimes = SeckillGoodsLogic::seckillTime(); // $seckillTimes = SeckillGoodsLogic::seckillTime();
$seckillGoods = []; // $seckillGoods = [];
foreach($seckillTimes as $item) { // foreach($seckillTimes as $item) {
$item['goods'] = SeckillGoodsLogic::getSeckillGoodsTwo($item['id'],$terminal); // $item['goods'] = SeckillGoodsLogic::getSeckillGoodsTwo($item['id'],$terminal);
$seckillGoods[] = $item; // $seckillGoods[] = $item;
} // }
//活动专区 //活动专区
$activity_area = ActivityArea::field('id,name,synopsis as title,image')->where(['del'=>0,'status'=>1])->select(); $activity_area = ActivityArea::field('id,name,synopsis as title,image')->where(['del'=>0,'status'=>1])->select();
foreach ($activity_area as &$area_item){ foreach ($activity_area as &$area_item){
@ -61,7 +61,7 @@ class IndexLogic extends Logic
} }
// 种草社区文章 // 种草社区文章
$communityArticle = self::getCommunityArticle(); // $communityArticle = self::getCommunityArticle();
return [ return [
'headlines' => $headlines, 'headlines' => $headlines,
@ -70,8 +70,8 @@ class IndexLogic extends Logic
'activity_area' => $activity_area, 'activity_area' => $activity_area,
'shop_lists' => $shopLists, 'shop_lists' => $shopLists,
'shop_recommend' => $shopRecommend, 'shop_recommend' => $shopRecommend,
'seckill_goods' => $seckillGoods, // 'seckill_goods' => $seckillGoods,
'community_article' => $communityArticle // 'community_article' => $communityArticle
]; ];
} }
@ -101,6 +101,13 @@ class IndexLogic extends Logic
*/ */
public static function getHots() public static function getHots()
{ {
$hots = session('home_hosts');
if (!empty($hots)) {
// 有缓存且未过期
if (!empty($hots['expire']) && $hots['expire'] > time()) {
return $hots['list'];
}
}
// 销售中商品:未删除/审核通过/已上架 // 销售中商品:未删除/审核通过/已上架
$onSaleWhere = [ $onSaleWhere = [
'del' => GoodsEnum::DEL_NORMAL, // 未删除 'del' => GoodsEnum::DEL_NORMAL, // 未删除
@ -113,12 +120,15 @@ class IndexLogic extends Logic
'sort_weight' => 'asc', // 商品权重 'sort_weight' => 'asc', // 商品权重
'id' => 'desc' '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) ->where($onSaleWhere)
->order($order) ->order($order)
->limit(9) ->limit(9)
->select() ->select()
->toArray(); ->toArray();
$hots['expire'] = time() + 600;//10分钟过期
session('home_hosts', $hots);
return $hots; return $hots;
} }
@ -128,6 +138,13 @@ class IndexLogic extends Logic
*/ */
public static function getNews() public static function getNews()
{ {
$news = session('home_news');
if (!empty($news)) {
// 有缓存且未过期
if (!empty($news['expire']) && $news['expire'] > time()) {
return $news['list'];
}
}
// 销售中商品:未删除/审核通过/已上架 // 销售中商品:未删除/审核通过/已上架
$onSaleWhere = [ $onSaleWhere = [
'del' => GoodsEnum::DEL_NORMAL, // 未删除 'del' => GoodsEnum::DEL_NORMAL, // 未删除
@ -140,12 +157,16 @@ class IndexLogic extends Logic
'sort_weight' => 'asc', // 商品权重 'sort_weight' => 'asc', // 商品权重
'id' => 'desc' '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) ->where($onSaleWhere)
->order($order) ->order($order)
->limit(3) ->limit(3)
->select() ->select()
->toArray(); ->toArray();
$news['expire'] = time() + 600;//10分钟过期
session('home_news', $news);
return $news; return $news;
} }
@ -480,7 +501,7 @@ class IndexLogic extends Logic
return $other_qualifications; return $other_qualifications;
} }
/** /**
* @notes 首页社区文章 * @notes 首页社区文章
* @return array * @return array