mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 07:11:52 +08:00
订单:介入 TradeOrderHandler#cancelOrder
This commit is contained in:
parent
c485c6e04d
commit
89b240c1f9
@ -1,5 +1,6 @@
|
||||
package cn.iocoder.yudao.module.trade.enums.order;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -37,4 +38,20 @@ public enum TradeOrderTypeEnum implements IntArrayValuable {
|
||||
return ARRAYS;
|
||||
}
|
||||
|
||||
public static boolean isNormal(Integer type) {
|
||||
return ObjectUtil.equal(type, NORMAL.getType());
|
||||
}
|
||||
|
||||
public static boolean isSeckill(Integer type) {
|
||||
return ObjectUtil.equal(type, SECKILL.getType());
|
||||
}
|
||||
|
||||
public static boolean isBargain(Integer type) {
|
||||
return ObjectUtil.equal(type, BARGAIN.getType());
|
||||
}
|
||||
|
||||
public static boolean isCombination(Integer type) {
|
||||
return ObjectUtil.equal(type, COMBINATION.getType());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -625,12 +625,11 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
||||
throw exception(ORDER_CANCEL_FAIL_STATUS_NOT_UNPAID);
|
||||
}
|
||||
|
||||
// 2. TODO 活动相关库存回滚需要活动 id,活动 id 怎么获取?app 端能否传过来;回复:从订单里拿呀
|
||||
tradeOrderHandlers.forEach(handler -> handler.cancelOrder());
|
||||
|
||||
// 3. 回滚库存
|
||||
List<TradeOrderItemDO> orderItems = tradeOrderItemMapper.selectListByOrderId(id);
|
||||
// 3. 回滚库存
|
||||
productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convert(orderItems));
|
||||
// 3.1、 活动相关的回滚
|
||||
tradeOrderHandlers.forEach(handler -> handler.cancelOrder(order, orderItems));
|
||||
|
||||
// 4. 回滚优惠券
|
||||
if (order.getCouponId() != null && order.getCouponId() > 0) {
|
||||
@ -807,10 +806,11 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
||||
// 2.2 如果全部退款,则进行取消订单
|
||||
getSelf().cancelOrderByAfterSale(order, orderRefundPrice);
|
||||
|
||||
// TODO @puhui999:活动相关的回滚
|
||||
|
||||
// 3. 回滚库存
|
||||
productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convert(Collections.singletonList(orderItem)));
|
||||
// 3.1、 活动相关的回滚
|
||||
tradeOrderHandlers.forEach(handler -> handler.cancelOrder(order, Collections.singletonList(orderItem)));
|
||||
|
||||
// 4.1 回滚积分:扣减用户积分(赠送的)
|
||||
reduceUserPoint(order.getUserId(), orderItem.getGivePoint(), MemberPointBizTypeEnum.AFTER_SALE_DEDUCT_GIVE, orderItem.getAfterSaleId());
|
||||
|
@ -1,6 +1,5 @@
|
||||
package cn.iocoder.yudao.module.trade.service.order.handler;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
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;
|
||||
@ -26,9 +25,10 @@ public class TradeBargainHandler implements TradeOrderHandler {
|
||||
|
||||
@Override
|
||||
public void beforeOrderCreate(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
|
||||
if (ObjectUtil.notEqual(TradeOrderTypeEnum.BARGAIN.getType(), order.getType())) {
|
||||
if (TradeOrderTypeEnum.isBargain(order.getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 扣减砍价活动的库存
|
||||
bargainActivityApi.updateBargainActivityStock(order.getBargainActivityId(),
|
||||
-orderItems.get(0).getCount());
|
||||
@ -36,13 +36,20 @@ public class TradeBargainHandler implements TradeOrderHandler {
|
||||
|
||||
@Override
|
||||
public void afterOrderCreate(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
|
||||
if (ObjectUtil.notEqual(TradeOrderTypeEnum.BARGAIN.getType(), order.getType())) {
|
||||
if (TradeOrderTypeEnum.isBargain(order.getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 记录砍价记录对应的订单编号
|
||||
bargainRecordApi.updateBargainRecordOrderId(order.getBargainRecordId(), order.getId());
|
||||
}
|
||||
|
||||
// TODO 芋艿:取消订单时,需要增加库存
|
||||
@Override
|
||||
public void cancelOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
|
||||
if (TradeOrderTypeEnum.isBargain(order.getType())) {
|
||||
return;
|
||||
}
|
||||
// TODO 芋艿:取消订单时,需要增加库存
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package cn.iocoder.yudao.module.trade.service.order.handler;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.iocoder.yudao.module.promotion.api.combination.CombinationRecordApi;
|
||||
import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert;
|
||||
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
|
||||
@ -26,7 +25,7 @@ public class TradeCombinationHandler implements TradeOrderHandler {
|
||||
@Override
|
||||
public void beforeOrderCreate(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
|
||||
// 如果不是拼团订单则结束
|
||||
if (ObjectUtil.notEqual(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) {
|
||||
if (TradeOrderTypeEnum.isCombination(order.getType())) {
|
||||
return;
|
||||
}
|
||||
Assert.isTrue(orderItems.size() == 1, "拼团时,只允许选择一个商品");
|
||||
@ -41,7 +40,7 @@ public class TradeCombinationHandler implements TradeOrderHandler {
|
||||
@Override
|
||||
public void afterPayOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
|
||||
// 如果不是拼团订单则结束
|
||||
if (ObjectUtil.notEqual(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) {
|
||||
if (TradeOrderTypeEnum.isCombination(order.getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -53,4 +52,11 @@ public class TradeCombinationHandler implements TradeOrderHandler {
|
||||
combinationRecordApi.createCombinationRecord(TradeOrderConvert.INSTANCE.convert(order, item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
|
||||
if (TradeOrderTypeEnum.isCombination(order.getType())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -40,7 +40,11 @@ public interface TradeOrderHandler {
|
||||
|
||||
/**
|
||||
* 订单取消
|
||||
*
|
||||
* @param order 订单
|
||||
* @param orderItems 订单项
|
||||
*/
|
||||
default void cancelOrder() {}
|
||||
default void cancelOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package cn.iocoder.yudao.module.trade.service.order.handler;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.iocoder.yudao.module.promotion.api.seckill.SeckillActivityApi;
|
||||
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
|
||||
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
|
||||
@ -23,12 +22,21 @@ public class TradeSeckillHandler implements TradeOrderHandler {
|
||||
|
||||
@Override
|
||||
public void beforeOrderCreate(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
|
||||
if (ObjectUtil.notEqual(TradeOrderTypeEnum.SECKILL.getType(), order.getType())) {
|
||||
if (TradeOrderTypeEnum.isSeckill(order.getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 扣减秒杀活动的库存
|
||||
seckillActivityApi.updateSeckillStock(order.getSeckillActivityId(),
|
||||
orderItems.get(0).getSkuId(), orderItems.get(0).getCount());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
|
||||
if (TradeOrderTypeEnum.isSeckill(order.getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user