Commit 1f65dd2ec99192a99015963416a0a6914c0c2b33

Authored by 芋道源码
Committed by Gitee
2 parents e860314b b678da81

!1027 【新增】MALL:拼团结果通知订阅消息

Merge pull request !1027 from puhui999/develop
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/MessageTemplateConstants.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.enums;
  2 +
  3 +/**
  4 + * 通知模板枚举类
  5 + *
  6 + * @author HUIHUI
  7 + */
  8 +public interface MessageTemplateConstants {
  9 +
  10 + //======================= 小程序订阅消息模版 =======================
  11 +
  12 + String COMBINATION_RESULT = "拼团结果通知";
  13 +
  14 +}
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java
@@ -5,6 +5,7 @@ import cn.hutool.core.util.ObjUtil; @@ -5,6 +5,7 @@ import cn.hutool.core.util.ObjUtil;
5 import cn.hutool.extra.spring.SpringUtil; 5 import cn.hutool.extra.spring.SpringUtil;
6 import cn.iocoder.yudao.framework.common.core.KeyValue; 6 import cn.iocoder.yudao.framework.common.core.KeyValue;
7 import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; 7 import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
  8 +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
8 import cn.iocoder.yudao.framework.common.pojo.PageResult; 9 import cn.iocoder.yudao.framework.common.pojo.PageResult;
9 import cn.iocoder.yudao.framework.common.util.json.JsonUtils; 10 import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
10 import cn.iocoder.yudao.module.member.api.user.MemberUserApi; 11 import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
@@ -23,11 +24,14 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationP @@ -23,11 +24,14 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationP
23 import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; 24 import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO;
24 import cn.iocoder.yudao.module.promotion.dal.mysql.combination.CombinationRecordMapper; 25 import cn.iocoder.yudao.module.promotion.dal.mysql.combination.CombinationRecordMapper;
25 import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; 26 import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum;
  27 +import cn.iocoder.yudao.module.system.api.social.SocialClientApi;
  28 +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxaSubscribeMessageSendReqDTO;
26 import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi; 29 import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi;
27 import jakarta.annotation.Nullable; 30 import jakarta.annotation.Nullable;
28 import jakarta.annotation.Resource; 31 import jakarta.annotation.Resource;
29 import lombok.extern.slf4j.Slf4j; 32 import lombok.extern.slf4j.Slf4j;
30 import org.springframework.context.annotation.Lazy; 33 import org.springframework.context.annotation.Lazy;
  34 +import org.springframework.scheduling.annotation.Async;
31 import org.springframework.stereotype.Service; 35 import org.springframework.stereotype.Service;
32 import org.springframework.transaction.annotation.Transactional; 36 import org.springframework.transaction.annotation.Transactional;
33 import org.springframework.validation.annotation.Validated; 37 import org.springframework.validation.annotation.Validated;
@@ -40,6 +44,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. @@ -40,6 +44,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.
40 import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.afterNow; 44 import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.afterNow;
41 import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.beforeNow; 45 import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.beforeNow;
42 import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; 46 import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*;
  47 +import static cn.iocoder.yudao.module.promotion.enums.MessageTemplateConstants.COMBINATION_RESULT;
