diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/MessageTemplateConstants.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/MessageTemplateConstants.java new file mode 100644 index 000000000..83e6ecde8 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/MessageTemplateConstants.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.module.promotion.enums; + +/** + * 通知模板枚举类 + * + * @author HUIHUI + */ +public interface MessageTemplateConstants { + + //======================= 小程序订阅消息模版 ======================= + + String COMBINATION_RESULT = "拼团结果通知"; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java index 951285261..10022ad6c 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java +++ b/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; import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; @@ -23,11 +24,14 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationP import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; import cn.iocoder.yudao.module.promotion.dal.mysql.combination.CombinationRecordMapper; import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; +import cn.iocoder.yudao.module.system.api.social.SocialClientApi; +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxaSubscribeMessageSendReqDTO; import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi; import jakarta.annotation.Nullable; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Lazy; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -40,6 +44,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.afterNow; import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.beforeNow; import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; +import static cn.iocoder.yudao.module.promotion.enums.MessageTemplateConstants.COMBINATION_RESULT; // TODO 芋艿:等拼团记录做完,完整 review 下 @@ -68,6 +73,8 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { @Resource @Lazy // 延迟加载,避免循环依赖 private TradeOrderApi tradeOrderApi; + @Resource + public SocialClientApi socialClientApi; // TODO @芋艿:在详细预览下; @Override @@ -205,7 +212,25 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { } updateRecords.add(updateRecord); }); - combinationRecordMapper.updateBatch(updateRecords); + Boolean result = combinationRecordMapper.updateBatch(updateRecords); + + // 3. 拼团成功发送订阅消息 + if (result && isFull) { + records.forEach(item -> { + getSelf().sendCombinationResultMessage(item); + }); + } + } + + @Async + public void sendCombinationResultMessage(CombinationRecordDO record) { + // 构建并发送模版消息 + socialClientApi.sendWxaSubscribeMessage(new SocialWxaSubscribeMessageSendReqDTO() + .setUserId(record.getUserId()).setUserType(UserTypeEnum.MEMBER.getValue()) + .setTemplateTitle(COMBINATION_RESULT) + .setPage("pages/order/detail?id=" + record.getOrderId()) // 订单详情页 + .addMessage("thing1", "商品拼团活动") // 活动标题 + .addMessage("thing2", "恭喜您拼团成功!我们将尽快为您发货。")); // 温馨提示 } @Override diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/MessageTemplateConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/MessageTemplateConstants.java index 1bed7864d..195a9fde2 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/MessageTemplateConstants.java +++ b/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 { //======================= 小程序订阅消息模版 ======================= - String TRADE_AFTER_SALE_CHANGE = "售后进度通知"; String DELIVERY_ORDER = "订单发货通知"; } diff --git a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/MessageTemplateConstants.java b/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/MessageTemplateConstants.java index 5f2cf8965..b25d7645d 100644 --- a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/MessageTemplateConstants.java +++ b/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 { //======================= 小程序订阅消息 ======================= String WALLET_RECHARGER_PAID = "充值成功通知"; - // TODO @puhui999:这个放在售后那。aftersale - String WALLET_RECHARGE_REFUNDED = "退款申请通知"; } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java index 4414c8881..1d334d1b5 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java +++ b/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 import static cn.iocoder.yudao.module.pay.convert.wallet.PayWalletRechargeConvert.INSTANCE; import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.*; import static cn.iocoder.yudao.module.pay.enums.MessageTemplateConstants.WALLET_RECHARGER_PAID; -import static cn.iocoder.yudao.module.pay.enums.MessageTemplateConstants.WALLET_RECHARGE_REFUNDED; import static cn.iocoder.yudao.module.pay.enums.refund.PayRefundStatusEnum.*; /** @@ -218,26 +217,6 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService { } // 3. 更新钱包充值的退款字段 walletRechargeMapper.updateByIdAndRefunded(id, WAITING.getStatus(), updateObj); - - // 4. 发送订阅消息 - getSelf().sendWalletRechargeRefundedMessage(walletRecharge.getWalletId(), payRefund); - } - - @Async - public void sendWalletRechargeRefundedMessage(Long walletId, PayRefundDO payRefund) { - // 1. 获得会员钱包信息 - PayWalletDO wallet = payWalletService.getWallet(walletId); - // 2. 构建并发送模版消息 - String thing8 = PayRefundStatusEnum.isSuccess(payRefund.getStatus()) ? SUCCESS.getName() : FAILURE.getName(); - socialClientApi.sendWxaSubscribeMessage(new SocialWxaSubscribeMessageSendReqDTO() - .setUserId(wallet.getUserId()).setUserType(wallet.getUserType()) - .setTemplateTitle(WALLET_RECHARGE_REFUNDED) - .setPage("pages/user/wallet/money") // 钱包详情界面 - .addMessage("character_string1", String.valueOf(payRefund.getId())) // 退款订单编号 - .addMessage("time7", LocalDateTimeUtil.formatNormal(payRefund.getCreateTime())) // 申请时间 - .addMessage("amount3", fenToYuanStr(payRefund.getRefundPrice())) // 退款金额 - .addMessage("thing4", payRefund.getReason()) // 退款原因 - .addMessage("thing8", thing8 + ",点击卡片查看详情")); // 温馨提示 } private PayRefundDO validateWalletRechargeCanRefunded(PayWalletRechargeDO walletRecharge, Long payRefundId) {