From b28e31e3847a06c42cad06912cf2e7381cfc05c2 Mon Sep 17 00:00:00 2001 From: youda Date: Sat, 19 Apr 2025 16:13:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/Config.php | 2 +- app/api/controller/Goods.php | 2 +- app/api/controller/Infinite.php | 57 +++++++++++++++++---------------- app/command/UpdateGoodsHeat.php | 2 +- 4 files changed, 32 insertions(+), 31 deletions(-) diff --git a/app/api/controller/Config.php b/app/api/controller/Config.php index e1e4c96..6ffe8c2 100755 --- a/app/api/controller/Config.php +++ b/app/api/controller/Config.php @@ -26,7 +26,7 @@ class Config extends Base return $this->renderSuccess('获取成功', [ 'good_type' => $goodsTypeList, 'app_setting' => $app_setting, - 'version' => '101' + 'version' => '103' ]); } diff --git a/app/api/controller/Goods.php b/app/api/controller/Goods.php index d756526..2d008db 100755 --- a/app/api/controller/Goods.php +++ b/app/api/controller/Goods.php @@ -267,7 +267,7 @@ class Goods extends Base ]; // 将结果缓存到Redis,设置过期时间为30秒(30秒) - $redis->set($cache_key, json_encode($new_data), 30); + $redis->set($cache_key, json_encode($new_data), 10); return $this->renderSuccess('请求成功', $new_data); } diff --git a/app/api/controller/Infinite.php b/app/api/controller/Infinite.php index 641f72b..3b772d5 100755 --- a/app/api/controller/Infinite.php +++ b/app/api/controller/Infinite.php @@ -35,28 +35,28 @@ class Infinite extends Base { $user_id = $this->getUserId(); $goods_id = request()->param('goods_id/d', 0); - + // 获取Redis实例并检查缓存 $redis = (new \app\common\server\RedisHelper())->getRedis(); $cache_key = "infinite_goodsdetail_{$goods_id}_{$user_id}"; $cache_data = $redis->get($cache_key); - + // 如果缓存存在,直接返回缓存数据 if ($cache_data) { $cached_data = json_decode($cache_data, true); - + // 检查是否有最新的热度值,并更新缓存中的数据 $heat_cache_key = "order_goods_count:{$goods_id}"; $latest_heat = $redis->get($heat_cache_key); - + if ($latest_heat !== false) { // 更新缓存数据中的热度值 $cached_data['goods']['join_count'] = intval($latest_heat); } - + return $this->renderSuccess("请求成功", $cached_data); } - + $goods = Goodsmodel::field('id,title,imgurl_detail,price,stock,sale_stock,lock_is,type,status,addtime,rage_is,rage,item_card_id,lingzhu_is,lingzhu_shang_id,is_shou_zhe,daily_xiangou,quanju_xiangou') ->where(['id' => $goods_id]) ->find(); @@ -120,15 +120,16 @@ class Infinite extends Base $redis = (new \app\common\server\RedisHelper())->getRedis(); $cacheKey = "order_goods_count:{$goods_id}"; $join_count1 = $redis->get($cacheKey); - + // 缓存未命中,从数据库获取并缓存 if ($join_count1 === false) { - $join_count1 = OrderList::field('id')->where('goods_id', '=', $goods_id) + $join_count1 = OrderList::field('id') + ->where('goods_id', '=', $goods_id) ->where('shang_id', 'between', [34, 38]) - ->where('order_type', '=', $goods['type']) - ->where('source', '=', 1) + // ->where('order_type', '=', $goods['type']) + // ->where('source', '=', 1) ->count(); - + // 设置缓存,5分钟过期 $redis->set($cacheKey, $join_count1, 300); } else { @@ -182,7 +183,7 @@ class Infinite extends Base $value['shang_color'] = $value['shang_info']['color']; unset($value['shang_info']); } - + $type1 = 8; if ($goods['type'] == 2) { $type1 = 8; } elseif ($goods['type'] == 8) { @@ -216,10 +217,10 @@ class Infinite extends Base 'danye_id' => $type1, 'limitInfo' => $limitInfo ]; - + // 将原始数据缓存到Redis,设置过期时间为60秒(3分钟) $redis->set($cache_key, json_encode($new_data), 180); - + return $this->renderSuccess("请求成功", $new_data); } @@ -282,7 +283,7 @@ class Infinite extends Base $redis = (new \app\common\server\RedisHelper())->getRedis(); $cacheKey = "order_goods_count:{$goods_id}"; $join_count1 = $redis->get($cacheKey); - + // 缓存未命中,从数据库获取并缓存 if ($join_count1 === false) { $join_count1 = OrderList::field('id')->where('goods_id', '=', $goods_id) @@ -290,7 +291,7 @@ class Infinite extends Base ->where('order_type', '=', $goods['type']) ->where('source', '=', 1) ->count(); - + // 设置缓存,5分钟过期 $redis->set($cacheKey, $join_count1, 300); } else { @@ -349,18 +350,18 @@ class Infinite extends Base $shang_id = request()->param('shang_id/d', 0); $goods_id = request()->param('goods_id/d', 0); $is_mibao = request()->param('is_mibao/d', 0); - + // 生成缓存键 $redis = (new \app\common\server\RedisHelper())->getRedis(); $cache_key = "infinite_shang_log:{$goods_id}:{$shang_id}:{$is_mibao}"; - + // 尝试从缓存获取数据 $cached_data = $redis->get($cache_key); if ($cached_data) { // 直接返回缓存的数据,这个方法不涉及热度值显示,无需更新 return $this->renderSuccess("请求成功", json_decode($cached_data, true)); } - + #盒子信息 $goods = Goodsmodel::field('id,stock,status,type') ->where(['id' => $goods_id]) @@ -410,10 +411,10 @@ class Infinite extends Base 'data' => $data->items(), 'last_page' => $data->lastPage(), ]; - + // 将数据存入缓存,设置1分钟过期时间 $redis->set($cache_key, json_encode($new_data), 60); - + return $this->renderSuccess("请求成功", $new_data); } @@ -1316,7 +1317,7 @@ class Infinite extends Base }); } - + $ling_goods_list = GoodsList::field('goods_id,shang_id,title,imgurl') ->append(['shang_info']) ->where(['goods_id' => $goods_id]) @@ -1329,12 +1330,12 @@ class Infinite extends Base } $ling_goods_list1 = GoodsList::field('goods_id,shang_id,title,imgurl') - ->append(['shang_info']) - ->where(['goods_id' => $goods_id]) - ->where('is_lingzhu', '=', 1) - ->where(['num' => 0]) - ->order('sort desc,shang_id asc,id asc') - ->select(); + ->append(['shang_info']) + ->where(['goods_id' => $goods_id]) + ->where('is_lingzhu', '=', 1) + ->where(['num' => 0]) + ->order('sort desc,shang_id asc,id asc') + ->select(); foreach ($ling_goods_list1 as &$value) { $value['imgurl'] = imageUrl($value['imgurl']); $ling_goods_list[] = $value; diff --git a/app/command/UpdateGoodsHeat.php b/app/command/UpdateGoodsHeat.php index 0b2f1d1..db640f8 100644 --- a/app/command/UpdateGoodsHeat.php +++ b/app/command/UpdateGoodsHeat.php @@ -12,7 +12,7 @@ use think\console\Output; use think\facade\Db; /** - * 更新盒子热度值到Redis命令 + * 更新盒子热度值到Redis命令 php think UpdateGoodsHeat */ class UpdateGoodsHeat extends Command {