From e9609ce7d5896ed08ac416d92db0d3289a517a93 Mon Sep 17 00:00:00 2001 From: XinWei <2718030729@qq.com> Date: Tue, 22 Oct 2024 22:55:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=99=E9=A2=9D=E5=85=85=E5=80=BC=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1=E6=9C=AA=E6=94=AF=E4=BB=98=E6=97=B6=EF=BC=8C=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E5=A2=9E=E5=8A=A0=E4=BD=99=E9=A2=9D=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/order/PayOrderServiceImpl.java | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java index 6a6dbb9..c677372 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java @@ -7,6 +7,7 @@ import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; 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.dto.order.PayOrderRespDTO; import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; @@ -149,7 +150,17 @@ public class PayOrderServiceImpl implements PayOrderService { // 1.32 校验支付渠道是否有效 PayChannelDO channel = validateChannelCanSubmit(order.getAppId(), reqVO.getChannelCode()); PayClient client = channelService.getPayClient(channel.getId()); - + // 如果订单扩展里面已经存在该订单号的订单扩展(正在等待),则关闭已有的订单扩展,然后再创建(解决先点击微信支付,然后再使用余额支付会产生两个扩展订单的bug) + LambdaQueryWrapperX wrapperX = new LambdaQueryWrapperX<>(); + wrapperX.eq(PayOrderExtensionDO::getOrderId, order.getId()).eq(PayOrderExtensionDO::getStatus, PayOrderStatusEnum.WAITING.getStatus()); + List existOrderExtensionList = orderExtensionMapper.selectList(wrapperX); + if (existOrderExtensionList != null){ + // 考虑到这种重复的扩展订单一般就一个(最大值取决与支付方式个数),所以不使用批处理插入 + for (PayOrderExtensionDO payOrderExtensionDO : existOrderExtensionList) { + payOrderExtensionDO.setStatus(PayOrderStatusEnum.CLOSED.getStatus()); + orderExtensionMapper.updateById(payOrderExtensionDO); + } + } // 2. 插入 PayOrderExtensionDO String no = noRedisDAO.generate(payProperties.getOrderNoPrefix()); PayOrderExtensionDO orderExtension = PayOrderConvert.INSTANCE.convert(reqVO, userIp) @@ -262,13 +273,19 @@ public class PayOrderServiceImpl implements PayOrderService { PayChannelDO channel = channelService.validPayChannel(channelId); // 更新支付订单为已支付 TenantUtils.execute(channel.getTenantId(), () -> getSelf().notifyOrder(channel, notify)); + // 获取订单扩展 PayOrderExtensionDO payOrderExtensionDO = orderExtensionMapper.selectByNo(notify.getOutTradeNo()); - PayWalletRechargeDO walletRechargeDO = walletRechargeMapper.selectOne("pay_order_id", payOrderExtensionDO.getOrderId()); - if (walletRechargeDO != null){ - walletRechargeDO.setPayStatus(true); - walletRechargeDO.setPayTime(LocalDateTime.now()); - walletRechargeMapper.updateById(walletRechargeDO); - payWalletService.addWalletBalance(walletRechargeDO.getWalletId(),walletRechargeDO.getPayOrderId().toString(),RECHARGE,walletRechargeDO.getTotalPrice()); + // 判断订单是否更新为已支付 + if (Objects.equals(PayOrderStatusEnum.SUCCESS.getStatus(), orderMapper.selectById(payOrderExtensionDO.getOrderId()).getStatus())){ + + // 充值判断 + PayWalletRechargeDO walletRechargeDO = walletRechargeMapper.selectOne("pay_order_id", payOrderExtensionDO.getOrderId()); + if (walletRechargeDO != null){ + walletRechargeDO.setPayStatus(true); + walletRechargeDO.setPayTime(LocalDateTime.now()); + walletRechargeMapper.updateById(walletRechargeDO); + payWalletService.addWalletBalance(walletRechargeDO.getWalletId(),walletRechargeDO.getPayOrderId().toString(),RECHARGE,walletRechargeDO.getTotalPrice()); + } } }