砍价活动:完成订单取消时恢复活动库存

This commit is contained in:
puhui999 2023-10-10 10:47:25 +08:00
parent 245f14b8f1
commit 42fcbe0501
3 changed files with 21 additions and 13 deletions

View File

@ -85,11 +85,16 @@ public class BargainActivityServiceImpl implements BargainActivityService {
@Override
public void updateBargainActivityStock(Long id, Integer count) {
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) {

View File

@ -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());
}
}

View File

@ -76,11 +76,4 @@ public class TradeCombinationHandler implements TradeOrderHandler {
recordIdAndHeadId.getKey(), recordIdAndHeadId.getValue());
}
@Override
public void cancelOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
if (TradeOrderTypeEnum.isCombination(order.getType())) {
return;
}
}
}