送盲盒转盘 报错解决
This commit is contained in:
@@ -47,7 +47,16 @@ class BlindBoxTurntableGiftDraw extends Model
|
|||||||
$availableGiftss = $precomputeResult['data']['availableGifts'];
|
$availableGiftss = $precomputeResult['data']['availableGifts'];
|
||||||
$currentXlhPeriodsNum = $precomputeResult['data']['current_xlh_periods_num'];
|
$currentXlhPeriodsNum = $precomputeResult['data']['current_xlh_periods_num'];
|
||||||
$xlhIsPiaoPing = $precomputeResult['data']['xlh_is_piao_ping'];
|
$xlhIsPiaoPing = $precomputeResult['data']['xlh_is_piao_ping'];
|
||||||
|
if(count($precomputedResults) != count(explode(',', $gift_user_ids)) * $num){
|
||||||
|
Log::record('抽奖结果数量与预期数量不一致,请重试! ('.count($precomputedResults).'): ' . $room_id."【数据】".var_export($precomputedResults, true),"infos-mhzp");
|
||||||
|
return ['code' => 0, 'msg' => '抽奖结果数量与预期数量不一致,请重试!', 'data' => null];
|
||||||
|
}
|
||||||
|
|
||||||
|
//兼容送礼判断,主持人比例设置为100% 送礼方法里报错,快速解决,把送礼方法前置,送完礼再处理盲盒转盘记录
|
||||||
|
$result = $this->sendGiftsToRecipients($precomputedResults, $room_id,$user_id);
|
||||||
|
if ($result['code'] !== 1) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
// 4. 执行抽奖事务(核心操作)
|
// 4. 执行抽奖事务(核心操作)
|
||||||
$transactionResult = $this->executeDrawTransaction(
|
$transactionResult = $this->executeDrawTransaction(
|
||||||
$bag_data,
|
$bag_data,
|
||||||
@@ -285,13 +294,10 @@ class BlindBoxTurntableGiftDraw extends Model
|
|||||||
unset($remaining_available_gifts[$key]);
|
unset($remaining_available_gifts[$key]);
|
||||||
}
|
}
|
||||||
$numm = $num;
|
$numm = $num;
|
||||||
// echo "好好玩";
|
|
||||||
}else{
|
}else{
|
||||||
$numm = $num+$remaining_num;
|
$numm = $num+$remaining_num;
|
||||||
}
|
}
|
||||||
// echo $numm."---";
|
|
||||||
for ($i = 0; $i < $numm; $i++) {
|
for ($i = 0; $i < $numm; $i++) {
|
||||||
// echo "好好呀";
|
|
||||||
// 使用Alias Method选择礼物(O(1)复杂度)
|
// 使用Alias Method选择礼物(O(1)复杂度)
|
||||||
$selectedGift = $this->selectGiftWithAliasMethod($aliasTable);
|
$selectedGift = $this->selectGiftWithAliasMethod($aliasTable);
|
||||||
if (!$selectedGift) {
|
if (!$selectedGift) {
|
||||||
@@ -591,8 +597,8 @@ class BlindBoxTurntableGiftDraw extends Model
|
|||||||
// 1. 批量插入盲盒转盘结果记录
|
// 1. 批量插入盲盒转盘结果记录
|
||||||
$this->batchInsertBlindBoxResults($precomputedResults, $boxTurntableLog, $room_id);
|
$this->batchInsertBlindBoxResults($precomputedResults, $boxTurntableLog, $room_id);
|
||||||
|
|
||||||
// 2. 发送礼物给接收者
|
// 2. 发送礼物给接收者 (已前置)
|
||||||
$this->sendGiftsToRecipients($precomputedResults, $boxTurntableLog, $room_id,$user_id);
|
// $this->sendGiftsToRecipients($precomputedResults, $room_id,$user_id);
|
||||||
|
|
||||||
// 3. 处理巡乐会相关操作
|
// 3. 处理巡乐会相关操作
|
||||||
if (!empty($xlh_ext) && $xlh_ext['inlet_bag_id'] == $precomputedResults[0]['gift_bag_detail']['gift_bag_id']) {
|
if (!empty($xlh_ext) && $xlh_ext['inlet_bag_id'] == $precomputedResults[0]['gift_bag_detail']['gift_bag_id']) {
|
||||||
@@ -643,7 +649,7 @@ class BlindBoxTurntableGiftDraw extends Model
|
|||||||
/**
|
/**
|
||||||
* 发送礼物给接收者
|
* 发送礼物给接收者
|
||||||
*/
|
*/
|
||||||
private function sendGiftsToRecipients($precomputedResults, $boxTurntableLog, $room_id,$user_id)
|
private function sendGiftsToRecipients($precomputedResults, $room_id,$user_id)
|
||||||
{
|
{
|
||||||
// 统计每个用户每个礼物的数量
|
// 统计每个用户每个礼物的数量
|
||||||
$giftUserCounts = [];
|
$giftUserCounts = [];
|
||||||
@@ -662,6 +668,9 @@ class BlindBoxTurntableGiftDraw extends Model
|
|||||||
|
|
||||||
// 批量发送礼物
|
// 批量发送礼物
|
||||||
foreach ($giftUserCounts as $userGift) {
|
foreach ($giftUserCounts as $userGift) {
|
||||||
|
if($userGift['count'] > 9){ //防止礼物超发,礼物超10个则不发送
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$giveGiftExt = [
|
$giveGiftExt = [
|
||||||
'gift_id' => $userGift['gift_id'],
|
'gift_id' => $userGift['gift_id'],
|
||||||
'count' => $userGift['count'],
|
'count' => $userGift['count'],
|
||||||
@@ -1299,7 +1308,10 @@ class BlindBoxTurntableGiftDraw extends Model
|
|||||||
// 7. 批量处理结果记录
|
// 7. 批量处理结果记录
|
||||||
try {
|
try {
|
||||||
db::startTrans();
|
db::startTrans();
|
||||||
|
if(count($drawn_gifts) > $num){
|
||||||
|
Log::record('巡乐会抽奖失败-数量超限: ' . count($drawn_gifts),"infos");
|
||||||
|
return ['code' => 0, 'msg' => "抽奖中,请稍等...", 'data' => null];
|
||||||
|
}
|
||||||
// 批量插入礼包发放记录
|
// 批量插入礼包发放记录
|
||||||
$gift_records = [];
|
$gift_records = [];
|
||||||
$periods = $room_pan_data[0]['periods'] ?? 0;
|
$periods = $room_pan_data[0]['periods'] ?? 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user