From 74f319a6573b64f920dcb5fe43b54f428da13116 Mon Sep 17 00:00:00 2001 From: jiangchao <281119120@qq.com> Date: Thu, 27 Mar 2025 11:00:07 +0800 Subject: [PATCH] =?UTF-8?q?##=20=E5=9C=A8=E7=BA=BF=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E5=9B=9E=E8=B0=83=E6=B7=BB=E5=8A=A0=E4=B8=8A=E9=94=81=E5=A4=84?= =?UTF-8?q?=E7=90=86=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/core/constant/CacheConstants.java | 5 +++++ .../pay/service/impl/PayServiceImpl.java | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/hzs-common/hzs-common-core/src/main/java/com/hzs/common/core/constant/CacheConstants.java b/hzs-common/hzs-common-core/src/main/java/com/hzs/common/core/constant/CacheConstants.java index ea0b4ffc..3adc68f5 100644 --- a/hzs-common/hzs-common-core/src/main/java/com/hzs/common/core/constant/CacheConstants.java +++ b/hzs-common/hzs-common-core/src/main/java/com/hzs/common/core/constant/CacheConstants.java @@ -475,4 +475,9 @@ public class CacheConstants { */ public final static String DELIVER_MERGE_KEY = CACHE_PREFIX + "deliver:merge"; + /** + * 在线支付回调上锁 + */ + public final static String ONLINE_PAYE_KEY = CACHE_PREFIX + "online:payment:"; + } diff --git a/hzs-third/src/main/java/com/hzs/third/pay/service/impl/PayServiceImpl.java b/hzs-third/src/main/java/com/hzs/third/pay/service/impl/PayServiceImpl.java index 6488280c..ecc0a590 100644 --- a/hzs-third/src/main/java/com/hzs/third/pay/service/impl/PayServiceImpl.java +++ b/hzs-third/src/main/java/com/hzs/third/pay/service/impl/PayServiceImpl.java @@ -1,10 +1,13 @@ package com.hzs.third.pay.service.impl; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.hzs.activity.base.IActivityServiceApi; +import com.hzs.common.core.constant.CacheConstants; import com.hzs.common.core.constant.MagicNumberConstants; import com.hzs.common.core.constant.RabbitMqConstants; import com.hzs.common.core.domain.R; import com.hzs.common.core.enums.*; +import com.hzs.common.core.service.RedisService; import com.hzs.common.domain.third.pay.TOnlinePayment; import com.hzs.member.account.IMemberTradeServiceApi; import com.hzs.sale.order.ISaOrderServiceApi; @@ -31,6 +34,8 @@ public class PayServiceImpl implements IPayService { private ITOnlinePaymentService itOnlinePaymentService; @Autowired private RabbitTemplate rabbitTemplate; + @Autowired + private RedisService redisService; @DubboReference ISaOrderServiceApi iSaOrderServiceApi; @@ -56,6 +61,9 @@ public class PayServiceImpl implements IPayService { public boolean notifyHandle(String businessType, String businessCode, String originalOrder, String payNumber, Date payTime, BigDecimal payMoney, EPayChannel ePayChannel, String channelNumber) { + Long pkId = null; + String redisKey = CacheConstants.ONLINE_PAYE_KEY + businessCode; + try { // 校验支付信息状态、业务与支付金额是否一致等 TOnlinePayment onlinePayment = itOnlinePaymentService.queryByBusiness(Integer.valueOf(businessType), businessCode, null); @@ -63,6 +71,7 @@ public class PayServiceImpl implements IPayService { log.error("支付信息不存在或已支付"); return false; } + pkId = onlinePayment.getPkId(); if (!PayUtil.checkAmount(onlinePayment.getBusinessMoney(), payMoney)) { // 业务金额 大于 实际支付金额 @@ -91,6 +100,17 @@ public class PayServiceImpl implements IPayService { } } catch (Exception e) { log.error("在线支付信息回调处理异常", e); + + if (null != pkId) { + // 更新业务处理信息 + itOnlinePaymentService.update(Wrappers.lambdaUpdate() + .eq(TOnlinePayment::getPkId, pkId) + .set(TOnlinePayment::getCallbackStatus, ECallbackStatus.FAIL.getValue()) + .set(TOnlinePayment::getCallbackInfo, e.getMessage()) + ); + } + } finally { + redisService.unlock(redisKey); } return false; }