From f8efd223ee453fca7125f37847c7733d7a75c64a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E9=92=8A?= Date: Wed, 7 Jan 2026 18:55:06 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=92=E5=90=A7=E6=88=BF=EF=BC=9A->=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=8E=A5=E5=8F=A3=E6=8F=90=E4=BA=A4-=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3bug=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/model/BarRoom.php | 3 ++ .../BlindBoxTurntableGiftDrawWorldNew.php | 37 +++++++++++++++---- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/application/api/model/BarRoom.php b/application/api/model/BarRoom.php index 94652b1d..8d034765 100644 --- a/application/api/model/BarRoom.php +++ b/application/api/model/BarRoom.php @@ -104,11 +104,14 @@ class BarRoom extends Model if(empty($gift)){ return ['code' => 0, 'msg' => '礼物不存在', 'data' => null]; } + //当前用户钱包余额(金币) + $wallet_coin = db::name('user_wallet_coin')->where(['user_id' => $user_id])->value('coin') ?? 0; $return_data = [ 'gift_id' => $pit_gift['gift_id'], 'gift_name' => $gift['gift_name'], 'base_image' => $gift['base_image'], 'gift_price' => $gift['gift_price'], + 'user_wallet_coin' => $wallet_coin, ]; } return ['code' => 1, 'msg' => '成功', 'data' => $return_data]; diff --git a/application/api/model/BlindBoxTurntableGiftDrawWorldNew.php b/application/api/model/BlindBoxTurntableGiftDrawWorldNew.php index e0e64447..8e8423e6 100644 --- a/application/api/model/BlindBoxTurntableGiftDrawWorldNew.php +++ b/application/api/model/BlindBoxTurntableGiftDrawWorldNew.php @@ -1616,6 +1616,7 @@ class BlindBoxTurntableGiftDrawWorldNew extends Model $this->getCachedPanDrawTimes($gift_bag_id, "clear"); } else if ($pan_total_remaining < $num) { // 如果剩余数量不足,保存当前剩余礼物作为上期剩余 + // 但只分配实际剩余数量的礼物,避免超额分配 $remaining_gifts = $available_gifts; $available_gifts = $this->resetPoolAndReload($gift_bag_id); @@ -1624,6 +1625,9 @@ class BlindBoxTurntableGiftDrawWorldNew extends Model } $this->getCachedPanDrawTimes($gift_bag_id, "clear"); + } else { + // 剩余数量足够,直接使用当前奖池 + // 不需要特殊处理,正常流程即可 } return [ @@ -1647,20 +1651,26 @@ class BlindBoxTurntableGiftDrawWorldNew extends Model $inventory_updates = []; $old_gift_num = 0; - // 先处理上期剩余的礼物 + // 先处理上期剩余的礼物,但要严格控制数量,避免超额分配 if (!empty($remaining_gifts)) { + // 获取上期实际剩余数量 + $remaining_total = array_sum(array_column($remaining_gifts, 'remaining_number')); + // 计算实际可从剩余礼物中分配的数量 + $actual_old_gift_num = min($num, $remaining_total); + + $gift_queue = []; // 初始化礼物队列 foreach ($remaining_gifts as $remaining_gift) { $gift_id = $remaining_gift['foreign_id'];//礼物ID - //查询上把这个礼物抽取数量---------------- + //查询上期这个礼物抽取数量---------------- $count_num = Db::name('vs_gift_bag_receive_pan_log')->where(['gift_bag_id' => $gift_bag_id,'gift_id' => $gift_id,'periods'=>$periods-1])->count(); $error_gifts[$gift_id] =[ //上期抽中数量 'count_num'=>$count_num, 'quantity'=>$remaining_gift['quantity'], + 'remaining_number'=>$remaining_gift['remaining_number'] // 添加实际剩余数量 ]; - //查询这个礼物上期数量 -// $this_gift_quantity = Db::name('vs_gift_bag_detail')->where(['gift_bag_id' => $gift_bag_id,'foreign_id' => $gift_id])->value('quantity'); + //上期这个礼物抽走数量与礼物上限数量相同剔除这个礼物 if ($count_num >= $remaining_gift['quantity']){ //错误日志记录-------- @@ -1676,14 +1686,25 @@ class BlindBoxTurntableGiftDrawWorldNew extends Model $this->redis->setex($key, 86400 * 7, "礼物数量超出限制 ".json_encode($errorData)); //错误日志记录--------end //剔除该礼物 - continue; + continue; } + + // 将礼物按剩余数量添加到队列中 + for ($i = 0; $i < $remaining_gift['remaining_number']; $i++) { + $gift_queue[] = $remaining_gift; + } + } + // 从礼物队列中分配礼物,直到达到实际需要的数量 + for ($i = 0; $i < $actual_old_gift_num && $i < count($gift_queue); $i++) { + $selected_gift = $gift_queue[$i]; + $gift_id = $selected_gift['foreign_id']; + //查询上把这个礼物抽取数量------防止并发多出容错---------- $drawn_gifts[$gift_id] = ($drawn_gifts[$gift_id] ?? 0) + 1; $precomputed_results[] = [ 'gift_id' => $gift_id, - 'gift_detail_id' => $remaining_gift['id'], - 'gift_bag_detail' => $remaining_gift, + 'gift_detail_id' => $selected_gift['id'], + 'gift_bag_detail' => $selected_gift, 'gift' => Db::name('vs_gift')->where(['gid' => $gift_id])->find(), 'gift_user_id' => 0, 'periods' => $periods, @@ -1715,7 +1736,7 @@ class BlindBoxTurntableGiftDrawWorldNew extends Model } // 计算还需要抽取的数量 - $remaining_count = $num - $old_gift_num; + $remaining_count = max(0, $num - $old_gift_num); // 抽取新礼物 for ($i = 0; $i < $remaining_count; $i++) {