重复充值余额处理 #61

Merged
root merged 2 commits from cxw into master 2024-10-23 10:06:40 +08:00
Showing only changes of commit e9609ce7d5 - Show all commits

View File

@ -7,6 +7,7 @@ import cn.hutool.extra.spring.SpringUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; import cn.iocoder.yudao.framework.common.util.number.MoneyUtils;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.pay.core.client.PayClient; import cn.iocoder.yudao.framework.pay.core.client.PayClient;
import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO; import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO;
import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO;
@ -149,7 +150,17 @@ public class PayOrderServiceImpl implements PayOrderService {
// 1.32 校验支付渠道是否有效 // 1.32 校验支付渠道是否有效
PayChannelDO channel = validateChannelCanSubmit(order.getAppId(), reqVO.getChannelCode()); PayChannelDO channel = validateChannelCanSubmit(order.getAppId(), reqVO.getChannelCode());
PayClient client = channelService.getPayClient(channel.getId()); PayClient client = channelService.getPayClient(channel.getId());
// 如果订单扩展里面已经存在该订单号的订单扩展正在等待则关闭已有的订单扩展然后再创建解决先点击微信支付然后再使用余额支付会产生两个扩展订单的bug
LambdaQueryWrapperX<PayOrderExtensionDO> wrapperX = new LambdaQueryWrapperX<>();
wrapperX.eq(PayOrderExtensionDO::getOrderId, order.getId()).eq(PayOrderExtensionDO::getStatus, PayOrderStatusEnum.WAITING.getStatus());
List<PayOrderExtensionDO> existOrderExtensionList = orderExtensionMapper.selectList(wrapperX);
if (existOrderExtensionList != null){
// 考虑到这种重复的扩展订单一般就一个最大值取决与支付方式个数所以不使用批处理插入
for (PayOrderExtensionDO payOrderExtensionDO : existOrderExtensionList) {
payOrderExtensionDO.setStatus(PayOrderStatusEnum.CLOSED.getStatus());
orderExtensionMapper.updateById(payOrderExtensionDO);
}
}
// 2. 插入 PayOrderExtensionDO // 2. 插入 PayOrderExtensionDO
String no = noRedisDAO.generate(payProperties.getOrderNoPrefix()); String no = noRedisDAO.generate(payProperties.getOrderNoPrefix());
PayOrderExtensionDO orderExtension = PayOrderConvert.INSTANCE.convert(reqVO, userIp) PayOrderExtensionDO orderExtension = PayOrderConvert.INSTANCE.convert(reqVO, userIp)
@ -262,7 +273,12 @@ public class PayOrderServiceImpl implements PayOrderService {
PayChannelDO channel = channelService.validPayChannel(channelId); PayChannelDO channel = channelService.validPayChannel(channelId);
// 更新支付订单为已支付 // 更新支付订单为已支付
TenantUtils.execute(channel.getTenantId(), () -> getSelf().notifyOrder(channel, notify)); TenantUtils.execute(channel.getTenantId(), () -> getSelf().notifyOrder(channel, notify));
// 获取订单扩展
PayOrderExtensionDO payOrderExtensionDO = orderExtensionMapper.selectByNo(notify.getOutTradeNo()); PayOrderExtensionDO payOrderExtensionDO = orderExtensionMapper.selectByNo(notify.getOutTradeNo());
// 判断订单是否更新为已支付
if (Objects.equals(PayOrderStatusEnum.SUCCESS.getStatus(), orderMapper.selectById(payOrderExtensionDO.getOrderId()).getStatus())){
// 充值判断
PayWalletRechargeDO walletRechargeDO = walletRechargeMapper.selectOne("pay_order_id", payOrderExtensionDO.getOrderId()); PayWalletRechargeDO walletRechargeDO = walletRechargeMapper.selectOne("pay_order_id", payOrderExtensionDO.getOrderId());
if (walletRechargeDO != null){ if (walletRechargeDO != null){
walletRechargeDO.setPayStatus(true); walletRechargeDO.setPayStatus(true);
@ -271,6 +287,7 @@ public class PayOrderServiceImpl implements PayOrderService {
payWalletService.addWalletBalance(walletRechargeDO.getWalletId(),walletRechargeDO.getPayOrderId().toString(),RECHARGE,walletRechargeDO.getTotalPrice()); payWalletService.addWalletBalance(walletRechargeDO.getWalletId(),walletRechargeDO.getPayOrderId().toString(),RECHARGE,walletRechargeDO.getTotalPrice());
} }
} }
}
/** /**
* 通知并更新订单的支付结果 * 通知并更新订单的支付结果