From 32a1f6b1097bbb27730d681f65d1f36ecff0d029 Mon Sep 17 00:00:00 2001 From: khy <2908249413@qq.com> Date: Fri, 25 Oct 2024 11:23:03 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BC=9A=E5=91=98=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/order/AppTradeOrderController.java | 2 ++ .../member/TradePaidMemberUserService.java | 2 +- .../TradeTradePaidMemberUserServiceImpl.java | 8 +++++--- .../order/TradeOrderUpdateServiceImpl.java | 2 +- .../service/user/PaidMemberUserService.java | 2 +- .../service/user/PaidMemberUserServiceImpl.java | 8 +++++--- .../pay/service/order/PayOrderServiceImpl.java | 17 ----------------- 7 files changed, 15 insertions(+), 26 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java index b318e84..c8285e9 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java @@ -76,8 +76,10 @@ public class AppTradeOrderController { @Operation(summary = "更新订单为已支付") // 由 pay-module 支付服务,进行回调,可见 PayNotifyJob @PermitAll public CommonResult updateOrderPaid(@RequestBody PayOrderNotifyReqDTO notifyReqDTO) { + System.out.println("进入回调notify:"+ notifyReqDTO); tradeOrderUpdateService.updateOrderPaid(Long.valueOf(notifyReqDTO.getMerchantOrderId()), notifyReqDTO.getPayOrderId()); + System.out.println("订单更新完成"); return success(true); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/member/TradePaidMemberUserService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/member/TradePaidMemberUserService.java index 823c807..0a92857 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/member/TradePaidMemberUserService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/member/TradePaidMemberUserService.java @@ -32,6 +32,6 @@ public interface TradePaidMemberUserService { - TradePaidMemberUserDO getByIdAndPayOrderId(Long id, Long payOrderId); + TradePaidMemberUserDO getByPayOrderId(Long payOrderId); } \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/member/TradeTradePaidMemberUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/member/TradeTradePaidMemberUserServiceImpl.java index 34c5b17..6580529 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/member/TradeTradePaidMemberUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/member/TradeTradePaidMemberUserServiceImpl.java @@ -85,10 +85,12 @@ public class TradeTradePaidMemberUserServiceImpl implements TradePaidMemberUserS @Override - public TradePaidMemberUserDO getByIdAndPayOrderId(Long id, Long payOrderId) { + public TradePaidMemberUserDO getByPayOrderId(Long payOrderId) { TradePaidMemberUserDO tradePaidMemberUserDO = tradePaidMemberUserMapper.selectOne( - new LambdaQueryWrapperX().eqIfPresent(TradePaidMemberUserDO::getId,id) - .eqIfPresent(TradePaidMemberUserDO::getPayOrderId,payOrderId)); + new LambdaQueryWrapperX().eqIfPresent(TradePaidMemberUserDO::getPayOrderId,payOrderId)); + if (tradePaidMemberUserDO == null) { + throw exception(PAID_MEMBER_ORDER_NOT_EXISTS); + } return tradePaidMemberUserDO; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index 7c2e0c7..6f4821c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -337,7 +337,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { System.out.println("交易订单成功id:"+id+"和payOrderId:"+payOrderId); //会员用户信息,支付状态修改 TradeMemberUserDO tradeMemberUserDO = tradeMemberUserService.getUser(getLoginUserId()); - TradePaidMemberUserDO tradePaidMemberUserDO = tradePaidMemberUserService.getByIdAndPayOrderId(id,payOrderId); + TradePaidMemberUserDO tradePaidMemberUserDO = tradePaidMemberUserService.getByPayOrderId(payOrderId); if(tradePaidMemberUserDO != null && tradeMemberUserDO != null){ System.out.println("进入会员支付修改操作paid:"+tradePaidMemberUserDO+"和member:"+tradeMemberUserDO); tradePaidMemberUserDO.setPayTime(LocalDateTime.now()); diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/PaidMemberUserService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/PaidMemberUserService.java index 67ada52..6561e8b 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/PaidMemberUserService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/PaidMemberUserService.java @@ -84,6 +84,6 @@ public interface PaidMemberUserService { */ PageResult getMemberUserPage(PaidMemberUserPageReqVO pageReqVO); - PaidMemberUserDO getByIdAndPayOrderId(Long id,Long payOrderId); + PaidMemberUserDO getByPayOrderId(Long payOrderId); } \ No newline at end of file diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/PaidMemberUserServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/PaidMemberUserServiceImpl.java index b9fa2d1..256fbde 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/PaidMemberUserServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/PaidMemberUserServiceImpl.java @@ -186,10 +186,12 @@ public class PaidMemberUserServiceImpl implements PaidMemberUserService { } @Override - public PaidMemberUserDO getByIdAndPayOrderId(Long id, Long payOrderId) { + public PaidMemberUserDO getByPayOrderId(Long payOrderId) { PaidMemberUserDO paidMemberUserDO = paidMemberUserMapper.selectOne( - new LambdaQueryWrapperX().eqIfPresent(PaidMemberUserDO::getId,id) - .eqIfPresent(PaidMemberUserDO::getPayOrderId,payOrderId)); + new LambdaQueryWrapperX().eqIfPresent(PaidMemberUserDO::getPayOrderId,payOrderId)); + if(paidMemberUserDO == null){ + throw exception(PAID_MEMBER_ORDER_NOT_EXISTS); + } return paidMemberUserDO; } 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 8c76ad8..6011c8d 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 @@ -154,17 +154,6 @@ 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) @@ -277,12 +266,7 @@ public class PayOrderServiceImpl implements PayOrderService { PayChannelDO channel = channelService.validPayChannel(channelId); // 更新支付订单为已支付 TenantUtils.execute(channel.getTenantId(), () -> getSelf().notifyOrder(channel, notify)); - // 获取订单扩展 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()); if (walletRechargeDO != null){ walletRechargeDO.setPayStatus(true); @@ -291,7 +275,6 @@ public class PayOrderServiceImpl implements PayOrderService { payWalletService.addWalletBalance(walletRechargeDO.getWalletId(),walletRechargeDO.getPayOrderId().toString(),RECHARGE,walletRechargeDO.getTotalPrice()); } } - } /** * 通知并更新订单的支付结果 -- 2.45.2 From e650bab63b1637eb0a06e81c006b0e4a91feff95 Mon Sep 17 00:00:00 2001 From: khy <2908249413@qq.com> Date: Fri, 25 Oct 2024 11:26:32 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BC=9A=E5=91=98=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/trade/service/order/TradeOrderUpdateServiceImpl.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index 6f4821c..880d53a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -330,8 +330,10 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Transactional(rollbackFor = Exception.class) @TradeOrderLog(operateType = TradeOrderOperateTypeEnum.MEMBER_PAY) public void updateOrderPaid(Long id, Long payOrderId) { + System.out.println("进入校验"); // 1. 校验并获得交易订单(可支付) KeyValue orderResult = validateOrderPayable(id, payOrderId); + System.out.println("校验成功"); TradeOrderDO order = orderResult.getKey(); PayOrderRespDTO payOrder = orderResult.getValue(); System.out.println("交易订单成功id:"+id+"和payOrderId:"+payOrderId); -- 2.45.2