盲盒转盘优化-重构-修改调试
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user