diff --git a/application/api/model/BlindBoxTurntableGiftDrawWorldNew.php b/application/api/model/BlindBoxTurntableGiftDrawWorldNew.php index 6ea911e..1a12362 100644 --- a/application/api/model/BlindBoxTurntableGiftDrawWorldNew.php +++ b/application/api/model/BlindBoxTurntableGiftDrawWorldNew.php @@ -214,6 +214,16 @@ class BlindBoxTurntableGiftDrawWorldNew extends Model } for ($i = 0; $i < $userNewAllocation; $i++) { $selectedGift = $this->selectGiftWithAliasMethod($aliasTableForNew); + if(!$selectedGift){ + //重置奖池 + $availableGifts = $this->resetPoolAndReload($gift_bag_id); + if (empty($availableGifts)) { + throw new \Exception('重置奖池后仍无可用礼物'); + } + $this->getCachedPanDrawTimes($gift_bag_id,"clear");//总抽奖次数重置 + $aliasTableForNew = $this->buildAliasTable($availableGifts); + $selectedGift = $this->selectGiftWithAliasMethod($aliasTableForNew); + } if ($selectedGift) { $gift = $giftInfoMap[$selectedGift['foreign_id']]??[]; $precomputedResults[] = [ @@ -400,6 +410,12 @@ class BlindBoxTurntableGiftDrawWorldNew extends Model } $attempt++; } + // 兜底方案:遍历查找第一个有库存的礼物 + foreach ($aliasTable['index_map'] as $gift) { + if ($gift['remaining_number'] > 0) { + return $gift; + } + } // 如果重试次数用完仍未抽中有效礼物,返回null return null; }