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; - } - } - }