This commit is contained in:
youda 2025-04-19 16:13:32 +08:00
parent f764e69640
commit b28e31e384
4 changed files with 32 additions and 31 deletions

View File

@ -26,7 +26,7 @@ class Config extends Base
return $this->renderSuccess('获取成功', [
'good_type' => $goodsTypeList,
'app_setting' => $app_setting,
'version' => '101'
'version' => '103'
]);
}

View File

@ -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);
}

View File

@ -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;

View File

@ -12,7 +12,7 @@ use think\console\Output;
use think\facade\Db;
/**
* 更新盒子热度值到Redis命令
* 更新盒子热度值到Redis命令 php think UpdateGoodsHeat
*/
class UpdateGoodsHeat extends Command
{