mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-29 18:51:53 +08:00
重构:将订单的分支流程,抽到 TradeOrderHandler 实现类中(取消的排重逻辑)
This commit is contained in:
parent
2e5cc0537b
commit
150a1c9771
@ -1,5 +1,6 @@
|
|||||||
package cn.iocoder.yudao.module.trade.service.order.handler;
|
package cn.iocoder.yudao.module.trade.service.order.handler;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
|
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
|
||||||
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
|
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
|
||||||
@ -53,21 +54,36 @@ public class TradeBrokerageOrderHandler implements TradeOrderHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterPayOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
|
public void afterPayOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
|
||||||
if (order.getBrokerageUserId() != null) {
|
if (order.getBrokerageUserId() == null) {
|
||||||
addBrokerage(order.getUserId(), orderItems);
|
return;
|
||||||
}
|
}
|
||||||
|
addBrokerage(order.getUserId(), orderItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterCancelOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
|
public void afterCancelOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
|
||||||
// TODO 芋艿:取消支付时,需要处理下;
|
// 如果是未支付的订单,不会产生分销结果,所以直接 return
|
||||||
|
if (!order.getPayStatus()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (order.getBrokerageUserId() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 售后的订单项,已经在 afterCancelOrderItem 回滚库存,所以这里不需要重复回滚
|
||||||
|
orderItems = filterOrderItemListByNoneAfterSale(orderItems);
|
||||||
|
if (CollUtil.isEmpty(orderItems)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
orderItems.forEach(orderItem -> afterCancelOrderItem(order, orderItem));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterCancelOrderItem(TradeOrderDO order, TradeOrderItemDO orderItem) {
|
public void afterCancelOrderItem(TradeOrderDO order, TradeOrderItemDO orderItem) {
|
||||||
if (order.getBrokerageUserId() != null) {
|
if (order.getBrokerageUserId() == null) {
|
||||||
cancelBrokerage(order.getId(), orderItem.getOrderId());
|
return;
|
||||||
}
|
}
|
||||||
|
cancelBrokerage(order.getId(), orderItem.getOrderId());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package cn.iocoder.yudao.module.trade.service.order.handler;
|
package cn.iocoder.yudao.module.trade.service.order.handler;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.iocoder.yudao.module.member.api.level.MemberLevelApi;
|
import cn.iocoder.yudao.module.member.api.level.MemberLevelApi;
|
||||||
import cn.iocoder.yudao.module.member.api.point.MemberPointApi;
|
import cn.iocoder.yudao.module.member.api.point.MemberPointApi;
|
||||||
import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum;
|
import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum;
|
||||||
@ -13,6 +14,8 @@ import org.springframework.stereotype.Component;
|
|||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getSumValue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 会员积分、等级的 {@link TradeOrderHandler} 实现类
|
* 会员积分、等级的 {@link TradeOrderHandler} 实现类
|
||||||
*
|
*
|
||||||
@ -48,10 +51,29 @@ public class TradeMemberPointOrderHandler implements TradeOrderHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterCancelOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
|
public void afterCancelOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
|
||||||
// 扣减(回滚)用户积分(订单抵扣)
|
// 售后的订单项,已经在 afterCancelOrderItem 回滚库存,所以这里不需要重复回滚
|
||||||
addPoint(order.getUserId(), order.getUsePoint(), MemberPointBizTypeEnum.ORDER_CANCEL,
|
orderItems = filterOrderItemListByNoneAfterSale(orderItems);
|
||||||
|
if (CollUtil.isEmpty(orderItems)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 增加(回滚)用户积分(订单抵扣)
|
||||||
|
Integer usePoint = getSumValue(orderItems, TradeOrderItemDO::getUsePoint, Integer::sum);
|
||||||
|
addPoint(order.getUserId(), usePoint, MemberPointBizTypeEnum.ORDER_CANCEL,
|
||||||
order.getId());
|
order.getId());
|
||||||
// TODO 芋艿:需要校验;如果部分子订单已经售后退款,则不进行整单退;因为已经退了一部分积分了
|
// 如下的返还,需要经过支持,也就是经历 afterPayOrder 流程
|
||||||
|
if (!order.getPayStatus()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 扣减(回滚)积分(订单赠送)
|
||||||
|
Integer givePoint = getSumValue(orderItems, TradeOrderItemDO::getGivePoint, Integer::sum);
|
||||||
|
reducePoint(order.getUserId(), givePoint, MemberPointBizTypeEnum.ORDER_CANCEL,
|
||||||
|
order.getId());
|
||||||
|
// 扣减(回滚)用户经验
|
||||||
|
int payPrice = order.getPayPrice() - order.getRefundPrice();
|
||||||
|
// TODO @疯狂:这里的 bizId 和 afterCancelOrderItem 不一致了,有什么建议的处理方案?
|
||||||
|
memberLevelApi.addExperience(order.getUserId(), -payPrice, MemberExperienceBizTypeEnum.REFUND.getType(),
|
||||||
|
String.valueOf(order.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -59,7 +81,7 @@ public class TradeMemberPointOrderHandler implements TradeOrderHandler {
|
|||||||
// 扣减(回滚)积分(订单赠送)
|
// 扣减(回滚)积分(订单赠送)
|
||||||
reducePoint(order.getUserId(), orderItem.getGivePoint(), MemberPointBizTypeEnum.AFTER_SALE_DEDUCT_GIVE,
|
reducePoint(order.getUserId(), orderItem.getGivePoint(), MemberPointBizTypeEnum.AFTER_SALE_DEDUCT_GIVE,
|
||||||
orderItem.getAfterSaleId());
|
orderItem.getAfterSaleId());
|
||||||
// 扣减(回滚)积分:增加用户积分(返还抵扣)
|
// 增加(回滚)积分(订单抵扣)
|
||||||
addPoint(order.getUserId(), orderItem.getUsePoint(), MemberPointBizTypeEnum.AFTER_SALE_REFUND_USED,
|
addPoint(order.getUserId(), orderItem.getUsePoint(), MemberPointBizTypeEnum.AFTER_SALE_REFUND_USED,
|
||||||
orderItem.getAfterSaleId());
|
orderItem.getAfterSaleId());
|
||||||
|
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package cn.iocoder.yudao.module.trade.service.order.handler;
|
package cn.iocoder.yudao.module.trade.service.order.handler;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
|
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
|
||||||
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
|
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
|
||||||
|
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderItemAfterSaleStatusEnum;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -60,4 +62,17 @@ public interface TradeOrderHandler {
|
|||||||
*/
|
*/
|
||||||
default void beforeDeliveryOrder(TradeOrderDO order) {}
|
default void beforeDeliveryOrder(TradeOrderDO order) {}
|
||||||
|
|
||||||
|
// ========== 公用方法 ==========
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 过滤“未售后”的订单项列表
|
||||||
|
*
|
||||||
|
* @param orderItems 订单项列表
|
||||||
|
* @return 过滤后的订单项列表
|
||||||
|
*/
|
||||||
|
default List<TradeOrderItemDO> filterOrderItemListByNoneAfterSale(List<TradeOrderItemDO> orderItems) {
|
||||||
|
CollUtil.filterNew(orderItems, item -> !TradeOrderItemAfterSaleStatusEnum.isNone(item.getAfterSaleStatus()));
|
||||||
|
return orderItems;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package cn.iocoder.yudao.module.trade.service.order.handler;
|
package cn.iocoder.yudao.module.trade.service.order.handler;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi;
|
import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi;
|
||||||
import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert;
|
import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert;
|
||||||
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
|
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
|
||||||
@ -29,7 +30,11 @@ public class TradeProductSkuOrderHandler implements TradeOrderHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterCancelOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
|
public void afterCancelOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
|
||||||
// TODO 芋艿:如果部分售后,最后导致取消;这里需要过滤下;
|
// 售后的订单项,已经在 afterCancelOrderItem 回滚库存,所以这里不需要重复回滚
|
||||||
|
orderItems = filterOrderItemListByNoneAfterSale(orderItems);
|
||||||
|
if (CollUtil.isEmpty(orderItems)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convert(orderItems));
|
productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convert(orderItems));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user