新需求-活动需求-盲盒转盘调通盘

This commit is contained in:
2025-10-13 11:26:30 +08:00
parent 212c4faaf3
commit 9c0cd48425
4 changed files with 42 additions and 23 deletions

View File

@@ -52,10 +52,8 @@ class BlindBoxTurntableGiftDrawWorld extends Model
// 3. 预计算抽奖结果
$precomputeResult = $this->precomputeDrawResults(
$bag_data,
$room,
$gift_user_ids,
$num,
$room_id
$num
);
if ($precomputeResult['code'] !== 1) {
return $precomputeResult;
@@ -104,7 +102,18 @@ class BlindBoxTurntableGiftDrawWorld extends Model
} catch (\Exception $e) {
$key = 'blind_box_draw_errors_' . date('Y-m-d-H-i-s');
$this->redis->setex($key, 86400 * 7, $e->getMessage());
$errorData = [
'error_message' => $e->getMessage(),
'gift_bag_id' => $gift_bag_id,
'user_id' => $user_id,
'gift_user_ids' => $gift_user_ids,
'num' => $num,
'room_id' => $room_id,
'heart_id' => $heart_id,
'auction_id' => $auction_id,
];
$this->redis->setex($key, 86400 * 7, json_encode($errorData));
return ['code' => 0, 'msg' => "网络加载失败,请重试!", 'data' => null];
}
@@ -182,20 +191,17 @@ class BlindBoxTurntableGiftDrawWorld extends Model
/**
* 预计算抽奖结果
*/
private function precomputeDrawResults($bag_data, $room, $gift_user_ids, $num, $room_id)
private function precomputeDrawResults($bag_data, $gift_user_ids, $num)
{
$toarray = explode(',', $gift_user_ids);
$ext = json_decode($bag_data['ext'], true);
$xlh_ext = $this->getCachedXlhConfig();
$xlh_is_piao_ping = 0;
$current_xlh_periods_num = $room['xlh_periods_num'];
$current_xlh_periods_num = $this->getCachedXlhPeriodsNum("get");
// 1. 计算奖池信息
$poolInfo = $this->calculatePoolInfo($bag_data['id']);
if ($poolInfo['code'] !== 1) {
return $poolInfo;
}
$totalQuantity = $poolInfo['data']['total_quantity'];
$totalRemaining = $poolInfo['data']['total_remaining'];
$periods = $poolInfo['data']['periods'];
$totalDrawTimes = $poolInfo['data']['total_draw_times'];
@@ -543,7 +549,7 @@ class BlindBoxTurntableGiftDrawWorld extends Model
}
if (!empty($batchInsertData)) {
$insertResult = db::name("vs_gift_bag_receive_log")->insertAll($batchInsertData);
$insertResult = db::name("vs_gift_bag_receive_pan_log")->insertAll($batchInsertData);
if (!$insertResult) {
throw new \Exception('插入礼包发放记录失败');
}
@@ -700,17 +706,15 @@ class BlindBoxTurntableGiftDrawWorld extends Model
*/
private function handleXlhOperations($room_id, $xlh_ext, $xlhIsPiaoPing, $currentXlhPeriodsNum,$room)
{
if($room['xlh_periods_num'] < $xlh_ext['open_condition']['waiting_start_num'] && $currentXlhPeriodsNum >= $xlh_ext['open_condition']['waiting_start_num']){
$xlhPeriodsNum = $this->getCachedXlhPeriodsNum("get");
if($xlhPeriodsNum < $xlh_ext['open_condition']['waiting_start_num'] && $currentXlhPeriodsNum >= $xlh_ext['open_condition']['waiting_start_num']){
$xlhIsPiaoPing = 1;
}
if($room['xlh_periods_num'] < $xlh_ext['open_condition']['start_num'] && $currentXlhPeriodsNum >= $xlh_ext['open_condition']['start_num']){
if($xlhPeriodsNum < $xlh_ext['open_condition']['start_num'] && $currentXlhPeriodsNum >= $xlh_ext['open_condition']['start_num']){
$xlhIsPiaoPing = 2;
}
// 更新房间巡乐会次数
db::name("vs_room")->where('id', $room_id)->update([
'xlh_periods_num' => $currentXlhPeriodsNum
]);
$this->getCachedXlhPeriodsNum("set",$currentXlhPeriodsNum);
// 处理飘屏
if ($xlhIsPiaoPing == 1 || $xlhIsPiaoPing == 2) {
@@ -918,6 +922,18 @@ class BlindBoxTurntableGiftDrawWorld extends Model
}
return $ext;
}
/**
* 获取缓存的巡乐会开启次数
*/
private function getCachedXlhPeriodsNum($type="get",$num=1) {
$cacheKey = "xlh_periods_num";
$xlh_periods_num = Cache::get($cacheKey) ?? 0;
if($type=="set"){
$xlh_periods_num = $xlh_periods_num+$num;
Cache::set($cacheKey, $xlh_periods_num, 0);
}
return $xlh_periods_num;
}
/**
* 重置奖池
@@ -1190,7 +1206,7 @@ class BlindBoxTurntableGiftDrawWorld extends Model
}
if (!empty($gift_records)) {
db::name("vs_gift_bag_receive_log")->insertAll($gift_records);
db::name("vs_gift_bag_receive_pan_log")->insertAll($gift_records);
}
// 批量处理用户礼物包
@@ -1418,4 +1434,5 @@ class BlindBoxTurntableGiftDrawWorld extends Model
Log::record('Redis操作失败: ' . $e->getMessage(), 'error');
}
}
}