sunpengfei
2025-11-19 7b47c91bcf89d667a5c99cfafe0d899280f7fbe3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using Furion;
using Furion.DatabaseAccessor;
using Furion.EventBus;
using Furion.Schedule;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
 
namespace ApiTools.Core
{
    /// <summary>
    /// 刷新渠道钱包交易状态
    /// </summary>
    [JobDetail("RefreshChannelWalletTransactionStatusJob", Description = "刷新渠道钱包交易状态", Concurrent = false)]
    [PeriodMinutes(5)]
    public class RefreshChannelWalletTransactionStatusJob(
            ChannelWalletRepository channelWalletRepository,
            ChannelWalletTransactionRepository channelWalletTransactionRepository,
            ChannelWalletService channelWalletService
        ) : IJob
    {
        private readonly ChannelWalletRepository channelWalletRepository = channelWalletRepository;
        private readonly ChannelWalletTransactionRepository channelWalletTransactionRepository = channelWalletTransactionRepository;
        private readonly ChannelWalletService channelWalletService = channelWalletService;
 
        public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
        {
            var env = App.GetConfig<string>("Environment");
            if (env != "Local")
            {
                var transactions = await channelWalletTransactionRepository.GetQueryable(false)
                .Where(it =>
                    it.TransactionStatus == EnumWalletTransactionStatus.WaitPay
                    || it.TransactionStatus == EnumWalletTransactionStatus.Dealing)
                .ToListAsync();
                var walletIds = transactions.DistinctSelect(it => it.WalletId);
                var wallets = await channelWalletRepository.GetQueryable(false)
                    .Where(it => walletIds.Contains(it.Id))
                    .ToListAsync();
                foreach (var transaction in transactions)
                {
                    var wallet = wallets.FirstOrDefault(it => it.Id == transaction.WalletId);
                    if (wallet != null)
                    {
                        // 查询交易详情
                        await channelWalletService.GetTransactionDetail(wallet, transaction);
                        // 下载回单
                        await channelWalletService.DownloadEreceiptUrl(wallet, transaction);
                    }
                }
            }
        }
    }
}