From 714eca49223a7eabdfc6666eb745c631d27046dc Mon Sep 17 00:00:00 2001 From: sunpengfei <i@angelzzz.com> Date: 星期三, 11 六月 2025 19:37:04 +0800 Subject: [PATCH] pref:锁日志 --- LifePayment/LifePayment.HttpApi/LifePay/AliPayNotifyController.cs | 51 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 46 insertions(+), 5 deletions(-) diff --git a/LifePayment/LifePayment.HttpApi/LifePay/AliPayNotifyController.cs b/LifePayment/LifePayment.HttpApi/LifePay/AliPayNotifyController.cs index 3d41c9c..be0fd5a 100644 --- a/LifePayment/LifePayment.HttpApi/LifePay/AliPayNotifyController.cs +++ b/LifePayment/LifePayment.HttpApi/LifePay/AliPayNotifyController.cs @@ -1,5 +1,8 @@ -锘縰sing LifePayment.Application.Contracts; +锘縰sing Alipay.AopSdk.F2FPay.Model; +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; @@ -9,7 +12,9 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; using Volo.Abp.AspNetCore.Mvc; +using Volo.Abp.DistributedLocking; using Volo.Abp.Uow; +using ZeroD.Util; namespace LifePayment.HttpApi { @@ -21,17 +26,22 @@ { private readonly ILifePayService _lifePayService; + private readonly ILifePayOrderService _lifePayOrderService; private readonly ILogger<AliPayNotifyController> _logger; + private readonly IAbpDistributedLock distributedLock; public AliPayNotifyController( ILogger<AliPayNotifyController> logger, - - ILifePayService lifePayService) + IAbpDistributedLock distributedLock, + ILifePayService lifePayService, + ILifePayOrderService lifePayOrderService) { _logger = logger; + this.distributedLock = distributedLock; _lifePayService = lifePayService; + _lifePayOrderService = lifePayOrderService; } /// <summary> @@ -53,14 +63,43 @@ if (input.OutTradeNo.Contains("JF")) { - if (input.TradeStatus == LifePaymentConstant.AliPayStatus.鏀粯鎴愬姛) + if (input.TradeStatus == LifePaymentConstant.AliPayStatus.鏀粯鎴愬姛 && input.OutBizNo.IsNullOrEmpty()) { + await using var orderLock = await distributedLock.TryAcquireAsync($"LockKey:UpdateOrder:{input.OutTradeNo}", TimeSpan.FromSeconds(60)); + _logger.LogInformation($"閿侊細LockKey:UpdateOrder:{input.OutTradeNo} - {orderLock != null}"); + await _lifePayService.LifePaySuccessHandler(input.OutTradeNo, input.TradeNo); + // 鎻掑叆鏀舵敮娴佹按 + await _lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput() + { + OrderNo = input.OutTradeNo, + OutOrderNo = input.TradeNo, + LifePayType = LifePayTypeEnum.AliPay, + ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Expenses + }); + } + else if (((input.TradeStatus == LifePaymentConstant.AliPayStatus.鏀粯鎴愬姛 || input.TradeStatus == LifePaymentConstant.AliPayStatus.瓒呮椂鍏抽棴) + && input.OutBizNo.IsNotNullOrEmpty() + && (input.RefundFee.HasValue && input.RefundFee > 0))) + { + await using var orderLock = await distributedLock.TryAcquireAsync($"LockKey:UpdateOrder:{input.OutTradeNo}", TimeSpan.FromSeconds(60)); + _logger.LogInformation($"閿侊細LockKey:UpdateOrder:{input.OutTradeNo} - {orderLock != null}"); + + await _lifePayService.LifePayRefundsHandler(input.OutTradeNo, LifePayRefundStatusEnum.宸查��娆�); + // 鎻掑叆鏀舵敮娴佹按 + await _lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput() + { + OrderNo = input.OutTradeNo, + OutRefundNo = input.OutBizNo, + OutOrderNo = input.TradeNo, + LifePayType = LifePayTypeEnum.AliPay, + ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Receipts + }); } } else { - _logger.LogError($"鐢熸椿绠″鏀粯瀹濆厖鍊煎洖璋冮�氱煡锛氳鍗曞彿寮傚父 "+ input.OutTradeNo); + _logger.LogError($"鐢熸椿绠″鏀粯瀹濆厖鍊煎洖璋冮�氱煡锛氳鍗曞彿寮傚父 " + input.OutTradeNo); } return new ContentResult @@ -90,6 +129,8 @@ }; } + + #endif /// <summary> -- Gitblit v1.9.1