新需求-活动需求-盲盒转盘调通盘-巡乐会-调试-优化错误

This commit is contained in:
2025-10-15 14:58:37 +08:00
parent 213294ac64
commit faba9d6d2b

View File

@@ -1103,11 +1103,10 @@ class BlindBoxTurntableGiftDrawWorld extends Model
$batch_size = min(10, $num); // 每批次处理10次
$total_processed = 0;
$all_results = []; // 存储所有抽奖结果
while ($total_processed < $num) {
$current_batch = min($batch_size, $num - $total_processed); // 当前批次处理数量
try {
db::startTrans();
while ($total_processed < $num) {
$current_batch = min($batch_size, $num - $total_processed); // 当前批次处理数量
// 批量扣除金币(只在第一次事务中处理)
if ($total_processed == 0) {
$user_waller = db::name('user_wallet')->where(['user_id' => $user_id])->find();
@@ -1235,25 +1234,9 @@ class BlindBoxTurntableGiftDrawWorld extends Model
]);
$is_zhong_jiang = 1;
}
db::commit();
$total_processed += $current_batch;
} catch (\Exception $e) {
db::rollback();
$key = 'xlh_draw_gift_errors_' . date('Y-m-d-H-i-s');
$errorData = [
'user_id' => $user_id,
'gift_bag_id' => $gift_bag_id,
'room_id' => $room_id,
];
$this->redis->setex($key, 86400 * 7, $e->getMessage(). ' ' .json_encode($errorData));
return ['code' => 0, 'msg' => "抽奖中,请稍等...", 'data' => null];
}
}
// 7. 批量处理结果记录
try {
db::startTrans();
if(count($drawn_gifts) > $num){
$key = 'xlh_draw_gift_errors_' . date('Y-m-d-H-i-s');
$errorData = [
@@ -1310,7 +1293,6 @@ class BlindBoxTurntableGiftDrawWorld extends Model
'createtime' => time(),
'updatetime' => time()
]);
db::commit();
} catch (\Exception $e) {
db::rollback();
@@ -1320,10 +1302,9 @@ class BlindBoxTurntableGiftDrawWorld extends Model
'gift_bag_id' => $gift_bag_id,
'room_id' => $room_id,
];
$this->redis->setex($key, 86400 * 7, "巡乐会抽奖记录失败-异常:".$e->getMessage(). ' ' .json_encode($errorData));
return ['code' => 0, 'msg' => $e->getMessage(), 'data' => null];
$this->redis->setex($key, 86400 * 7, $e->getMessage(). ' ' .json_encode($errorData));
return ['code' => 0, 'msg' => "抽奖中,请稍等...", 'data' => null];
}
// 8. 处理推送消息
if ($is_zhong_jiang == 1) {
$this->handlePrizeNotification($user_id,$gift_id, $room_id, $pan_xlh_num, $end_time,$ext['locking_condition']['locking_gift_id']);