From 1605af1ced748313e99f38e5eb6888768fbc7d54 Mon Sep 17 00:00:00 2001 From: sunpengfei <i@angelzzz.com> Date: 星期三, 11 六月 2025 14:46:43 +0800 Subject: [PATCH] fix:支付回调和供应商回调的并发问题 --- LifePayment/LifePayment.Application/LifePay/LifePayService.cs | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-) diff --git a/LifePayment/LifePayment.Application/LifePay/LifePayService.cs b/LifePayment/LifePayment.Application/LifePay/LifePayService.cs index c2774a8..5581eb3 100644 --- a/LifePayment/LifePayment.Application/LifePay/LifePayService.cs +++ b/LifePayment/LifePayment.Application/LifePay/LifePayService.cs @@ -18,6 +18,7 @@ using Volo.Abp; using Volo.Abp.Application.Services; using Volo.Abp.Data; +using Volo.Abp.DistributedLocking; using Volo.Abp.Domain.Repositories; using Volo.Abp.EventBus.Distributed; using Z.EntityFramework.Plus; @@ -44,6 +45,7 @@ private readonly ILifePayOrderService _lifePayOrderService; private readonly IDataFilter dataFilter; private readonly IChannelFilter _channelFilter; + private readonly IAbpDistributedLock distributedLock; private readonly IAliPayApi _aliPayApi; private readonly IAlipayInterfaceManager _alipayInterfaceManager; private readonly IWxPayApi _wxPayApi; @@ -73,7 +75,8 @@ IRepository<LifePayChannles, Guid> lifePayChannlesRep, IRepository<LifePayAccount, Guid> lifePayAccount, IDataFilter dataFilter, - IChannelFilter channelFilter) + IChannelFilter channelFilter, + IAbpDistributedLock distributedLock) { _logger = logger; _aCOOLYManager = aCOOLYManager; @@ -95,6 +98,7 @@ _lifePayAccount = lifePayAccount; this.dataFilter = dataFilter; _channelFilter = channelFilter; + this.distributedLock = distributedLock; _operateHistory = operateHistory; } @@ -1528,8 +1532,11 @@ public async Task ACOOLYOrderNotifyHandler(string orderNo, string acoolyOrderNo, LifePayOrderStatusEnum status, ACOOLYStatusEnum acoolyStatus, decimal payAmount, string refundApplyRemark, decimal? parValue = 0, decimal? actualParValue = 0) { var order = await _lifePayOrderRepository.Where(x => x.OrderNo == orderNo).FirstOrDefaultAsync(); + CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "璁㈠崟涓嶅瓨鍦�"); + await using var orderLock = await distributedLock.TryAcquireAsync($"LockKey:UpdateOrder:{orderNo}", TimeSpan.FromSeconds(60)); + if (order.ACOOLYStatus.HasValue && (int)order.ACOOLYStatus > (int)acoolyStatus) { _logger.LogInformation($"璁㈠崟锛坽orderNo}锛夌敱{order.ACOOLYStatus}鑷硔acoolyStatus}澶辫触锛屼笉鍙洖婊氱姸鎬�"); -- Gitblit v1.9.1