sunpengfei
2025-06-11 714eca49223a7eabdfc6666eb745c631d27046dc
LifePayment/LifePayment.HttpApi/LifePay/AliPayNotifyController.cs
@@ -1,6 +1,8 @@
using 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;
@@ -10,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
{
@@ -25,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;
        }
@@ -57,17 +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,
                        Amount = input.ReceiptAmount.Value });
                    // 插入收支流水
                    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
@@ -98,7 +130,7 @@
        }
#endif
        /// <summary>