新需求-活动需求-盲盒转盘调通盘-巡乐会-调试
This commit is contained in:
@@ -37,9 +37,9 @@ class BlindBoxTurntableGiftDrawWorld extends Model
|
|||||||
public function draw_gift($gift_bag_id, $user_id, $gift_user_ids, $num = 1, $room_id = 0, $heart_id = 0,$auction_id = 0)
|
public function draw_gift($gift_bag_id, $user_id, $gift_user_ids, $num = 1, $room_id = 0, $heart_id = 0,$auction_id = 0)
|
||||||
{
|
{
|
||||||
// 最大重试次数
|
// 最大重试次数
|
||||||
// $maxRetries = 3;
|
$maxRetries = 3;
|
||||||
// for ($attempt = 0; $attempt < $maxRetries; $attempt++) {
|
for ($attempt = 0; $attempt < $maxRetries; $attempt++) {
|
||||||
// try {
|
try {
|
||||||
// 1. 验证参数并提前处理错误
|
// 1. 验证参数并提前处理错误
|
||||||
$validationResult = $this->validateDrawParameters($gift_bag_id, $user_id, $gift_user_ids);
|
$validationResult = $this->validateDrawParameters($gift_bag_id, $user_id, $gift_user_ids);
|
||||||
if ($validationResult !== true) {
|
if ($validationResult !== true) {
|
||||||
@@ -107,29 +107,29 @@ class BlindBoxTurntableGiftDrawWorld extends Model
|
|||||||
// 6. 构建并返回结果
|
// 6. 构建并返回结果
|
||||||
return $this->buildDrawResult($boxTurntableLog, $giftCounts);
|
return $this->buildDrawResult($boxTurntableLog, $giftCounts);
|
||||||
|
|
||||||
// } catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
// $key = 'blind_box_draw_errors_' . date('Y-m-d-H-i-s');
|
$key = 'blind_box_draw_errors_' . date('Y-m-d-H-i-s');
|
||||||
// $errorData = [
|
$errorData = [
|
||||||
// 'gift_bag_id' => $gift_bag_id,
|
'gift_bag_id' => $gift_bag_id,
|
||||||
// 'user_id' => $user_id,
|
'user_id' => $user_id,
|
||||||
// 'gift_user_ids' => $gift_user_ids,
|
'gift_user_ids' => $gift_user_ids,
|
||||||
// 'num' => $num,
|
'num' => $num,
|
||||||
// 'room_id' => $room_id,
|
'room_id' => $room_id,
|
||||||
// 'heart_id' => $heart_id,
|
'heart_id' => $heart_id,
|
||||||
// 'auction_id' => $auction_id,
|
'auction_id' => $auction_id,
|
||||||
// ];
|
];
|
||||||
// if ($this->redis) {
|
if ($this->redis) {
|
||||||
// $this->redis->setex($key, 86400 * 7, $e->getMessage() . ' ' . json_encode($errorData));
|
$this->redis->setex($key, 86400 * 7, $e->getMessage() . ' ' . json_encode($errorData));
|
||||||
// }
|
}
|
||||||
// // 如果是死锁且还有重试机会
|
// 如果是死锁且还有重试机会
|
||||||
// if (strpos($e->getMessage(), 'Deadlock') !== false && $attempt < $maxRetries - 1) {
|
if (strpos($e->getMessage(), 'Deadlock') !== false && $attempt < $maxRetries - 1) {
|
||||||
// // 随机延迟后重试
|
// 随机延迟后重试
|
||||||
// usleep(rand(50000, 200000)); // 50-200ms
|
usleep(rand(50000, 200000)); // 50-200ms
|
||||||
// continue;
|
continue;
|
||||||
// }
|
}
|
||||||
// return ['code' => 0, 'msg' => "网络加载失败,请重试!", 'data' => null];
|
return ['code' => 0, 'msg' => "网络加载失败,请重试!", 'data' => null];
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 验证抽奖参数
|
* 验证抽奖参数
|
||||||
@@ -320,6 +320,13 @@ class BlindBoxTurntableGiftDrawWorld extends Model
|
|||||||
$selectedGift = $this->selectGiftWithAliasMethod($aliasTableForRemaining);
|
$selectedGift = $this->selectGiftWithAliasMethod($aliasTableForRemaining);
|
||||||
if ($selectedGift) {
|
if ($selectedGift) {
|
||||||
$gift = $giftInfoMap[$selectedGift['foreign_id']] ?? null;
|
$gift = $giftInfoMap[$selectedGift['foreign_id']] ?? null;
|
||||||
|
if (empty($gift)) {
|
||||||
|
$selectedGift = $this->selectGiftWithAliasMethod($aliasTableForRemaining);
|
||||||
|
$gift = $giftInfoMap[$selectedGift['foreign_id']] ?? null;
|
||||||
|
}
|
||||||
|
if(!$gift){
|
||||||
|
throw new \Exception('礼物信息不存在');
|
||||||
|
}
|
||||||
$precomputedResults[] = [
|
$precomputedResults[] = [
|
||||||
'gift_user_id' => $giftUserId,
|
'gift_user_id' => $giftUserId,
|
||||||
'gift_bag_detail' => $selectedGift,
|
'gift_bag_detail' => $selectedGift,
|
||||||
@@ -493,9 +500,9 @@ class BlindBoxTurntableGiftDrawWorld extends Model
|
|||||||
$bagGiftPrice = $bag_data['gift_price'] * $num * $gift_user_num;
|
$bagGiftPrice = $bag_data['gift_price'] * $num * $gift_user_num;
|
||||||
|
|
||||||
// 增加重试机制
|
// 增加重试机制
|
||||||
// $maxRetries = 3;
|
$maxRetries = 3;
|
||||||
// for ($retry = 0; $retry < $maxRetries; $retry++) {
|
for ($retry = 0; $retry < $maxRetries; $retry++) {
|
||||||
// try {
|
try {
|
||||||
db::startTrans();
|
db::startTrans();
|
||||||
// 按照固定顺序处理事务步骤
|
// 按照固定顺序处理事务步骤
|
||||||
// 1. 扣除用户金币(优先处理)
|
// 1. 扣除用户金币(优先处理)
|
||||||
@@ -540,17 +547,17 @@ class BlindBoxTurntableGiftDrawWorld extends Model
|
|||||||
'gift_counts' => $giftCounts
|
'gift_counts' => $giftCounts
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
// } catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
// db::rollback();
|
db::rollback();
|
||||||
// // 检查是否是死锁错误
|
// 检查是否是死锁错误
|
||||||
// if (strpos($e->getMessage(), 'Deadlock') !== false && $retry < $maxRetries - 1) {
|
if (strpos($e->getMessage(), 'Deadlock') !== false && $retry < $maxRetries - 1) {
|
||||||
// // 等待随机时间后重试
|
// 等待随机时间后重试
|
||||||
// usleep(rand(10000, 100000)); // 10-100ms
|
usleep(rand(10000, 100000)); // 10-100ms
|
||||||
// continue;
|
continue;
|
||||||
// }
|
}
|
||||||
// return ['code' => 0, 'msg' => $e->getMessage(), 'data' => null];
|
return ['code' => 0, 'msg' => $e->getMessage(), 'data' => null];
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
return ['code' => 0, 'msg' => '操作超时,请重试', 'data' => null];
|
return ['code' => 0, 'msg' => '操作超时,请重试', 'data' => null];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user