From a4ee4df71bc5320a8400b2794ff07d995cc875e3 Mon Sep 17 00:00:00 2001 From: zhenghao <1321288662@qq.com> Date: Wed, 9 Feb 2022 12:56:38 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E9=A2=84=E5=AD=98=E6=AC=BE?= =?UTF-8?q?=E4=BA=8B=E5=8A=A1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- framework/pom.xml | 6 +++++ .../kit/plugin/wallet/WalletPlugin.java | 22 +++++++++++++++---- pom.xml | 1 + 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/framework/pom.xml b/framework/pom.xml index 7b6af4cb..5990b777 100644 --- a/framework/pom.xml +++ b/framework/pom.xml @@ -143,6 +143,12 @@ jasypt-spring-boot-starter ${jasypt-version} + + + org.redisson + redisson + ${redisson} + com.aliyun diff --git a/framework/src/main/java/cn/lili/modules/payment/kit/plugin/wallet/WalletPlugin.java b/framework/src/main/java/cn/lili/modules/payment/kit/plugin/wallet/WalletPlugin.java index 56dad469..86c31727 100644 --- a/framework/src/main/java/cn/lili/modules/payment/kit/plugin/wallet/WalletPlugin.java +++ b/framework/src/main/java/cn/lili/modules/payment/kit/plugin/wallet/WalletPlugin.java @@ -19,6 +19,9 @@ import cn.lili.modules.wallet.entity.dto.MemberWalletUpdateDTO; import cn.lili.modules.wallet.entity.enums.DepositServiceTypeEnum; import cn.lili.modules.wallet.service.MemberWalletService; import lombok.extern.slf4j.Slf4j; +import org.redisson.Redisson; +import org.redisson.api.RLock; +import org.redisson.api.RedissonClient; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -57,9 +60,11 @@ public class WalletPlugin implements Payment { @Autowired private CashierSupport cashierSupport; + @Autowired + private RedissonClient redisson; + @Override public ResultMessage h5pay(HttpServletRequest request, HttpServletResponse response, PayParam payParam) { - savePaymentLog(payParam); return ResultUtil.success(ResultCode.PAY_SUCCESS); } @@ -113,9 +118,18 @@ public class WalletPlugin implements Payment { * @param payParam 支付参数 */ private void savePaymentLog(PayParam payParam) { - //获取支付收银参数 - CashierParam cashierParam = cashierSupport.cashierParam(payParam); - this.callBack(payParam, cashierParam); + //同一个会员如果在不同的客户端使用预存款支付,会存在同时支付,无法保证预存款的正确性,所以对会员加锁 + RLock lock = redisson.getLock(UserContext.getCurrentUser().getId() + ""); + lock.lock(); + try { + //获取支付收银参数 + CashierParam cashierParam = cashierSupport.cashierParam(payParam); + this.callBack(payParam, cashierParam); + } catch (Exception e) { + throw e; + } finally { + lock.unlock(); + } } @Override diff --git a/pom.xml b/pom.xml index 30e18428..003e84e7 100644 --- a/pom.xml +++ b/pom.xml @@ -29,6 +29,7 @@ 3.0.0 2.9.10 1.18.22 + 3.5.5 4.5.18 3.11.1 2.0.8