From 5754f71023bc6b7b86d30b9561a2ae2851fe22d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E9=92=8A?= Date: Wed, 29 Oct 2025 17:47:12 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=B2=E7=9B=92=E8=BD=AC=E7=9B=98=E4=BC=98?= =?UTF-8?q?=E5=8C=96-=E9=87=8D=E6=9E=84-=E8=B0=83=E8=AF=95-=E5=86=8D?= =?UTF-8?q?=E5=8A=A0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlindBoxTurntableGiftDrawWorldNew.php | 50 ++++++++----------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/application/api/model/BlindBoxTurntableGiftDrawWorldNew.php b/application/api/model/BlindBoxTurntableGiftDrawWorldNew.php index ce73eac..39b634c 100644 --- a/application/api/model/BlindBoxTurntableGiftDrawWorldNew.php +++ b/application/api/model/BlindBoxTurntableGiftDrawWorldNew.php @@ -171,11 +171,10 @@ class BlindBoxTurntableGiftDrawWorldNew extends Model $newGiftsNeeded = max(0, $total_num - $remainingGiftCount); // 计算还需要多少礼物从新奖池中抽取 // 先从上期剩余礼物中分配 if (!empty($remaining_available_gifts)) { - $aliasTableForRemaining = $this->buildAliasTable($remaining_available_gifts); // 计算上期剩余礼物总数 foreach ($gift_user_ids as $giftUserId) { // 为每个用户先分配上期剩余礼物 - $userRemainingAllocation = floor($remainingGiftCount / $total_num); + $userRemainingAllocation = floor($remainingGiftCount / count($gift_user_ids)); if (count($gift_user_ids) > 0) { // 防止除零错误 $extraGifts = $remainingGiftCount % count($gift_user_ids); if (array_search($giftUserId, $gift_user_ids) < $extraGifts) { @@ -183,19 +182,26 @@ class BlindBoxTurntableGiftDrawWorldNew extends Model } } for ($i = 0; $i < $userRemainingAllocation; $i++) { - $selectedGift = $this->selectGiftWithAliasMethod($aliasTableForRemaining); - if ($selectedGift) { - $gift = $giftInfoMap[$selectedGift['foreign_id']]; - $precomputedResults[] = [ - 'gift_user_id' => $giftUserId, - 'gift_bag_detail' => $selectedGift, - 'gift' => $gift, - 'draw_times' => $this->getCachedPanDrawTimes($gift_bag_id), - 'periods' => $periods, - ]; - $this->getCachedXlhPeriodsNum("set");//添加寻乐会条件次数 - $pan_total_draw_times = $this->getCachedPanDrawTimes($gift_bag_id,"set"); // 总抽奖次数 - } + if(!empty($remaining_available_gifts)){ + $randomKey = array_rand($remaining_available_gifts); + $selectedGift = $remaining_available_gifts[$randomKey]; + --$remaining_available_gifts[$randomKey]['remaining_number']; + if($remaining_available_gifts[$randomKey]['remaining_number'] <=0){ + unset($remaining_available_gifts[$randomKey]); + } + if ($selectedGift) { + $gift = $giftInfoMap[$selectedGift['foreign_id']]; + $precomputedResults[] = [ + 'gift_user_id' => $giftUserId, + 'gift_bag_detail' => $selectedGift, + 'gift' => $gift, + 'draw_times' => $this->getCachedPanDrawTimes($gift_bag_id), + 'periods' => $periods, + ]; + $this->getCachedXlhPeriodsNum("set");//添加寻乐会条件次数 + $pan_total_draw_times = $this->getCachedPanDrawTimes($gift_bag_id,"set"); // 总抽奖次数 + } + } } } $pan_total_draw_times = $this->getCachedPanDrawTimes($gift_bag_id,"clear");//总抽奖次数重置 @@ -258,20 +264,6 @@ class BlindBoxTurntableGiftDrawWorldNew extends Model } } } - if (count($precomputedResults) != $total_num) { - // 记录错误到Redis - // 使用正确的Redis方法存储数据 - $key = 'blind_box_draw_world_errors_' . date('Y-m-d-H-i-s'); - $errorData = [ - 'total_num' => $total_num, - 'chag_total_num' => count($precomputedResults), - 'precomputedResults' => $precomputedResults, - 'availableGifts' => $availableGifts, - 'remaining_available_gifts' => $remaining_available_gifts, - ]; - $this->redis->setex($key, 86400 * 7, "超出数量".json_encode($errorData)); - return ['code' => 0, 'msg' => '网络加载失败,请重试!', 'data' => null]; - } return ['precomputedResults' => $precomputedResults, 'precomputedResultss' => $precomputedResultss]; }