From 7a540f529d2c9a541993bc9818cad9c9093fec91 Mon Sep 17 00:00:00 2001
From: zhengyiming <540361168@qq.com>
Date: 星期三, 03 十二月 2025 11:04:35 +0800
Subject: [PATCH] fix: bug
---
LifePayment/LifePayment.HttpApi/LifePay/AliPayNotifyController.cs | 70 +++++++++++++++++++++++-----------
1 files changed, 47 insertions(+), 23 deletions(-)
diff --git a/LifePayment/LifePayment.HttpApi/LifePay/AliPayNotifyController.cs b/LifePayment/LifePayment.HttpApi/LifePay/AliPayNotifyController.cs
index e5b41c0..97c023c 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;
}
@@ -45,7 +49,7 @@
/// </summary>
/// <returns></returns>
[HttpPost]
- [UnitOfWork]
+ [UnitOfWork(false)]
public async Task<ContentResult> AliRechargeNotify()
{
_logger.LogError($"鐢熸椿绠″鏀粯瀹濆厖鍊煎洖璋冮�氱煡锛氳繘鍏ユ敮浠樺疂鍥炶皟");
@@ -57,34 +61,54 @@
//var serializeRequest = "{\"gmt_create\":\"2025-02-25 13:18:59\",\"charset\":\"UTF-8\",\"seller_email\":\"zfb1@818nb.com\",\"subject\":\"鐢熸椿缂磋垂-璇濊垂\",\"sign\":\"Sp06G1GxrAfDvoHPz9l3DJ20SxhvRzEGFeCGu4LHrSWmEG4OY7MHMx+iJi54ETbdXV0YsyDH9JZD7PWN3HCpEq/wGO4Wh4VSYSe7lqxD6r4f/HFiB0YlrdQoSzjZgYPzLjy6bcdlKRRHOeDkgs2i7TfvIsxWxHs9t0xuS0RlkpdZfb7d7m0EuZ/3v2Cbsj5AHjxb1S2PkO0oQyriYgGQdmkPqILZHwieST+tNEHS4dGFKYu2nkfctAGjWIDv/hKQNY7jEUxsEeG0SnK4TPU8zNplFR9/aKM0Wfwp1pdlaiP2u/d8vOtNh5q+emvaYbKrUkIEFBok8pDLNDta7ZjtVw==\",\"invoice_amount\":\"0.01\",\"buyer_open_id\":\"071xYXDfXBLAI9U11jg_WrH1K6hWq8HYGz0u85xBivf3Sce\",\"notify_id\":\"2025022501222131904087711494539601\",\"fund_bill_list\":\"[{\\\"amount\\\":\\\"0.01\\\",\\\"fundChannel\\\":\\\"ALIPAYACCOUNT\\\"}]\",\"notify_type\":\"trade_status_sync\",\"trade_status\":\"TRADE_SUCCESS\",\"receipt_amount\":\"0.01\",\"buyer_pay_amount\":\"0.01\",\"app_id\":\"2021004171602214\",\"sign_type\":\"RSA2\",\"seller_id\":\"2088050542042301\",\"gmt_payment\":\"2025-02-25 13:19:03\",\"notify_time\":\"2025-02-25 13:44:34\",\"merchant_app_id\":\"2021004171602214\",\"version\":\"1.0\",\"out_trade_no\":\"JF202502251318555214671\",\"total_amount\":\"0.01\",\"trade_no\":\"2025022522001487711401331043\",\"auth_app_id\":\"2021004171602214\",\"buyer_logon_id\":\"130****2238\",\"point_amount\":\"0.00\"}";
var input = JsonConvert.DeserializeObject<AliRechargeNotifyInput>(serializeRequest);
+ await using var orderLock = await distributedLock.TryAcquireAsync($"LockKey:UpdateOrder:{input.OutTradeNo}", TimeSpan.FromSeconds(60));
+ _logger.LogInformation($"閿侊細LockKey:UpdateOrder:{input.OutTradeNo} - {orderLock != null}");
+
if (input.OutTradeNo.Contains("JF"))
{
- if (input.TradeStatus == LifePaymentConstant.AliPayStatus.鏀粯鎴愬姛 && input.OutBizNo.IsNullOrEmpty())
+ try
{
- await _lifePayService.LifePaySuccessHandler(input.OutTradeNo, input.TradeNo);
- // 鎻掑叆鏀舵敮娴佹按
- await _lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput() { OrderNo = input.OutTradeNo,
- OutOrderNo = input.TradeNo ,LifePayType = LifePayTypeEnum.AliPay,ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Expenses,
- Amount = input.ReceiptAmount.Value });
- }
- else if((input.TradeStatus == LifePaymentConstant.AliPayStatus.鏀粯鎴愬姛 && input.OutBizNo.IsNotNullOrEmpty() && input.RefundFee.HasValue) ||
- input.TradeStatus == LifePaymentConstant.AliPayStatus.瓒呮椂鍏抽棴)
- {
- await _lifePayService.LifePayRefundsHandler(input.OutTradeNo, LifePayRefundStatusEnum.宸查��娆�);
- // 鎻掑叆鏀舵敮娴佹按
- await _lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput()
+ if (input.TradeStatus == LifePaymentConstant.AliPayStatus.鏀粯鎴愬姛 && input.OutBizNo.IsNullOrEmpty())
{
- OrderNo = input.OutTradeNo,
- OutOrderNo = input.TradeNo,
- LifePayType = LifePayTypeEnum.AliPay,
- ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Receipts,
- Amount = input.ReceiptAmount.Value
- });
+ await _lifePayService.LifePaySuccessHandler(input.OutTradeNo, input.TradeNo);
+ // 鎻掑叆鏀舵敮娴佹按
+ await _lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput()
+ {
+ OrderNo = input.OutTradeNo,
+ OutOrderNo = input.TradeNo,
+ LifePayType = LifePayTypeEnum.AliPay,
+ ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Expenses
+ });
+ await CurrentUnitOfWork.SaveChangesAsync();
+ _logger.LogInformation("浜嬪姟瀹屾垚");
+ }
+ else if (((input.TradeStatus == LifePaymentConstant.AliPayStatus.鏀粯鎴愬姛 || input.TradeStatus == LifePaymentConstant.AliPayStatus.瓒呮椂鍏抽棴)
+ && input.OutBizNo.IsNotNullOrEmpty()
+ && (input.RefundFee.HasValue && input.RefundFee > 0)))
+ {
+ 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
+ });
+ await CurrentUnitOfWork.SaveChangesAsync();
+ _logger.LogInformation("浜嬪姟瀹屾垚");
+ }
+ }
+ catch (Exception ex)
+ {
+ await CurrentUnitOfWork.RollbackAsync();
+ _logger.LogError($"鏀粯瀹濇敮浠樺洖璋冨紓甯革細{ex.Message}", ex);
}
}
else
{
- _logger.LogError($"鐢熸椿绠″鏀粯瀹濆厖鍊煎洖璋冮�氱煡锛氳鍗曞彿寮傚父 "+ input.OutTradeNo);
+ _logger.LogError($"鐢熸椿绠″鏀粯瀹濆厖鍊煎洖璋冮�氱煡锛氳鍗曞彿寮傚父 " + input.OutTradeNo);
}
return new ContentResult
@@ -115,7 +139,7 @@
}
-
+
#endif
/// <summary>
--
Gitblit v1.9.1