43 48
44 // TODO 芋艿:等拼团记录做完,完整 review 下 49 // TODO 芋艿:等拼团记录做完,完整 review 下
45 50
@@ -68,6 +73,8 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { @@ -68,6 +73,8 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
68 @Resource 73 @Resource
69 @Lazy // 延迟加载,避免循环依赖 74 @Lazy // 延迟加载,避免循环依赖
70 private TradeOrderApi tradeOrderApi; 75 private TradeOrderApi tradeOrderApi;
  76 + @Resource
  77 + public SocialClientApi socialClientApi;
71 78
72 // TODO @芋艿:在详细预览下; 79 // TODO @芋艿:在详细预览下;
73 @Override 80 @Override
@@ -205,7 +212,25 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { @@ -205,7 +212,25 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
205 } 212 }
206 updateRecords.add(updateRecord); 213 updateRecords.add(updateRecord);
207 }); 214 });
208 - combinationRecordMapper.updateBatch(updateRecords); 215 + Boolean result = combinationRecordMapper.updateBatch(updateRecords);
  216 +
  217 + // 3. 拼团成功发送订阅消息
  218 + if (result && isFull) {
  219 + records.forEach(item -> {
  220 + getSelf().sendCombinationResultMessage(item);
  221 + });
  222 + }
  223 + }
  224 +
  225 + @Async
  226 + public void sendCombinationResultMessage(CombinationRecordDO record) {
  227 + // 构建并发送模版消息
  228 + socialClientApi.sendWxaSubscribeMessage(new SocialWxaSubscribeMessageSendReqDTO()
  229 + .setUserId(record.getUserId()).setUserType(UserTypeEnum.MEMBER.getValue())
  230 + .setTemplateTitle(COMBINATION_RESULT)
  231 + .setPage("pages/order/detail?id=" + record.getOrderId()) // 订单详情页
  232 + .addMessage("thing1", "商品拼团活动") // 活动标题
  233 + .addMessage("thing2", "恭喜您拼团成功!我们将尽快为您发货。")); // 温馨提示
209 } 234 }
210 235
211 @Override 236 @Override
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/MessageTemplateConstants.java
@@ -16,7 +16,6 @@ public interface MessageTemplateConstants { @@ -16,7 +16,6 @@ public interface MessageTemplateConstants {
16 16
17 //======================= 小程序订阅消息模版 ======================= 17 //======================= 小程序订阅消息模版 =======================
18 18
19 - String TRADE_AFTER_SALE_CHANGE = "售后进度通知";  
20 String DELIVERY_ORDER = "订单发货通知"; 19 String DELIVERY_ORDER = "订单发货通知";
21 20
22 } 21 }
yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/MessageTemplateConstants.java
@@ -10,7 +10,5 @@ public interface MessageTemplateConstants { @@ -10,7 +10,5 @@ public interface MessageTemplateConstants {
10 //======================= 小程序订阅消息 ======================= 10 //======================= 小程序订阅消息 =======================
11 11
12 String WALLET_RECHARGER_PAID = "充值成功通知"; 12 String WALLET_RECHARGER_PAID = "充值成功通知";
13 - // TODO @puhui999:这个放在售后那。aftersale  
14 - String WALLET_RECHARGE_REFUNDED = "退款申请通知";  
15 13
16 } 14 }
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java
@@ -40,7 +40,6 @@ import static cn.iocoder.yudao.framework.common.util.number.MoneyUtils.fenToYuan @@ -40,7 +40,6 @@ import static cn.iocoder.yudao.framework.common.util.number.MoneyUtils.fenToYuan
40 import static cn.iocoder.yudao.module.pay.convert.wallet.PayWalletRechargeConvert.INSTANCE; 40 import static cn.iocoder.yudao.module.pay.convert.wallet.PayWalletRechargeConvert.INSTANCE;
41 import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.*; 41 import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.*;
42 import static cn.iocoder.yudao.module.pay.enums.MessageTemplateConstants.WALLET_RECHARGER_PAID; 42 import static cn.iocoder.yudao.module.pay.enums.MessageTemplateConstants.WALLET_RECHARGER_PAID;
43 -import static cn.iocoder.yudao.module.pay.enums.MessageTemplateConstants.WALLET_RECHARGE_REFUNDED;  
44 import static cn.iocoder.yudao.module.pay.enums.refund.PayRefundStatusEnum.*; 43 import static cn.iocoder.yudao.module.pay.enums.refund.PayRefundStatusEnum.*;
45 44
46 /** 45 /**
@@ -218,26 +217,6 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService { @@ -218,26 +217,6 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService {
218 } 217 }
219 // 3. 更新钱包充值的退款字段 218 // 3. 更新钱包充值的退款字段
220 walletRechargeMapper.updateByIdAndRefunded(id, WAITING.getStatus(), updateObj); 219 walletRechargeMapper.updateByIdAndRefunded(id, WAITING.getStatus(), updateObj);
221 -  
222 - // 4. 发送订阅消息  
223 - getSelf().sendWalletRechargeRefundedMessage(walletRecharge.getWalletId(), payRefund);  
224 - }  
225 -  
226 - @Async  
227 - public void sendWalletRechargeRefundedMessage(Long walletId, PayRefundDO payRefund) {  
228 - // 1. 获得会员钱包信息  
229 - PayWalletDO wallet = payWalletService.getWallet(walletId);  
230 - // 2. 构建并发送模版消息  
231 - String thing8 = PayRefundStatusEnum.isSuccess(payRefund.getStatus()) ? SUCCESS.getName() : FAILURE.getName();  
232 - socialClientApi.sendWxaSubscribeMessage(new SocialWxaSubscribeMessageSendReqDTO()  
233 - .setUserId(wallet.getUserId()).setUserType(wallet.getUserType())  
234 - .setTemplateTitle(WALLET_RECHARGE_REFUNDED)  
235 - .setPage("pages/user/wallet/money") // 钱包详情界面  
236 - .addMessage("character_string1", String.valueOf(payRefund.getId())) // 退款订单编号  
237 - .addMessage("time7", LocalDateTimeUtil.formatNormal(payRefund.getCreateTime())) // 申请时间  
238 - .addMessage("amount3", fenToYuanStr(payRefund.getRefundPrice())) // 退款金额  
239 - .addMessage("thing4", payRefund.getReason()) // 退款原因  
240 - .addMessage("thing8", thing8 + ",点击卡片查看详情")); // 温馨提示  
241 } 220 }
242 221
243 private PayRefundDO validateWalletRechargeCanRefunded(PayWalletRechargeDO walletRecharge, Long payRefundId) { 222 private PayRefundDO validateWalletRechargeCanRefunded(PayWalletRechargeDO walletRecharge, Long payRefundId) {