Commit 1f65dd2ec99192a99015963416a0a6914c0c2b33
Committed by
Gitee
!1027 【新增】MALL:拼团结果通知订阅消息
Merge pull request !1027 from puhui999/develop
Showing
5 changed files
with
40 additions
and
25 deletions
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/MessageTemplateConstants.java
0 → 100644
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 | 5 | import cn.hutool.extra.spring.SpringUtil; |
| 6 | 6 | import cn.iocoder.yudao.framework.common.core.KeyValue; |
| 7 | 7 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 8 | +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | |
| 8 | 9 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 9 | 10 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| 10 | 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 | 24 | import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; |
| 24 | 25 | import cn.iocoder.yudao.module.promotion.dal.mysql.combination.CombinationRecordMapper; |
| 25 | 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 | 29 | import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi; |
| 27 | 30 | import jakarta.annotation.Nullable; |
| 28 | 31 | import jakarta.annotation.Resource; |
| 29 | 32 | import lombok.extern.slf4j.Slf4j; |
| 30 | 33 | import org.springframework.context.annotation.Lazy; |
| 34 | +import org.springframework.scheduling.annotation.Async; | |
| 31 | 35 | import org.springframework.stereotype.Service; |
| 32 | 36 | import org.springframework.transaction.annotation.Transactional; |
| 33 | 37 | import org.springframework.validation.annotation.Validated; |
| ... | ... | @@ -40,6 +44,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. |
| 40 | 44 | import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.afterNow; |
| 41 | 45 | import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.beforeNow; |
| 42 | 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 | 49 | // TODO 芋艿:等拼团记录做完,完整 review 下 |
| 45 | 50 | |
| ... | ... | @@ -68,6 +73,8 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { |
| 68 | 73 | @Resource |
| 69 | 74 | @Lazy // 延迟加载,避免循环依赖 |
| 70 | 75 | private TradeOrderApi tradeOrderApi; |
| 76 | + @Resource | |
| 77 | + public SocialClientApi socialClientApi; | |
| 71 | 78 | |
| 72 | 79 | // TODO @芋艿:在详细预览下; |
| 73 | 80 | @Override |
| ... | ... | @@ -205,7 +212,25 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { |
| 205 | 212 | } |
| 206 | 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 | 236 | @Override | ... | ... |
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/MessageTemplateConstants.java
yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/MessageTemplateConstants.java
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 | 40 | import static cn.iocoder.yudao.module.pay.convert.wallet.PayWalletRechargeConvert.INSTANCE; |
| 41 | 41 | import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.*; |
| 42 | 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 | 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 | 217 | } |
| 219 | 218 | // 3. 更新钱包充值的退款字段 |
| 220 | 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 | 222 | private PayRefundDO validateWalletRechargeCanRefunded(PayWalletRechargeDO walletRecharge, Long payRefundId) { | ... | ... |