sunpengfei
2025-06-13 6739e98662c16571da7aec0e9b52fab0afd3833b
LifePayment/LifePayment.Worker/Worker/CheckUnPayOrderWork.cs
@@ -6,16 +6,19 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Nest;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.BackgroundWorkers;
using Volo.Abp.DistributedLocking;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Threading;
using Volo.Abp.Uow;
using ZeroD.Util;
using ZeroD.Util.Fadd;
namespace LifePayment.Worker.Worker
{
@@ -23,20 +26,26 @@
    {
        private readonly int _doWorkHour = 0;
        private readonly int _doWorkMinute = 1;
        private readonly ILogger<CheckUnPayOrderWork> logger;
        private readonly ILifePayOrderService lifePayOrderService;
        private readonly ILifePayService lifePayService;
        private readonly IAbpDistributedLock distributedLock;
        private readonly IRepository<LifePayOrder, Guid> lifePayOrderRepository;
        public CheckUnPayOrderWork(
            AbpAsyncTimer timer,
            ILogger<CheckUnPayOrderWork> logger,
            IServiceScopeFactory serviceScopeFactory,
            ILifePayOrderService lifePayOrderService,
            ILifePayService lifePayService,
            IAbpDistributedLock distributedLock,
            IRepository<LifePayOrder, Guid> lifePayOrderRepository) : base(timer, serviceScopeFactory)
        {
            timer.Period = (int)TimeSpan.FromMinutes(10).TotalMilliseconds;
            timer.Period = (int)TimeSpan.FromMinutes(30).TotalMilliseconds;
            this.logger = logger;
            this.lifePayOrderService = lifePayOrderService;
            this.lifePayService = lifePayService;
            this.distributedLock = distributedLock;
            this.lifePayOrderRepository = lifePayOrderRepository;
        }
@@ -46,36 +55,40 @@
            try
            {
                Logger.LogInformation($"检查未支付订单状态开始: {DateTime.Now}");
                var end = DateTime.Now;
                var start = end.AddMinutes(-15);
                var orders = lifePayOrderRepository.Where(it => it.PayStatus == LifePayStatusEnum.未支付 && it.CreationTime >= start && it.CreationTime <= end).ToList();
                foreach (var order in orders)
                {
                    Logger.LogInformation($"订单:{order.OrderNo}-{order.ToJson()}");
                    //var wxPayNotice = await lifePayService.WxPayTradeQuery(order.OrderNo);
                    //var json = wxPayNotice.ToJson();
                    //Logger.LogInformation($"订单({wxPayNotice.OutTradeNo})信息: {json}");
                    //if (wxPayNotice.OutTradeNo.Contains("JF") && wxPayNotice.TradeState == LifePaymentConstant.WxPayStatus.支付成功)
                    //{
                    //    await lifePayService.LifePaySuccessHandler(wxPayNotice.OutTradeNo, wxPayNotice.TransactionId);
                //var end = DateTime.Now;
                //var start = end.AddMinutes(-45);
                //end = end.AddMinutes(-15);
                //var orders = lifePayOrderRepository.Where(it => it.PayStatus == LifePayStatusEnum.未支付 && it.CreationTime >= start && it.CreationTime <= end).ToList();
                //foreach (var order in orders)
                //{
                //    await using var orderLock = await distributedLock.TryAcquireAsync($"LockKey:UpdateOrder:{order.OrderNo}", TimeSpan.FromSeconds(60));
                //    logger.LogInformation($"锁:LockKey:UpdateOrder:{order.OrderNo} - {orderLock != null}");
                    //    // 插入收支流水
                    //    await lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput()
                    //    {
                    //        OrderNo = wxPayNotice.OutTradeNo,
                    //        OutOrderNo = wxPayNotice.TransactionId,
                    //        LifePayType = LifePayTypeEnum.WxPay,
                    //        ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Expenses,
                    //        Amount = wxPayNotice.Amount.Total
                    //    });
                //    Logger.LogInformation($"订单:{order.OrderNo}-{order.ToJson()}");
                //    var wxPayNotice = await lifePayService.WxPayTradeQuery(order.OrderNo);
                //    var json = wxPayNotice.ToJson();
                //    Logger.LogInformation($"订单({wxPayNotice.OutTradeNo})信息: {json}");
                //    if (wxPayNotice.OutTradeNo.Contains("JF") && wxPayNotice.TradeState == LifePaymentConstant.WxPayStatus.支付成功)
                //    {
                //        await lifePayService.LifePaySuccessHandler(wxPayNotice.OutTradeNo, wxPayNotice.TransactionId);
                    //    Logger.LogInformation("已改为支付成功");
                    //}
                    //else
                    //{
                    //    Logger.LogInformation("未更新");
                    //}
                }
                //        // 插入收支流水
                //        await lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput()
                //        {
                //            OrderNo = wxPayNotice.OutTradeNo,
                //            OutOrderNo = wxPayNotice.TransactionId,
                //            LifePayType = LifePayTypeEnum.WxPay,
                //            ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Expenses,
                //            Amount = wxPayNotice.Amount.Total
                //        });
                //        Logger.LogInformation("已改为支付成功");
                //    }
                //    else
                //    {
                //        Logger.LogInformation("未更新");
                //    }
                //}
            }
            catch (Exception ex)
            {