盲盒转盘优化-调试

This commit is contained in:
2025-10-24 20:58:31 +08:00
parent 3b22f8d134
commit e7a17bb34e
2 changed files with 35 additions and 6 deletions

View File

@@ -35,6 +35,9 @@ class SysSet extends adminApi
'10' => '邀请奖励',
'11' => '二级密码',
];
public $noAdminConfigType = [
'1' => '基础设置',
];
public function _initialize()
{
@@ -45,14 +48,18 @@ class SysSet extends adminApi
* 类型列表
*/
public function type_list(){
$configType = $this->configType;
if($this->auth->isSuperAdmin()){
$configType = $this->configType;
}else{
$configType = $this->noAdminConfigType;
}
$list = [];
$i=0;
foreach ($configType as $k=>$v){
$list[$i]['id'] = $k;
$list[$i]['name'] = $v;
$i++;
}
foreach ($configType as $k=>$v){
$list[$i]['id'] = $k;
$list[$i]['name'] = $v;
$i++;
}
return V(1,"成功", $list);
}

View File

@@ -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);
}