盲盒转盘 优化-缓存配置修改 提交
This commit is contained in:
@@ -708,30 +708,18 @@ class BlindBoxTurntableGiftDrawWorldNew extends Model
|
|||||||
|
|
||||||
// 批量更新
|
// 批量更新
|
||||||
foreach ($inventoryUpdates as $giftId => $count) {
|
foreach ($inventoryUpdates as $giftId => $count) {
|
||||||
$giftBagDetail = Db::name("vs_gift_bag_detail")
|
|
||||||
->where('id', $giftId)
|
|
||||||
->find();
|
|
||||||
$giftBagDetailCached = $this->getCachedGiftBagDetailItem($gift_bag_id, $giftId);
|
$giftBagDetailCached = $this->getCachedGiftBagDetailItem($gift_bag_id, $giftId);
|
||||||
if (!$giftBagDetail) {
|
if(empty($giftBagDetailCached)){
|
||||||
throw new \Exception("礼物详情不存在,ID: " . $giftId);
|
$giftBagDetail = db::name("vs_gift_bag_detail")->where('id',$giftId)->find();
|
||||||
}
|
$upRemainingNumber = $giftBagDetail['remaining_number'] - $count;
|
||||||
$upRemainingNumber = $giftBagDetail['remaining_number'] - $count;
|
}else{
|
||||||
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));
|
|
||||||
$upRemainingNumber = $giftBagDetailCached['remaining_number'];
|
$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([
|
$ret = db::name("vs_gift_bag_detail")->where('id',$giftId)->update([
|
||||||
'remaining_number' => $upRemainingNumber
|
'remaining_number' => $upRemainingNumber
|
||||||
]);
|
]);
|
||||||
if (!$ret) {
|
if (!$ret) {
|
||||||
throw new \Exception('更新礼物剩余数量失败');
|
throw new \Exception('更新礼物剩余数量失败 ID: ' . $giftId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user