diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java index f1d361d91..dc472e58c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java @@ -140,7 +140,7 @@ public class AppTradeOrderController { @Operation(summary = "确认交易订单收货") @Parameter(name = "id", description = "交易订单编号") public CommonResult receiveOrder(@RequestParam("id") Long id) { - tradeOrderUpdateService.receiveOrder(getLoginUserId(), id); + tradeOrderUpdateService.receiveOrderByMember(getLoginUserId(), id); return success(true); } @@ -148,7 +148,7 @@ public class AppTradeOrderController { @Operation(summary = "取消交易订单") @Parameter(name = "id", description = "交易订单编号") public CommonResult cancelOrder(@RequestParam("id") Long id) { - tradeOrderUpdateService.cancelOrder(getLoginUserId(), id); + tradeOrderUpdateService.cancelOrderByMember(getLoginUserId(), id); return success(true); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/order/TradeOrderAutoCancelJob.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/order/TradeOrderAutoCancelJob.java index 1833b9a69..2419987a6 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/order/TradeOrderAutoCancelJob.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/order/TradeOrderAutoCancelJob.java @@ -21,7 +21,7 @@ public class TradeOrderAutoCancelJob implements JobHandler { @Override public String execute(String param) { - int count = tradeOrderUpdateService.autoCancelOrder(); + int count = tradeOrderUpdateService.cancelOrderBySystem(); return String.format("过期订单 %s 个", count); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/order/TradeOrderAutoReceiveJob.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/order/TradeOrderAutoReceiveJob.java index 8d7b42b3c..06f3e9407 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/order/TradeOrderAutoReceiveJob.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/order/TradeOrderAutoReceiveJob.java @@ -21,7 +21,7 @@ public class TradeOrderAutoReceiveJob implements JobHandler { @Override public String execute(String param) { - int count = tradeOrderUpdateService.autoReceiveOrder(); + int count = tradeOrderUpdateService.receiveOrderBySystem(); return String.format("自动收货 %s 个", count); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java index f66e0efdb..18a75b679 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java @@ -60,14 +60,14 @@ public interface TradeOrderUpdateService { * @param userId 用户编号 * @param id 订单编号 */ - void receiveOrder(Long userId, Long id); + void receiveOrderByMember(Long userId, Long id); /** * 【系统】自动收货交易订单 * * @return 收货数量 */ - int autoReceiveOrder(); + int receiveOrderBySystem(); /** * 【会员】取消交易订单 @@ -75,14 +75,14 @@ public interface TradeOrderUpdateService { * @param userId 用户编号 * @param id 订单编号 */ - void cancelOrder(Long userId, Long id); + void cancelOrderByMember(Long userId, Long id); /** * 【系统】自动取消订单 * * @return 取消数量 */ - int autoCancelOrder(); + int cancelOrderBySystem(); /** * 【会员】删除订单 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index 8377fef15..0623cb8f3 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -488,7 +488,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Override @Transactional(rollbackFor = Exception.class) @TradeOrderLog(operateType = TradeOrderOperateTypeEnum.MEMBER_RECEIVE) - public void receiveOrder(Long userId, Long id) { + public void receiveOrderByMember(Long userId, Long id) { // 校验并获得交易订单(可收货) TradeOrderDO order = validateOrderReceivable(userId, id); @@ -497,7 +497,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { } @Override - public int autoReceiveOrder() { + public int receiveOrderBySystem() { // 1. 查询过期的待支付订单 LocalDateTime expireTime = addTime(tradeOrderProperties.getReceiveExpireTime()); List orders = tradeOrderMapper.selectListByStatusAndDeliveryTimeLt( @@ -510,7 +510,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { int count = 0; for (TradeOrderDO order : orders) { try { - getSelf().autoReceiveOrder(order); + getSelf().receiveOrderBySystem(order); count ++; } catch (Throwable e) { log.error("[autoReceiveOrder][order({}) 自动收货订单异常]", order.getId(), e); @@ -526,7 +526,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { */ @Transactional(rollbackFor = Exception.class) @TradeOrderLog(operateType = TradeOrderOperateTypeEnum.SYSTEM_RECEIVE) - public void autoReceiveOrder(TradeOrderDO order) { + public void receiveOrderBySystem(TradeOrderDO order) { receiveOrder0(order); } @@ -572,7 +572,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Override @Transactional(rollbackFor = Exception.class) @TradeOrderLog(operateType = TradeOrderOperateTypeEnum.MEMBER_CANCEL) - public void cancelOrder(Long userId, Long id) { + public void cancelOrderByMember(Long userId, Long id) { // 1.1 校验存在 TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(id, userId); if (order == null) { @@ -588,7 +588,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { } @Override - public int autoCancelOrder() { + public int cancelOrderBySystem() { // 1. 查询过期的待支付订单 LocalDateTime expireTime = addTime(tradeOrderProperties.getPayExpireTime()); List orders = tradeOrderMapper.selectListByStatusAndCreateTimeLt( @@ -601,7 +601,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { int count = 0; for (TradeOrderDO order : orders) { try { - getSelf().autoCancelOrder(order); + getSelf().cancelOrderBySystem(order); count ++; } catch (Throwable e) { log.error("[autoCancelOrder][order({}) 过期订单异常]", order.getId(), e); @@ -617,7 +617,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { */ @Transactional(rollbackFor = Exception.class) @TradeOrderLog(operateType = TradeOrderOperateTypeEnum.SYSTEM_CANCEL) - public void autoCancelOrder(TradeOrderDO order) { + public void cancelOrderBySystem(TradeOrderDO order) { cancelOrder0(order, TradeOrderCancelTypeEnum.PAY_TIMEOUT); } @@ -773,9 +773,11 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // =================== Order Item =================== + // TODO 疯狂:帮我重构下: + // 1. updateOrderItemAfterSaleStatus 拆分成三个方法:发起;同意;拒绝。原因是,职责更清晰,操作日志也更容易记录; + @Override @Transactional(rollbackFor = Exception.class) - // TODO 芋艿: public void updateOrderItemAfterSaleStatus(Long id, Integer oldAfterSaleStatus, Integer newAfterSaleStatus, Long afterSaleId, Integer refundPrice) { // 如果退款成功,则 refundPrice 非空 @@ -803,6 +805,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { TradeOrderItemDO orderItem = tradeOrderItemMapper.selectById(id); TradeOrderDO order = tradeOrderMapper.selectById(orderItem.getOrderId()); Integer orderRefundPrice = order.getRefundPrice() + refundPrice; + // TODO @疯狂:809 到 817 改成:cancelOrderByAfterSale:相当于全部售后成功后,就是要取消胆子; if (isAllOrderItemAfterSaleSuccess(order.getId())) { // 如果都售后成功,则需要取消订单 tradeOrderMapper.updateById(new TradeOrderDO().setId(order.getId()) .setRefundStatus(TradeOrderRefundStatusEnum.ALL.getStatus()).setRefundPrice(orderRefundPrice).setRefundPoint(order.getRefundPoint() + orderItem.getUsePoint()) @@ -812,7 +815,6 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // TODO 芋艿:要不要退优惠劵 - // TODO 芋艿:站内信? } else { // 如果部分售后,则更新退款金额 tradeOrderMapper.updateById(new TradeOrderDO().setId(order.getId()) .setRefundStatus(TradeOrderRefundStatusEnum.PART.getStatus()).setRefundPrice(orderRefundPrice)); @@ -821,6 +823,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // TODO 芋艿:这块扣减规则,需要在考虑下 // 售后成功后,执行数据回滚逻辑 if (Objects.equals(newAfterSaleStatus, TradeOrderItemAfterSaleStatusEnum.SUCCESS.getStatus())) { + // TODO @疯狂:这里库存也要扣减下; // 扣减用户积分(赠送的) reduceUserPoint(order.getUserId(), orderItem.getGivePoint(), MemberPointBizTypeEnum.AFTER_SALE_DEDUCT_GIVE, afterSaleId); // 增加用户积分(返还抵扣) @@ -880,6 +883,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { TradeOrderItemAfterSaleStatusEnum.SUCCESS.getStatus())); } + // =================== 营销相关的操作 =================== + @Async protected void addUserExperienceAsync(Long userId, Integer payPrice, Long orderId) { int bizType = MemberExperienceBizTypeEnum.ORDER.getType(); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceTest.java index 577780bd2..6b58fd9b6 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceTest.java @@ -306,7 +306,7 @@ public class TradeOrderUpdateServiceTest extends BaseDbUnitTest { // mock 方法(支付单) // 调用 - tradeOrderUpdateService.receiveOrder(userId, id); + tradeOrderUpdateService.receiveOrderByMember(userId, id); // 断言 TradeOrderDO dbOrder = tradeOrderMapper.selectById(1L); assertEquals(dbOrder.getStatus(), TradeOrderStatusEnum.COMPLETED.getStatus());