mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 18:28:43 +08:00 
			
		
		
		
	trade:支付订单成功时,记录订单日志
This commit is contained in:
		| @@ -14,6 +14,7 @@ import lombok.RequiredArgsConstructor; | |||||||
| public enum TradeOrderOperateTypeEnum { | public enum TradeOrderOperateTypeEnum { | ||||||
|  |  | ||||||
|     MEMBER_CREATE(1, "用户下单"), |     MEMBER_CREATE(1, "用户下单"), | ||||||
|  |     MEMBER_PAY(20, "用户付款成功"), | ||||||
|     MEMBER_RECEIVE(30, "用户已收货"), |     MEMBER_RECEIVE(30, "用户已收货"), | ||||||
|     SYSTEM_RECEIVE(31, "到期未收货,系统自动确认收货"), |     SYSTEM_RECEIVE(31, "到期未收货,系统自动确认收货"), | ||||||
|     MEMBER_COMMENT(33, "用户评价"), |     MEMBER_COMMENT(33, "用户评价"), | ||||||
|   | |||||||
| @@ -2,7 +2,10 @@ package cn.iocoder.yudao.module.trade.framework.order.core.annotations; | |||||||
|  |  | ||||||
| import cn.iocoder.yudao.module.trade.enums.order.TradeOrderOperateTypeEnum; | import cn.iocoder.yudao.module.trade.enums.order.TradeOrderOperateTypeEnum; | ||||||
|  |  | ||||||
| import java.lang.annotation.*; | import java.lang.annotation.Documented; | ||||||
|  | import java.lang.annotation.Retention; | ||||||
|  | import java.lang.annotation.RetentionPolicy; | ||||||
|  | import java.lang.annotation.Target; | ||||||
|  |  | ||||||
| import static java.lang.annotation.ElementType.ANNOTATION_TYPE; | import static java.lang.annotation.ElementType.ANNOTATION_TYPE; | ||||||
| import static java.lang.annotation.ElementType.METHOD; | import static java.lang.annotation.ElementType.METHOD; | ||||||
|   | |||||||
| @@ -31,6 +31,16 @@ import static java.util.Collections.emptyMap; | |||||||
| @Slf4j | @Slf4j | ||||||
| public class TradeOrderLogAspect { | public class TradeOrderLogAspect { | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 用户编号 | ||||||
|  |      * | ||||||
|  |      * 目前的使用场景:支付回调时,需要强制设置下用户编号 | ||||||
|  |      */ | ||||||
|  |     private static final ThreadLocal<Long> USER_ID = new ThreadLocal<>(); | ||||||
|  |     /** | ||||||
|  |      * 用户类型 | ||||||
|  |      */ | ||||||
|  |     private static final ThreadLocal<Integer> USER_TYPE = new ThreadLocal<>(); | ||||||
|     /** |     /** | ||||||
|      * 订单编号 |      * 订单编号 | ||||||
|      */ |      */ | ||||||
| @@ -112,4 +122,9 @@ public class TradeOrderLogAspect { | |||||||
|         EXTS.set(exts); |         EXTS.set(exts); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public static void setUserInfo(Long userId, Integer userType) { | ||||||
|  |         USER_ID.set(userId); | ||||||
|  |         USER_TYPE.set(userType); | ||||||
|  |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -20,4 +20,8 @@ public class TradeOrderLogUtils { | |||||||
|         TradeOrderLogAspect.setOrderInfo(id, beforeStatus, afterStatus, exts); |         TradeOrderLogAspect.setOrderInfo(id, beforeStatus, afterStatus, exts); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public static void setUserInfo(Long userId, Integer userType) { | ||||||
|  |         TradeOrderLogAspect.setUserInfo(userId, userType); | ||||||
|  |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -8,6 +8,7 @@ import cn.hutool.core.util.StrUtil; | |||||||
| import cn.hutool.extra.spring.SpringUtil; | import cn.hutool.extra.spring.SpringUtil; | ||||||
| import cn.iocoder.yudao.framework.common.core.KeyValue; | import cn.iocoder.yudao.framework.common.core.KeyValue; | ||||||
| import cn.iocoder.yudao.framework.common.enums.TerminalEnum; | import cn.iocoder.yudao.framework.common.enums.TerminalEnum; | ||||||
|  | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||||||
| import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | ||||||
| import cn.iocoder.yudao.module.member.api.address.AddressApi; | import cn.iocoder.yudao.module.member.api.address.AddressApi; | ||||||
| import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; | import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; | ||||||
| @@ -321,38 +322,39 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | |||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     @Transactional(rollbackFor = Exception.class) |     @Transactional(rollbackFor = Exception.class) | ||||||
|  |     @TradeOrderLog(operateType = TradeOrderOperateTypeEnum.MEMBER_PAY) | ||||||
|     public void updateOrderPaid(Long id, Long payOrderId) { |     public void updateOrderPaid(Long id, Long payOrderId) { | ||||||
|         // 校验并获得交易订单(可支付) |         // 1. 校验并获得交易订单(可支付) | ||||||
|         KeyValue<TradeOrderDO, PayOrderRespDTO> orderResult = validateOrderPayable(id, payOrderId); |         KeyValue<TradeOrderDO, PayOrderRespDTO> orderResult = validateOrderPayable(id, payOrderId); | ||||||
|         TradeOrderDO order = orderResult.getKey(); |         TradeOrderDO order = orderResult.getKey(); | ||||||
|         PayOrderRespDTO payOrder = orderResult.getValue(); |         PayOrderRespDTO payOrder = orderResult.getValue(); | ||||||
|  |  | ||||||
|         // 更新 TradeOrderDO 状态为已支付,等待发货 |         // 2. 更新 TradeOrderDO 状态为已支付,等待发货 | ||||||
|         int updateCount = tradeOrderMapper.updateByIdAndStatus(id, order.getStatus(), |         int updateCount = tradeOrderMapper.updateByIdAndStatus(id, order.getStatus(), | ||||||
|                 new TradeOrderDO().setStatus(TradeOrderStatusEnum.UNDELIVERED.getStatus()).setPayStatus(true) |                 new TradeOrderDO().setStatus(TradeOrderStatusEnum.UNDELIVERED.getStatus()).setPayStatus(true) | ||||||
|                         .setPayTime(LocalDateTime.now()).setPayChannelCode(payOrder.getChannelCode())); |                         .setPayTime(LocalDateTime.now()).setPayChannelCode(payOrder.getChannelCode())); | ||||||
|         if (updateCount == 0) { |         if (updateCount == 0) { | ||||||
|             throw exception(ORDER_UPDATE_PAID_STATUS_NOT_UNPAID); |             throw exception(ORDER_UPDATE_PAID_STATUS_NOT_UNPAID); | ||||||
|         } |         } | ||||||
|         // 校验活动 |  | ||||||
|  |         // 3. 校验活动 | ||||||
|         // 1、拼团活动 |         // 1、拼团活动 | ||||||
|         // TODO @puhui999:这块也抽象到 handler 里 |         // TODO @puhui999:这块也抽象到 handler 里 | ||||||
|         if (Objects.equals(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { |         if (Objects.equals(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { | ||||||
|             // 更新拼团状态 TODO puhui999:订单支付失败或订单支付过期删除这条拼团记录 |             // 更新拼团状态 TODO puhui999:订单支付失败或订单支付过期删除这条拼团记录 | ||||||
|             combinationRecordApi.updateRecordStatusToInProgress(order.getUserId(), order.getId(), LocalDateTime.now()); |             combinationRecordApi.updateRecordStatusToInProgress(order.getUserId(), order.getId(), LocalDateTime.now()); | ||||||
|         } |         } | ||||||
|         // TODO 芋艿:发送订单变化的消息 |  | ||||||
|  |  | ||||||
|         // TODO 芋艿:发送站内信 |         // 4.1 增加用户积分(赠送) | ||||||
|  |  | ||||||
|         // TODO 芋艿:OrderLog |  | ||||||
|  |  | ||||||
|         // 增加用户积分(赠送) |  | ||||||
|         addUserPoint(order.getUserId(), order.getGivePoint(), MemberPointBizTypeEnum.ORDER_GIVE, order.getId()); |         addUserPoint(order.getUserId(), order.getGivePoint(), MemberPointBizTypeEnum.ORDER_GIVE, order.getId()); | ||||||
|         // 增加用户经验 |         // 4.2 增加用户经验 | ||||||
|         getSelf().addUserExperienceAsync(order.getUserId(), order.getPayPrice(), order.getId()); |         getSelf().addUserExperienceAsync(order.getUserId(), order.getPayPrice(), order.getId()); | ||||||
|         // 增加用户佣金 |         // 4.3 增加用户佣金 | ||||||
|         getSelf().addBrokerageAsync(order.getUserId(), order.getId()); |         getSelf().addBrokerageAsync(order.getUserId(), order.getId()); | ||||||
|  |  | ||||||
|  |         // 5. 记录订单日志 | ||||||
|  |         TradeOrderLogUtils.setOrderInfo(order.getId(), order.getStatus(), TradeOrderStatusEnum.UNDELIVERED.getStatus()); | ||||||
|  |         TradeOrderLogUtils.setUserInfo(order.getUserId(), UserTypeEnum.MEMBER.getValue()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -435,8 +437,6 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | |||||||
|             throw exception(ORDER_DELIVERY_FAIL_STATUS_NOT_UNDELIVERED); |             throw exception(ORDER_DELIVERY_FAIL_STATUS_NOT_UNDELIVERED); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         // TODO 芋艿:发送订单变化的消息 |  | ||||||
|  |  | ||||||
|         // 发送站内信 |         // 发送站内信 | ||||||
|         tradeMessageService.sendMessageWhenDeliveryOrder(new TradeOrderMessageWhenDeliveryOrderReqBO().setOrderId(order.getId()) |         tradeMessageService.sendMessageWhenDeliveryOrder(new TradeOrderMessageWhenDeliveryOrderReqBO().setOrderId(order.getId()) | ||||||
|                 .setUserId(order.getUserId()).setMessage(null)); |                 .setUserId(order.getUserId()).setMessage(null)); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV