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.HttpApi/LifePay/AliPayNotifyController.cs | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-) diff --git a/LifePayment/LifePayment.HttpApi/LifePay/AliPayNotifyController.cs b/LifePayment/LifePayment.HttpApi/LifePay/AliPayNotifyController.cs index 1dc7f00..3ecc609 100644 --- a/LifePayment/LifePayment.HttpApi/LifePay/AliPayNotifyController.cs +++ b/LifePayment/LifePayment.HttpApi/LifePay/AliPayNotifyController.cs @@ -2,6 +2,7 @@ using Castle.Core.Internal; using LifePayment.Application.Contracts; using LifePayment.Domain.Shared; +using Medallion.Threading; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; @@ -11,6 +12,7 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; using Volo.Abp.AspNetCore.Mvc; +using Volo.Abp.DistributedLocking; using Volo.Abp.Uow; using ZeroD.Util; @@ -27,15 +29,17 @@ private readonly ILifePayOrderService _lifePayOrderService; private readonly ILogger<AliPayNotifyController> _logger; + private readonly IAbpDistributedLock distributedLock; public AliPayNotifyController( ILogger<AliPayNotifyController> logger, - + IAbpDistributedLock distributedLock, ILifePayService lifePayService, ILifePayOrderService lifePayOrderService) { _logger = logger; + this.distributedLock = distributedLock; _lifePayService = lifePayService; _lifePayOrderService = lifePayOrderService; } @@ -61,6 +65,8 @@ { if (input.TradeStatus == LifePaymentConstant.AliPayStatus.鏀粯鎴愬姛 && input.OutBizNo.IsNullOrEmpty()) { + await using var orderLock = await distributedLock.TryAcquireAsync($"LockKey:UpdateOrder:{input.OutTradeNo}", TimeSpan.FromSeconds(60)); + await _lifePayService.LifePaySuccessHandler(input.OutTradeNo, input.TradeNo); // 鎻掑叆鏀舵敮娴佹按 await _lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput() @@ -75,6 +81,8 @@ && input.OutBizNo.IsNotNullOrEmpty() && (input.RefundFee.HasValue && input.RefundFee > 0))) { + await using var orderLock = await distributedLock.TryAcquireAsync($"LockKey:UpdateOrder:{input.OutTradeNo}", TimeSpan.FromSeconds(60)); + await _lifePayService.LifePayRefundsHandler(input.OutTradeNo, LifePayRefundStatusEnum.宸查��娆�); // 鎻掑叆鏀舵敮娴佹按 await _lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput() -- Gitblit v1.9.1