sunpengfei
2025-06-13 67fc39c356d8b480b7005cb2fa4769a0a6c6cfb1
pref:优化事务
4个文件已修改
33 ■■■■ 已修改文件
LifePayment/LifePayment.Application/LifePay/LifePayService.cs 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
LifePayment/LifePayment.HttpApi/LifePay/ACOOLYNotifyController.cs 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
LifePayment/LifePayment.HttpApi/LifePay/AliPayNotifyController.cs 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
LifePayment/LifePayment.HttpApi/LifePay/WxPayNotifyController.cs 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
LifePayment/LifePayment.Application/LifePay/LifePayService.cs
@@ -1533,7 +1533,8 @@
    {
        await using var orderLock = await distributedLock.TryAcquireAsync($"LockKey:UpdateOrder:{orderNo}", TimeSpan.FromSeconds(60));
        _logger.LogInformation($"锁:LockKey:UpdateOrder:{orderNo} - {orderLock != null}");
        try
        {
        var order = await _lifePayOrderRepository.Where(x => x.OrderNo == orderNo).FirstOrDefaultAsync();
        CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "订单不存在");
@@ -1608,7 +1609,15 @@
        await _lifePayOrderService.CreatLifePayConsumption(acoolyStatus, order.OrderNo, order.ACOOLYOrderNo,
                    order.PlatformDeductionAmount ?? 0, order.ChannelId, order.CreationTime, order.FinishTime, order.ChannleRate, parValue, actualParValue);
        await CurrentUnitOfWork.SaveChangesAsync();
            await CurrentUnitOfWork.CompleteAsync();
            _logger.LogInformation("事务完成");
        }
        catch (Exception ex)
        {
            await CurrentUnitOfWork.RollbackAsync();
            _logger.LogError($"供应商回调异常:{ex.Message}", ex);
        }
    }
    /// <summary>
LifePayment/LifePayment.HttpApi/LifePay/ACOOLYNotifyController.cs
@@ -41,6 +41,7 @@
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        [UnitOfWork(false)]
        public async Task ACOOLYNotify()
        {
            _logger.LogError("ACOOLY回调通知开始进入");
LifePayment/LifePayment.HttpApi/LifePay/AliPayNotifyController.cs
@@ -49,6 +49,7 @@
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [UnitOfWork(false)]
        public async Task<ContentResult> AliRechargeNotify()
        {
            _logger.LogError($"生活管家支付宝充值回调通知:进入支付宝回调");
@@ -65,6 +66,8 @@
            if (input.OutTradeNo.Contains("JF"))
            {
                try
                {
                if (input.TradeStatus == LifePaymentConstant.AliPayStatus.支付成功 && input.OutBizNo.IsNullOrEmpty())
                {
                    await _lifePayService.LifePaySuccessHandler(input.OutTradeNo, input.TradeNo);
@@ -77,6 +80,7 @@
                        ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Expenses
                    });
                    await CurrentUnitOfWork.SaveChangesAsync();
                        _logger.LogInformation("事务完成");
                }
                else if (((input.TradeStatus == LifePaymentConstant.AliPayStatus.支付成功 || input.TradeStatus == LifePaymentConstant.AliPayStatus.超时关闭)
                    && input.OutBizNo.IsNotNullOrEmpty()
@@ -92,7 +96,14 @@
                        LifePayType = LifePayTypeEnum.AliPay,
                        ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Receipts
                    });
                    await CurrentUnitOfWork.SaveChangesAsync();
                        await CurrentUnitOfWork.CompleteAsync();
                        _logger.LogInformation("事务完成");
                    }
                }
                catch (Exception ex)
                {
                    await CurrentUnitOfWork.RollbackAsync();
                    _logger.LogError($"支付宝支付回调异常:{ex.Message}", ex);
                }
            }
            else
LifePayment/LifePayment.HttpApi/LifePay/WxPayNotifyController.cs
@@ -53,6 +53,7 @@
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [UnitOfWork(false)]
        public async Task<WxRechargeNotifyResult> WxRechargeNotify(WxRechargeNotifyInput input)
        {
            try
@@ -94,7 +95,8 @@
                                AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10)
                            });
                            await CurrentUnitOfWork.SaveChangesAsync();
                            await CurrentUnitOfWork.CompleteAsync();
                            _logger.LogInformation("事务完成");
                        }
                        else
                        {
@@ -113,6 +115,8 @@
            }
            catch (Exception ex)
            {
                await CurrentUnitOfWork.RollbackAsync();
                _logger.LogError($"微信支付回调异常:{ex.Message}", ex);
                return new WxRechargeNotifyResult
                {
                    Code = "FAIL",