定版之后bug修改--缓存同意方法封装
This commit is contained in:
@@ -70,7 +70,8 @@ class BlindBoxTurntableGiftDraw extends Model
|
||||
$xlh_ext,
|
||||
$xlhIsPiaoPing,
|
||||
$currentXlhPeriodsNum,
|
||||
$room
|
||||
$room,
|
||||
$user_id
|
||||
);
|
||||
|
||||
// 6. 构建并返回结果
|
||||
@@ -574,13 +575,14 @@ class BlindBoxTurntableGiftDraw extends Model
|
||||
$xlh_ext,
|
||||
$xlhIsPiaoPing,
|
||||
$currentXlhPeriodsNum,
|
||||
$room
|
||||
$room,
|
||||
$user_id
|
||||
) {
|
||||
// 1. 批量插入盲盒转盘结果记录
|
||||
$this->batchInsertBlindBoxResults($precomputedResults, $boxTurntableLog, $room_id);
|
||||
|
||||
// 2. 发送礼物给接收者
|
||||
$this->sendGiftsToRecipients($precomputedResults, $boxTurntableLog, $room_id);
|
||||
$this->sendGiftsToRecipients($precomputedResults, $boxTurntableLog, $room_id,$user_id);
|
||||
|
||||
// 3. 处理巡乐会相关操作
|
||||
if (!empty($xlh_ext) && $xlh_ext['inlet_bag_id'] == $precomputedResults[0]['gift_bag_detail']['gift_bag_id']) {
|
||||
@@ -631,7 +633,7 @@ class BlindBoxTurntableGiftDraw extends Model
|
||||
/**
|
||||
* 发送礼物给接收者
|
||||
*/
|
||||
private function sendGiftsToRecipients($precomputedResults, $boxTurntableLog, $room_id)
|
||||
private function sendGiftsToRecipients($precomputedResults, $boxTurntableLog, $room_id,$user_id)
|
||||
{
|
||||
// 统计每个用户每个礼物的数量
|
||||
$giftUserCounts = [];
|
||||
@@ -659,7 +661,7 @@ class BlindBoxTurntableGiftDraw extends Model
|
||||
];
|
||||
|
||||
$res = model('Room')->room_gift(
|
||||
$precomputedResults[0]['gift_user_id'],
|
||||
$user_id,
|
||||
$userGift['gift_user_id'],
|
||||
$userGift['gift_id'],
|
||||
$userGift['count'],
|
||||
@@ -671,7 +673,7 @@ class BlindBoxTurntableGiftDraw extends Model
|
||||
);
|
||||
|
||||
if (isset($res) && $res['code'] != 1) {
|
||||
Log::record('发送礼物失败: ' . $res['msg'],"info");
|
||||
Log::record('发送礼物失败: ' . $res['msg'].$userGift['gift_user_id'],"info");
|
||||
return ['code' => 0, 'msg' => $res['msg'], 'data' => null];
|
||||
// \think\facade\Log::error('发送礼物失败: ' . $res['msg']);
|
||||
}
|
||||
@@ -885,11 +887,21 @@ class BlindBoxTurntableGiftDraw extends Model
|
||||
* 获取缓存的巡乐会配置
|
||||
*/
|
||||
private function getCachedXlhConfig() {
|
||||
$cacheKey = 'xlh_config_13';
|
||||
return Cache::remember($cacheKey, function() {
|
||||
$xlh_box = db::name('vs_gift_bag')->where('id', 13)->find();
|
||||
return $xlh_box ? json_decode($xlh_box['ext'], true) : [];
|
||||
}, 3600); // 缓存1小时
|
||||
$cacheKey = "xlh_config_13";
|
||||
$ext = Cache::get($cacheKey);
|
||||
if (!$ext) {
|
||||
$bag_data = db::name("vs_gift_bag")
|
||||
->field('id,name,ext,periods')
|
||||
->where('id', 13)
|
||||
->find();
|
||||
if (!$bag_data) {
|
||||
return [];
|
||||
}
|
||||
$ext = json_decode($bag_data['ext'], true);
|
||||
$ext['gift_bag_name'] = $bag_data['name'];
|
||||
Cache::set($cacheKey, $ext, 3600); // 缓存1小时
|
||||
}
|
||||
return $ext;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1045,19 +1057,7 @@ class BlindBoxTurntableGiftDraw extends Model
|
||||
|
||||
// 1. 获取并缓存盲盒配置
|
||||
$cacheKey = "xlh_config_{$gift_bag_id}";
|
||||
$ext = Cache::get($cacheKey);
|
||||
if (!$ext) {
|
||||
$bag_data = db::name("vs_gift_bag")
|
||||
->field('id,name,ext,periods')
|
||||
->where('id', $gift_bag_id)
|
||||
->find();
|
||||
if (!$bag_data) {
|
||||
return ['code' => 0, 'msg' => '盲盒配置不存在', 'data' => null];
|
||||
}
|
||||
$ext = json_decode($bag_data['ext'], true);
|
||||
$ext['gift_bag_name'] = $bag_data['name'];
|
||||
Cache::set($cacheKey, $ext, 3600); // 缓存1小时
|
||||
}
|
||||
$ext = $this->getCachedXlhConfig();
|
||||
|
||||
// 2. 检查用户金币和房间状态
|
||||
$bag_gift_price = $ext['xlh_box_price'] * $num;
|
||||
|
||||
Reference in New Issue
Block a user