Commit cf41347cb37ae14e8a30436246d8065661fb274c
1 parent
debf5687
trade:支付订单成功时,记录订单日志
Showing
5 changed files
with
37 additions
and
14 deletions
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java
| @@ -14,6 +14,7 @@ import lombok.RequiredArgsConstructor; | @@ -14,6 +14,7 @@ import lombok.RequiredArgsConstructor; | ||
| 14 | public enum TradeOrderOperateTypeEnum { | 14 | public enum TradeOrderOperateTypeEnum { |
| 15 | 15 | ||
| 16 | MEMBER_CREATE(1, "用户下单"), | 16 | MEMBER_CREATE(1, "用户下单"), |
| 17 | + MEMBER_PAY(20, "用户付款成功"), | ||
| 17 | MEMBER_RECEIVE(30, "用户已收货"), | 18 | MEMBER_RECEIVE(30, "用户已收货"), |
| 18 | SYSTEM_RECEIVE(31, "到期未收货,系统自动确认收货"), | 19 | SYSTEM_RECEIVE(31, "到期未收货,系统自动确认收货"), |
| 19 | MEMBER_COMMENT(33, "用户评价"), | 20 | MEMBER_COMMENT(33, "用户评价"), |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/core/annotations/TradeOrderLog.java
| @@ -2,7 +2,10 @@ package cn.iocoder.yudao.module.trade.framework.order.core.annotations; | @@ -2,7 +2,10 @@ package cn.iocoder.yudao.module.trade.framework.order.core.annotations; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.module.trade.enums.order.TradeOrderOperateTypeEnum; | 3 | import cn.iocoder.yudao.module.trade.enums.order.TradeOrderOperateTypeEnum; |
| 4 | 4 | ||
| 5 | -import java.lang.annotation.*; | 5 | +import java.lang.annotation.Documented; |
| 6 | +import java.lang.annotation.Retention; | ||
| 7 | +import java.lang.annotation.RetentionPolicy; | ||
| 8 | +import java.lang.annotation.Target; | ||
| 6 | 9 | ||
| 7 | import static java.lang.annotation.ElementType.ANNOTATION_TYPE; | 10 | import static java.lang.annotation.ElementType.ANNOTATION_TYPE; |
| 8 | import static java.lang.annotation.ElementType.METHOD; | 11 | import static java.lang.annotation.ElementType.METHOD; |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/core/aop/TradeOrderLogAspect.java
| @@ -32,6 +32,16 @@ import static java.util.Collections.emptyMap; | @@ -32,6 +32,16 @@ import static java.util.Collections.emptyMap; | ||
| 32 | public class TradeOrderLogAspect { | 32 | public class TradeOrderLogAspect { |
| 33 | 33 | ||
| 34 | /** | 34 | /** |
| 35 | + * 用户编号 | ||
| 36 | + * | ||
| 37 | + * 目前的使用场景:支付回调时,需要强制设置下用户编号 | ||
| 38 | + */ | ||
| 39 | + private static final ThreadLocal<Long> USER_ID = new ThreadLocal<>(); | ||
| 40 | + /** | ||
| 41 | + * 用户类型 | ||
| 42 | + */ | ||
| 43 | + private static final ThreadLocal<Integer> USER_TYPE = new ThreadLocal<>(); | ||
| 44 | + /** | ||
| 35 | * 订单编号 | 45 | * 订单编号 |
| 36 | */ | 46 | */ |
| 37 | private static final ThreadLocal<Long> ORDER_ID = new ThreadLocal<>(); | 47 | private static final ThreadLocal<Long> ORDER_ID = new ThreadLocal<>(); |
| @@ -112,4 +122,9 @@ public class TradeOrderLogAspect { | @@ -112,4 +122,9 @@ public class TradeOrderLogAspect { | ||
| 112 | EXTS.set(exts); | 122 | EXTS.set(exts); |
| 113 | } | 123 | } |
| 114 | 124 | ||
| 125 | + public static void setUserInfo(Long userId, Integer userType) { | ||
| 126 | + USER_ID.set(userId); | ||
| 127 | + USER_TYPE.set(userType); | ||
| 128 | + } | ||
| 129 | + | ||
| 115 | } | 130 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/core/utils/TradeOrderLogUtils.java
| @@ -20,4 +20,8 @@ public class TradeOrderLogUtils { | @@ -20,4 +20,8 @@ public class TradeOrderLogUtils { | ||
| 20 | TradeOrderLogAspect.setOrderInfo(id, beforeStatus, afterStatus, exts); | 20 | TradeOrderLogAspect.setOrderInfo(id, beforeStatus, afterStatus, exts); |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | + public static void setUserInfo(Long userId, Integer userType) { | ||
| 24 | + TradeOrderLogAspect.setUserInfo(userId, userType); | ||
| 25 | + } | ||
| 26 | + | ||
| 23 | } | 27 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java
| @@ -8,6 +8,7 @@ import cn.hutool.core.util.StrUtil; | @@ -8,6 +8,7 @@ import cn.hutool.core.util.StrUtil; | ||
| 8 | import cn.hutool.extra.spring.SpringUtil; | 8 | import cn.hutool.extra.spring.SpringUtil; |
| 9 | import cn.iocoder.yudao.framework.common.core.KeyValue; | 9 | import cn.iocoder.yudao.framework.common.core.KeyValue; |
| 10 | import cn.iocoder.yudao.framework.common.enums.TerminalEnum; | 10 | import cn.iocoder.yudao.framework.common.enums.TerminalEnum; |
| 11 | +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||
| 11 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | 12 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| 12 | import cn.iocoder.yudao.module.member.api.address.AddressApi; | 13 | import cn.iocoder.yudao.module.member.api.address.AddressApi; |
| 13 | import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; | 14 | import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; |
| @@ -321,38 +322,39 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | @@ -321,38 +322,39 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | ||
| 321 | 322 | ||
| 322 | @Override | 323 | @Override |
| 323 | @Transactional(rollbackFor = Exception.class) | 324 | @Transactional(rollbackFor = Exception.class) |
| 325 | + @TradeOrderLog(operateType = TradeOrderOperateTypeEnum.MEMBER_PAY) | ||
| 324 | public void updateOrderPaid(Long id, Long payOrderId) { | 326 | public void updateOrderPaid(Long id, Long payOrderId) { |
| 325 | - // 校验并获得交易订单(可支付) | 327 | + // 1. 校验并获得交易订单(可支付) |
| 326 | KeyValue<TradeOrderDO, PayOrderRespDTO> orderResult = validateOrderPayable(id, payOrderId); | 328 | KeyValue<TradeOrderDO, PayOrderRespDTO> orderResult = validateOrderPayable(id, payOrderId); |
| 327 | TradeOrderDO order = orderResult.getKey(); | 329 | TradeOrderDO order = orderResult.getKey(); |
| 328 | PayOrderRespDTO payOrder = orderResult.getValue(); | 330 | PayOrderRespDTO payOrder = orderResult.getValue(); |
| 329 | 331 | ||
| 330 | - // 更新 TradeOrderDO 状态为已支付,等待发货 | 332 | + // 2. 更新 TradeOrderDO 状态为已支付,等待发货 |
| 331 | int updateCount = tradeOrderMapper.updateByIdAndStatus(id, order.getStatus(), | 333 | int updateCount = tradeOrderMapper.updateByIdAndStatus(id, order.getStatus(), |
| 332 | new TradeOrderDO().setStatus(TradeOrderStatusEnum.UNDELIVERED.getStatus()).setPayStatus(true) | 334 | new TradeOrderDO().setStatus(TradeOrderStatusEnum.UNDELIVERED.getStatus()).setPayStatus(true) |
| 333 | .setPayTime(LocalDateTime.now()).setPayChannelCode(payOrder.getChannelCode())); | 335 | .setPayTime(LocalDateTime.now()).setPayChannelCode(payOrder.getChannelCode())); |
| 334 | if (updateCount == 0) { | 336 | if (updateCount == 0) { |
| 335 | throw exception(ORDER_UPDATE_PAID_STATUS_NOT_UNPAID); | 337 | throw exception(ORDER_UPDATE_PAID_STATUS_NOT_UNPAID); |
| 336 | } | 338 | } |
| 337 | - // 校验活动 | 339 | + |
| 340 | + // 3. 校验活动 | ||
| 338 | // 1、拼团活动 | 341 | // 1、拼团活动 |
| 339 | // TODO @puhui999:这块也抽象到 handler 里 | 342 | // TODO @puhui999:这块也抽象到 handler 里 |
| 340 | if (Objects.equals(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { | 343 | if (Objects.equals(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { |
| 341 | // 更新拼团状态 TODO puhui999:订单支付失败或订单支付过期删除这条拼团记录 | 344 | // 更新拼团状态 TODO puhui999:订单支付失败或订单支付过期删除这条拼团记录 |
| 342 | combinationRecordApi.updateRecordStatusToInProgress(order.getUserId(), order.getId(), LocalDateTime.now()); | 345 | combinationRecordApi.updateRecordStatusToInProgress(order.getUserId(), order.getId(), LocalDateTime.now()); |
| 343 | } | 346 | } |
| 344 | - // TODO 芋艿:发送订单变化的消息 | ||
| 345 | - | ||
| 346 | - // TODO 芋艿:发送站内信 | ||
| 347 | - | ||
| 348 | - // TODO 芋艿:OrderLog | ||
| 349 | 347 | ||
| 350 | - // 增加用户积分(赠送) | 348 | + // 4.1 增加用户积分(赠送) |
| 351 | addUserPoint(order.getUserId(), order.getGivePoint(), MemberPointBizTypeEnum.ORDER_GIVE, order.getId()); | 349 | addUserPoint(order.getUserId(), order.getGivePoint(), MemberPointBizTypeEnum.ORDER_GIVE, order.getId()); |
| 352 | - // 增加用户经验 | 350 | + // 4.2 增加用户经验 |
| 353 | getSelf().addUserExperienceAsync(order.getUserId(), order.getPayPrice(), order.getId()); | 351 | getSelf().addUserExperienceAsync(order.getUserId(), order.getPayPrice(), order.getId()); |
| 354 | - // 增加用户佣金 | 352 | + // 4.3 增加用户佣金 |
| 355 | getSelf().addBrokerageAsync(order.getUserId(), order.getId()); | 353 | getSelf().addBrokerageAsync(order.getUserId(), order.getId()); |
| 354 | + | ||
| 355 | + // 5. 记录订单日志 | ||
| 356 | + TradeOrderLogUtils.setOrderInfo(order.getId(), order.getStatus(), TradeOrderStatusEnum.UNDELIVERED.getStatus()); | ||
| 357 | + TradeOrderLogUtils.setUserInfo(order.getUserId(), UserTypeEnum.MEMBER.getValue()); | ||
| 356 | } | 358 | } |
| 357 | 359 | ||
| 358 | /** | 360 | /** |
| @@ -435,8 +437,6 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | @@ -435,8 +437,6 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | ||
| 435 | throw exception(ORDER_DELIVERY_FAIL_STATUS_NOT_UNDELIVERED); | 437 | throw exception(ORDER_DELIVERY_FAIL_STATUS_NOT_UNDELIVERED); |
| 436 | } | 438 | } |
| 437 | 439 | ||
| 438 | - // TODO 芋艿:发送订单变化的消息 | ||
| 439 | - | ||
| 440 | // 发送站内信 | 440 | // 发送站内信 |
| 441 | tradeMessageService.sendMessageWhenDeliveryOrder(new TradeOrderMessageWhenDeliveryOrderReqBO().setOrderId(order.getId()) | 441 | tradeMessageService.sendMessageWhenDeliveryOrder(new TradeOrderMessageWhenDeliveryOrderReqBO().setOrderId(order.getId()) |
| 442 | .setUserId(order.getUserId()).setMessage(null)); | 442 | .setUserId(order.getUserId()).setMessage(null)); |