From a751597890bb28ba36a74612d121b50333157785 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E9=92=8A?= Date: Wed, 29 Oct 2025 14:55:30 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=B2=E7=9B=92=E8=BD=AC=E7=9B=98=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96-=E7=BC=93=E5=AD=98=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=20=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlindBoxTurntableGiftDrawWorldNew.php | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/application/api/model/BlindBoxTurntableGiftDrawWorldNew.php b/application/api/model/BlindBoxTurntableGiftDrawWorldNew.php index ab55fa4..6ea911e 100644 --- a/application/api/model/BlindBoxTurntableGiftDrawWorldNew.php +++ b/application/api/model/BlindBoxTurntableGiftDrawWorldNew.php @@ -708,30 +708,18 @@ class BlindBoxTurntableGiftDrawWorldNew extends Model // 批量更新 foreach ($inventoryUpdates as $giftId => $count) { - $giftBagDetail = Db::name("vs_gift_bag_detail") - ->where('id', $giftId) - ->find(); $giftBagDetailCached = $this->getCachedGiftBagDetailItem($gift_bag_id, $giftId); - if (!$giftBagDetail) { - throw new \Exception("礼物详情不存在,ID: " . $giftId); - } - $upRemainingNumber = $giftBagDetail['remaining_number'] - $count; - if($upRemainingNumber!=$giftBagDetailCached['remaining_number']){ - $this->redis->setex( 'blind_box_draw_errors_' . date('Y-m-d-H-i-s'), 86400 * 7, "有并发:礼物数量不一致,礼物ID: " . $giftId . '数据库数量: '.$upRemainingNumber. '缓存数量: '.$giftBagDetailCached['remaining_number']. ' ' .json_encode($giftBagDetail) . ' ' .json_encode($giftBagDetailCached)); + if(empty($giftBagDetailCached)){ + $giftBagDetail = db::name("vs_gift_bag_detail")->where('id',$giftId)->find(); + $upRemainingNumber = $giftBagDetail['remaining_number'] - $count; + }else{ $upRemainingNumber = $giftBagDetailCached['remaining_number']; } - // 检查库存是否足够 - if ($upRemainingNumber < 0) { - throw new \Exception("礼物库存不足,ID: " . $giftId); - } - if($upRemainingNumber = $giftBagDetail['remaining_number']){ - return; - } $ret = db::name("vs_gift_bag_detail")->where('id',$giftId)->update([ 'remaining_number' => $upRemainingNumber ]); if (!$ret) { - throw new \Exception('更新礼物剩余数量失败'); + throw new \Exception('更新礼物剩余数量失败 ID: ' . $giftId); } } }