Commit 0cca6be63a22f8a3e625356ed3b3daa5f7b1fbaa
1 parent
5307852f
【新增】MALL: 订单发货订阅消息
Showing
2 changed files
with
25 additions
and
11 deletions
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/MessageTemplateConstants.java
| ... | ... | @@ -17,16 +17,6 @@ public interface MessageTemplateConstants { |
| 17 | 17 | //======================= 小程序订阅消息模版 ======================= |
| 18 | 18 | |
| 19 | 19 | String TRADE_AFTER_SALE_CHANGE = "售后进度通知"; |
| 20 | - | |
| 21 | - /** | |
| 22 | - * 售后进度通知相关参数枚举 | |
| 23 | - * | |
| 24 | - * @author HUIHUI | |
| 25 | - */ | |
| 26 | - class TradeAfterSaleChangeReqParams { | |
| 27 | - | |
| 28 | - public static final String ORDER_DELIVERY = "order_delivery"; | |
| 29 | - | |
| 30 | - } | |
| 20 | + String DELIVERY_ORDER = "订单发货通知"; | |
| 31 | 21 | |
| 32 | 22 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java
| 1 | 1 | package cn.iocoder.yudao.module.trade.service.order; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | +import cn.hutool.core.date.LocalDateTimeUtil; | |
| 4 | 5 | import cn.hutool.core.lang.Assert; |
| 5 | 6 | import cn.hutool.core.map.MapUtil; |
| 6 | 7 | import cn.hutool.core.util.ObjUtil; |
| ... | ... | @@ -19,6 +20,8 @@ import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderRespDTO; |
| 19 | 20 | import cn.iocoder.yudao.module.pay.enums.order.PayOrderStatusEnum; |
| 20 | 21 | import cn.iocoder.yudao.module.product.api.comment.ProductCommentApi; |
| 21 | 22 | import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO; |
| 23 | +import cn.iocoder.yudao.module.system.api.social.SocialClientApi; | |
| 24 | +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxaSubscribeMessageSendReqDTO; | |
| 22 | 25 | import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDeliveryReqVO; |
| 23 | 26 | import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderRemarkReqVO; |
| 24 | 27 | import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderUpdateAddressReqVO; |
| ... | ... | @@ -52,6 +55,7 @@ import cn.iocoder.yudao.module.trade.service.price.calculator.TradePriceCalculat |
| 52 | 55 | import jakarta.annotation.Resource; |
| 53 | 56 | import jakarta.validation.constraints.NotNull; |
| 54 | 57 | import lombok.extern.slf4j.Slf4j; |
| 58 | +import org.springframework.scheduling.annotation.Async; | |
| 55 | 59 | import org.springframework.stereotype.Service; |
| 56 | 60 | import org.springframework.transaction.annotation.Transactional; |
| 57 | 61 | |
| ... | ... | @@ -67,6 +71,7 @@ import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.min |
| 67 | 71 | import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; |
| 68 | 72 | import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getTerminal; |
| 69 | 73 | import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*; |
| 74 | +import static cn.iocoder.yudao.module.trade.enums.MessageTemplateConstants.DELIVERY_ORDER; | |
| 70 | 75 | |
| 71 | 76 | /** |
| 72 | 77 | * 交易订单【写】Service 实现类 |
| ... | ... | @@ -78,6 +83,8 @@ import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*; |
| 78 | 83 | @Slf4j |
| 79 | 84 | public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { |
| 80 | 85 | |
| 86 | + public static final String ORDER_DETAIL_PATH = "pages/order/detail"; // 订单详情页 | |
| 87 | + | |
| 81 | 88 | @Resource |
| 82 | 89 | private TradeOrderMapper tradeOrderMapper; |
| 83 | 90 | @Resource |
| ... | ... | @@ -103,6 +110,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { |
| 103 | 110 | private MemberAddressApi addressApi; |
| 104 | 111 | @Resource |
| 105 | 112 | private ProductCommentApi productCommentApi; |
| 113 | + @Resource | |
| 114 | + public SocialClientApi socialClientApi; | |
| 106 | 115 | |
| 107 | 116 | @Resource |
| 108 | 117 | private TradeOrderProperties tradeOrderProperties; |
| ... | ... | @@ -367,6 +376,21 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { |
| 367 | 376 | // 4. 发送站内信 |
| 368 | 377 | tradeMessageService.sendMessageWhenDeliveryOrder(new TradeOrderMessageWhenDeliveryOrderReqBO() |
| 369 | 378 | .setOrderId(order.getId()).setUserId(order.getUserId()).setMessage(null)); |
| 379 | + // 5. 发送订阅消息 | |
| 380 | + getSelf().sendDeliveryOrderMessage(order, deliveryReqVO); | |
| 381 | + } | |
| 382 | + | |
| 383 | + @Async | |
| 384 | + public void sendDeliveryOrderMessage(TradeOrderDO order, TradeOrderDeliveryReqVO deliveryReqVO) { | |
| 385 | + // 构建并发送模版消息 | |
| 386 | + Long orderId = order.getId(); | |
| 387 | + socialClientApi.sendWxaSubscribeMessage(new SocialWxaSubscribeMessageSendReqDTO().setPage(ORDER_DETAIL_PATH + "?id=" + orderId) | |
| 388 | + .setUserId(order.getUserId()).setUserType(UserTypeEnum.MEMBER.getValue()).setTemplateTitle(DELIVERY_ORDER) | |
| 389 | + .addMessage("character_string3", String.valueOf(orderId)) // 订单编号 | |
| 390 | + .addMessage("phrase6", TradeOrderStatusEnum.DELIVERED.getName()) // 订单状态 | |
| 391 | + .addMessage("date4", LocalDateTimeUtil.formatNormal(LocalDateTime.now()))// 发货时间 | |
| 392 | + .addMessage("character_string5", deliveryReqVO.getLogisticsNo()) // 快递单号 | |
| 393 | + .addMessage("thing9", order.getReceiverDetailAddress())); // 收货地址 | |
| 370 | 394 | } |
| 371 | 395 | |
| 372 | 396 | /** | ... | ... |