diff --git a/honey_box/pages/mall/detail.vue b/honey_box/pages/mall/detail.vue index 3f9d6d99..da685101 100644 --- a/honey_box/pages/mall/detail.vue +++ b/honey_box/pages/mall/detail.vue @@ -246,6 +246,14 @@ export default { }, 300); return; } + + // 检查库存 + const remainStock = (this.goodsInfo.stock || 0) - (this.goodsInfo.sale_stock || 0); + if (remainStock <= 0) { + this.$c.msg('库存不足,兑换失败'); + return; + } + // 登录后如果还没加载支付信息,先加载 if (!this.orderData) { this.loadDetail().then(() => { @@ -301,6 +309,14 @@ export default { this.$c.msg(this.$config.getAppSetting('currency2_name') + '不足'); return; } + + // 再次检查库存(防止并发购买) + const remainStock = (this.goodsInfo.stock || 0) - (this.goodsInfo.sale_stock || 0); + if (remainStock <= 0) { + this.$c.msg('库存不足,兑换失败'); + return; + } + const res = await createMallOrder({ goods_id: this.goodsId, prize_num: 1 }); if (res.status == 1) { this.$refs.orderPop.close(); diff --git a/server/HoneyBox/src/HoneyBox.Core/Services/OrderService.cs b/server/HoneyBox/src/HoneyBox.Core/Services/OrderService.cs index 61a59686..74251dad 100644 --- a/server/HoneyBox/src/HoneyBox.Core/Services/OrderService.cs +++ b/server/HoneyBox/src/HoneyBox.Core/Services/OrderService.cs @@ -2415,7 +2415,7 @@ public class OrderService : IOrderService if (prizeItem == null) { - throw new InvalidOperationException("暂无奖品信息"); + throw new InvalidOperationException("库存不足,兑换失败"); } // 12. 扣减奖品库存