From 42fcbe0501eb61a7e10f74061f4bb729679bad3f Mon Sep 17 00:00:00 2001 From: puhui999 Date: Tue, 10 Oct 2023 10:47:25 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A0=8D=E4=BB=B7=E6=B4=BB=E5=8A=A8=EF=BC=9A?= =?UTF-8?q?=E5=AE=8C=E6=88=90=E8=AE=A2=E5=8D=95=E5=8F=96=E6=B6=88=E6=97=B6?= =?UTF-8?q?=E6=81=A2=E5=A4=8D=E6=B4=BB=E5=8A=A8=E5=BA=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bargain/BargainActivityServiceImpl.java | 15 ++++++++++----- .../order/handler/TradeBargainHandler.java | 12 +++++++++++- .../order/handler/TradeCombinationHandler.java | 7 ------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java index 8d10f0247..364cdf9ee 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java @@ -85,11 +85,16 @@ public class BargainActivityServiceImpl implements BargainActivityService { @Override public void updateBargainActivityStock(Long id, Integer count) { - // 更新库存。如果更新失败,则抛出异常 - int updateCount = bargainActivityMapper.updateStock(id, count); - if (updateCount == 0) { - throw exception(BARGAIN_ACTIVITY_STOCK_NOT_ENOUGH); + if (count < 0) { + // 更新库存。如果更新失败,则抛出异常 + int updateCount = bargainActivityMapper.updateStock(id, count); + if (updateCount == 0) { + throw exception(BARGAIN_ACTIVITY_STOCK_NOT_ENOUGH); + } + } else if (count > 0) { + bargainActivityMapper.updateStock(id, count); } + } private void validateBargainConflict(Long spuId, Long activityId) { @@ -140,7 +145,7 @@ public class BargainActivityServiceImpl implements BargainActivityService { @Override public List getBargainActivityList(Set ids) { - return bargainActivityMapper.selectBatchIds(ids); + return bargainActivityMapper.selectBatchIds(ids); } @Override diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainHandler.java index b83d2771b..e856621dc 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainHandler.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.trade.service.order.handler; +import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.module.promotion.api.bargain.BargainActivityApi; import cn.iocoder.yudao.module.promotion.api.bargain.BargainRecordApi; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; @@ -28,6 +29,8 @@ public class TradeBargainHandler implements TradeOrderHandler { if (TradeOrderTypeEnum.isBargain(order.getType())) { return; } + // 明确校验一下 + Assert.isTrue(orderItems.size() == 1, "砍价时,只允许选择一个商品"); // 扣减砍价活动的库存 bargainActivityApi.updateBargainActivityStock(order.getBargainActivityId(), @@ -39,6 +42,8 @@ public class TradeBargainHandler implements TradeOrderHandler { if (TradeOrderTypeEnum.isBargain(order.getType())) { return; } + // 明确校验一下 + Assert.isTrue(orderItems.size() == 1, "砍价时,只允许选择一个商品"); // 记录砍价记录对应的订单编号 bargainRecordApi.updateBargainRecordOrderId(order.getBargainRecordId(), order.getId()); @@ -49,7 +54,12 @@ public class TradeBargainHandler implements TradeOrderHandler { if (TradeOrderTypeEnum.isBargain(order.getType())) { return; } - // TODO 芋艿:取消订单时,需要增加库存 + // 明确校验一下 + Assert.isTrue(orderItems.size() == 1, "砍价时,只允许选择一个商品"); + + // 恢复砍价活动的库存 + bargainActivityApi.updateBargainActivityStock(order.getBargainActivityId(), + orderItems.get(0).getCount()); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java index c83615bda..05d87fa46 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java @@ -76,11 +76,4 @@ public class TradeCombinationHandler implements TradeOrderHandler { recordIdAndHeadId.getKey(), recordIdAndHeadId.getValue()); } - @Override - public void cancelOrder(TradeOrderDO order, List orderItems) { - if (TradeOrderTypeEnum.isCombination(order.getType())) { - return; - } - } - }