新需求-活动需求-盲盒转盘调通盘-巡乐会-调试-优化错误
This commit is contained in:
@@ -1101,8 +1101,11 @@ class BlindBoxTurntableGiftDrawWorld extends Model
|
||||
|
||||
while ($total_processed < $num) {
|
||||
$current_batch = min($batch_size, $num - $total_processed); // 当前批次处理数量
|
||||
db::startTrans();
|
||||
|
||||
$maxRetries = 3;
|
||||
for ($retry = 0; $retry < $maxRetries; $retry++) {
|
||||
try {
|
||||
db::startTrans();
|
||||
// 批量扣除金币(只在第一次事务中处理)
|
||||
if ($total_processed == 0) {
|
||||
$user_waller = db::name('user_wallet')->where(['user_id' => $user_id])->find();
|
||||
@@ -1202,6 +1205,7 @@ class BlindBoxTurntableGiftDrawWorld extends Model
|
||||
}
|
||||
|
||||
// 批量更新库存
|
||||
ksort($inventory_updates); // 按ID排序
|
||||
foreach ($inventory_updates as $detail_id => $count) {
|
||||
db::name("vs_gift_bag_detail")->where('id',$detail_id)->setDec('remaining_number', $count);
|
||||
}
|
||||
@@ -1234,6 +1238,12 @@ class BlindBoxTurntableGiftDrawWorld extends Model
|
||||
$total_processed += $current_batch;
|
||||
} catch (\Exception $e) {
|
||||
db::rollback();
|
||||
// 检查是否是死锁错误
|
||||
if (strpos($e->getMessage(), 'Deadlock') !== false && $retry < $maxRetries - 1) {
|
||||
// 等待随机时间后重试
|
||||
usleep(rand(10000, 100000)); // 10-100ms
|
||||
continue;
|
||||
}
|
||||
$key = 'xlh_draw_gift_errors_' . date('Y-m-d-H-i-s');
|
||||
$errorData = [
|
||||
'user_id' => $user_id,
|
||||
@@ -1244,6 +1254,7 @@ class BlindBoxTurntableGiftDrawWorld extends Model
|
||||
return ['code' => 0, 'msg' => "抽奖中,请稍等...", 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 7. 批量处理结果记录
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user