盲盒转盘优化-调试
This commit is contained in:
@@ -379,6 +379,24 @@ class BlindBoxTurntableGiftDrawWorld extends Model
|
||||
for ($i = 0; $i < $userNewAllocation; $i++) {
|
||||
$selectedGift = $this->selectGiftWithAliasMethod($aliasTableForNew);
|
||||
if ($selectedGift) {
|
||||
// 检查实际库存是否足够
|
||||
if ($selectedGift['remaining_number'] <= 0) {
|
||||
// 如果库存不足,重新构建 Alias 表
|
||||
$aliasTableForNew = $this->buildAliasTable($availableGifts);
|
||||
$selectedGift = $this->selectGiftWithAliasMethod($aliasTableForNew);
|
||||
}
|
||||
// 更新内存中的礼物库存
|
||||
foreach ($availableGifts as &$gift) {
|
||||
if ($gift['id'] == $selectedGift['id']) {
|
||||
$gift['remaining_number']--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
unset($gift); // 清除引用
|
||||
|
||||
// 更新 Alias 表
|
||||
$this->updateAliasTable($aliasTableForNew, $selectedGift['id']);
|
||||
|
||||
$giftInfoMap = $this->preloadGiftInfo($availableGifts);
|
||||
$gift = $giftInfoMap[$selectedGift['foreign_id']];
|
||||
if($gift){
|
||||
@@ -1249,6 +1267,10 @@ class BlindBoxTurntableGiftDrawWorld extends Model
|
||||
// 批量更新库存
|
||||
ksort($inventory_updates); // 按ID排序
|
||||
foreach ($inventory_updates as $detail_id => $count) {
|
||||
$bag_detail = db::name("vs_gift_bag_detail")->field('remaining_number') ->where('id',$detail_id)->find();
|
||||
if($bag_detail['remaining_number'] < $count){
|
||||
throw new \Exception('库存不足');
|
||||
}
|
||||
db::name("vs_gift_bag_detail")->where('id',$detail_id)->setDec('remaining_number', $count);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user