mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 15:21:53 +08:00
砍价活动:完成订单取消时恢复活动库存
This commit is contained in:
parent
245f14b8f1
commit
42fcbe0501
@ -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) {
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user