From bfd823a681cdc2d86a8af398e50a9c151cb41aac Mon Sep 17 00:00:00 2001
From: zhengyuxuan <zhengyuxuan1995>
Date: 星期四, 03 四月 2025 13:39:26 +0800
Subject: [PATCH] 暂存

---
 LifePayment/LifePayment.Application/LifePay/StatisticsService.cs |  359 +++++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 299 insertions(+), 60 deletions(-)

diff --git a/LifePayment/LifePayment.Application/LifePay/StatisticsService.cs b/LifePayment/LifePayment.Application/LifePay/StatisticsService.cs
index f6fec66..fb39436 100644
--- a/LifePayment/LifePayment.Application/LifePay/StatisticsService.cs
+++ b/LifePayment/LifePayment.Application/LifePay/StatisticsService.cs
@@ -16,6 +16,11 @@
 using Volo.Abp.EventBus.Distributed;
 using static Nest.FileSystemStats;
 using Microsoft.EntityFrameworkCore;
+using System.Threading.Channels;
+using ZeroD.Util;
+using NPOI.SS.Formula.Functions;
+using System.Security.Principal;
+using StackExchange.Redis;
 
 namespace LifePayment.Application.LifePay
 {
@@ -24,91 +29,325 @@
         private readonly IRepository<LifePayOrder, Guid> _lifePayOrderRepository;
         private readonly IRepository<LifePayUser, Guid> _lifePayUserRepository;
         private readonly IRepository<DallyStatistics, Guid> _dallyStatisticsRepository;
+        private readonly IRepository<LifePayChannlesRake, Guid> _lifePayChannlesRakeRepository;
+        private readonly IRepository<LifePayRechargeReceipts, Guid> _lifePayRechargeReceiptsRepository;
+        private readonly IRepository<LifePayChannles, Guid> _lifePayChannlesRep;
 
         public StatisticsService(
                               IRepository<LifePayOrder, Guid> lifePayOrderRepository,
                               IRepository<LifePayUser, Guid> lifePayUserRepository,
-                            IRepository<DallyStatistics, Guid> dallyStatisticsRepository)
+                                IRepository<DallyStatistics, Guid> dallyStatisticsRepository,
+                                IRepository<LifePayChannlesRake, Guid> lifePayChannlesRakeRepository,
+                                IRepository<LifePayRechargeReceipts, Guid> lifePayRechargeReceiptsRepository,
+                                IRepository<LifePayChannles, Guid> lifePayChannlesRep)
         {
             _lifePayOrderRepository = lifePayOrderRepository;
             _lifePayUserRepository = lifePayUserRepository;
             _dallyStatisticsRepository = dallyStatisticsRepository;
+            _lifePayChannlesRakeRepository = lifePayChannlesRakeRepository;
+            _lifePayRechargeReceiptsRepository = lifePayRechargeReceiptsRepository;
+            _lifePayChannlesRep = lifePayChannlesRep;
         }
 
-        public async Task<TopStatisticsOutput> GetTopStatistics()
+        /// <summary>
+        /// 椤堕儴缁熻
+        /// </summary>
+        /// <param name="channleId"></param>
+        /// <returns></returns>
+        public async Task<TopStatisticsOutput> GetTopStatistics(List<string> channleList)
         {
             var today = DateTime.Now.Date;
-            var statistics = await _dallyStatisticsRepository.Where(x => x.CreationTime.Date == today).FirstOrDefaultAsync();
-            if (statistics == null)
+            var statistics = await _dallyStatisticsRepository.Where(x => x.CreationTime.Date == today)
+                .WhereIf(channleList.Count() > 0, x => channleList.Contains(x.ChannelId))
+                .ToListAsync();
+            var totalRechargeReceipts = await _lifePayRechargeReceiptsRepository.Where(x => x.CreationTime < today).SumAsync(x => x.RechargeAmount);
+            if (statistics == null || statistics.Count() == 0)
             {
-                /// 绱鏀舵锛氱粺璁″钩鍙拌处鎴蜂笅璁㈠崟鍒涘缓鏃堕棿鍦ㄦ槰澶╁強涔嬪墠鏀跺埌鐨勩�愮敤鎴锋敮浠樻垚鍔熺殑閲戦-閫�娆剧粰鐢ㄦ埛鐨勯噾棰濄�戯紱
-                var accumulatedReceipts = await _lifePayOrderRepository.Where(x => x.CreationTime < today && x.PayStatus != LifePayStatusEnum.鏈敮浠�).SumAsync(x => x.PayAmount) - await _lifePayOrderRepository.Where(x => x.CreationTime < today && x.LifePayRefundStatus == LifePayRefundStatusEnum.宸查��娆�).SumAsync(x => (x.RefundPrice ?? 0));
-                /// 鏄ㄦ棩鏀舵锛氱粺璁″钩鍙拌处鎴蜂笅璁㈠崟鍒涘缓鏃堕棿鍦ㄦ槰澶╂敹鍒扮殑銆愮敤鎴锋敮浠樻垚鍔熺殑閲戦-閫�娆剧粰鐢ㄦ埛鐨勯噾棰濄�戯紱
-                var receiptsYesterday = await _lifePayOrderRepository.Where(x => x.CreationTime >= today.AddDays(-1) && x.CreationTime < today && x.PayStatus == LifePayStatusEnum.宸叉敮浠�).SumAsync(x => x.PayAmount) - await _lifePayOrderRepository.Where(x => x.CreationTime >= today.AddDays(-1) && x.CreationTime < today && x.LifePayRefundStatus == LifePayRefundStatusEnum.宸查��娆�).SumAsync(x => (x.RefundPrice ?? 0));
-                /// 绱鏀跺叆锛氱粺璁″钩鍙拌处鎴蜂笅璁㈠崟鐘舵�佷负鈥滃凡瀹屾垚鈥濅笖璁㈠崟鍒涘缓鏃堕棿鍦ㄦ槰澶╁強涔嬪墠鏀跺埌鐨勩�愮敤鎴峰疄浠橀噾棰�-骞冲彴鎵f閲戦-閮ㄥ垎閫�娆鹃噾棰濄�戯紱
-                var accumulatedIncome = await _lifePayOrderRepository.Where(x => x.CreationTime < today && x.LifePayOrderStatus == LifePayOrderStatusEnum.宸插畬鎴�).SumAsync(x => x.PayAmount - (x.PlatformDeductionAmount ?? 0) - (x.RefundPrice ?? 0));
-                /// 绱涓嬪崟锛氱粺璁″钩鍙颁腑璁㈠崟涓嬪崟鏃堕棿鍦ㄦ槰澶╁強涔嬪墠鏃堕棿鐨勮鍗曡褰曪紱
-                var accumulatedOrders = await _lifePayOrderRepository.Where(x => x.CreationTime < today).CountAsync();
-                /// 鏄ㄦ棩涓嬪崟锛氱粺璁″钩鍙颁腑璁㈠崟涓嬪崟鏃堕棿鍦ㄦ槰澶╃殑璁㈠崟璁板綍锛�
-                var ordersNumYesterday = await _lifePayOrderRepository.Where(x => x.CreationTime >= today.AddDays(-1) && x.CreationTime < today).CountAsync();
-                /// 鏄ㄦ棩鎴愬姛锛氱粺璁″钩鍙颁腑璁㈠崟鐘舵�佷负鈥滃凡瀹屾垚/閮ㄥ垎鍏呭�兼垚鍔熲�濅笖璁㈠崟涓嬪崟鏃堕棿鍦ㄦ槰澶╃殑璁㈠崟璁板綍锛�
-                var yesterdaySuccess = await _lifePayOrderRepository.Where(x => x.CreationTime >= today.AddDays(-1) && x.CreationTime < today && x.LifePayOrderStatus == LifePayOrderStatusEnum.宸插畬鎴�).CountAsync();
-                /// 鏄ㄦ棩澶辫触锛氱粺璁″钩鍙颁腑璁㈠崟鐘舵�佷负鈥滃厖鍊煎け璐�/宸查��娆锯�濅笖璁㈠崟涓嬪崟鏃堕棿鍦ㄦ槰澶╃殑璁㈠崟璁板綍锛�
-                var yesterdayFail = await _lifePayOrderRepository.Where(x => x.CreationTime >= today.AddDays(-1) && x.CreationTime < today && x.LifePayOrderStatus == LifePayOrderStatusEnum.宸查��娆�).CountAsync();
-                /// 绱鐢ㄦ埛
-                var accumulatedUsers = await _lifePayUserRepository.CountAsync();
-                /// 鏄ㄦ棩娲昏穬鐢ㄦ埛
-                var yesterdayActiveUsers = await _lifePayUserRepository.Where(x => x.LastLoginTime >= today.AddDays(-1)).CountAsync();
-
-                var entity = new DallyStatistics()
+                TopStatisticsOutput topStatisticsOutput = new TopStatisticsOutput() { };
+                var allChannle = await _lifePayChannlesRep.ToListAsync();
+                foreach (var item in allChannle)
                 {
-                    Id = GuidGenerator.Create(),
-                    CreationTime = DateTime.Now,
-                    Amount = 0,
-                    AccumulatedReceipts = accumulatedReceipts??0,
-                    AccumulatedIncome = accumulatedIncome ?? 0,
-                    ReceiptsYesterday = receiptsYesterday ?? 0,
-                    AccumulatedOrders = accumulatedOrders,
-                    OrdersNumYesterday = ordersNumYesterday,
-                    YesterdaySuccess = yesterdaySuccess,
-                    YesterdayFail = yesterdayFail,
-                    AccumulatedUsers = accumulatedUsers,
-                    YesterdayActiveUsers = yesterdayActiveUsers
-                };
-                await _dallyStatisticsRepository.InsertAsync(entity);
+                    var entity = await TopStatistics(item.ChannlesNum, today);
+                    if (channleList.Count() == 0 || channleList.Contains(item.ChannlesNum))
+                    {
+                        topStatisticsOutput.AccumulatedReceipts += entity.AccumulatedReceipts;
+                        topStatisticsOutput.AccumulatedIncome += entity.AccumulatedIncome;
+                        topStatisticsOutput.ReceiptsYesterday += entity.ReceiptsYesterday;
+                        topStatisticsOutput.AccumulatedOrders += entity.AccumulatedOrders;
+                        topStatisticsOutput.OrdersNumYesterday += entity.OrdersNumYesterday;
+                        topStatisticsOutput.YesterdaySuccess += entity.YesterdaySuccess;
+                        topStatisticsOutput.YesterdayFail += entity.YesterdayFail;
+                        topStatisticsOutput.AccumulatedUsers += entity.AccumulatedUsers;
+                        topStatisticsOutput.YesterdayActiveUsers += entity.YesterdayActiveUsers;
+                        topStatisticsOutput.AccumulatedChannlesRakePrice += entity.AccumulatedChannlesRakePrice;
+                    }
+                }
 
-                TopStatisticsOutput topStatisticsOutput = new TopStatisticsOutput()
+                if (channleList.Count() == 0)
                 {
-                    Amount = entity.Amount,
-                    AccumulatedReceipts = entity.AccumulatedReceipts,
-                    AccumulatedIncome = entity.AccumulatedIncome,
-                    ReceiptsYesterday = entity.ReceiptsYesterday,
-                    AccumulatedOrders = entity.AccumulatedOrders,
-                    OrdersNumYesterday = entity.OrdersNumYesterday,
-                    YesterdaySuccess = entity.YesterdaySuccess,
-                    YesterdayFail = entity.YesterdayFail,
-                    AccumulatedUsers = entity.AccumulatedUsers,
-                    YesterdayActiveUsers = entity.YesterdayActiveUsers,
-                };
+                    /// 璐︽埛浣欓
+                    topStatisticsOutput.Amount = totalRechargeReceipts - await _lifePayOrderRepository.Where(x => x.ACOOLYStatus == ACOOLYStatusEnum.鍏呭�兼垚鍔� || x.ACOOLYStatus == ACOOLYStatusEnum.宸插畬鎴� || x.ACOOLYStatus == ACOOLYStatusEnum.閮ㄥ垎鍏呭�兼垚鍔�)
+                      .SumAsync(x => x.PlatformDeductionAmount) ?? 0;
+                }
+
                 return topStatisticsOutput;
             }
             else
             {
                 TopStatisticsOutput topStatisticsOutput = new TopStatisticsOutput()
                 {
-                    Amount = statistics.Amount,
-                    AccumulatedReceipts = statistics.AccumulatedReceipts,
-                    AccumulatedIncome = statistics.AccumulatedIncome,
-                    ReceiptsYesterday = statistics.ReceiptsYesterday,
-                    AccumulatedOrders = statistics.AccumulatedOrders,
-                    OrdersNumYesterday = statistics.OrdersNumYesterday,
-                    YesterdaySuccess = statistics.YesterdaySuccess,
-                    YesterdayFail = statistics.YesterdayFail,
-                    AccumulatedUsers = statistics.AccumulatedUsers,
-                    YesterdayActiveUsers = statistics.YesterdayActiveUsers,
+                    AccumulatedReceipts = statistics.Sum(s => s.AccumulatedReceipts),
+                    AccumulatedIncome = statistics.Sum(s => s.AccumulatedIncome),
+                    ReceiptsYesterday = statistics.Sum(s => s.ReceiptsYesterday),
+                    AccumulatedOrders = statistics.Sum(s => s.AccumulatedOrders),
+                    OrdersNumYesterday = statistics.Sum(s => s.OrdersNumYesterday),
+                    YesterdaySuccess = statistics.Sum(s => s.YesterdaySuccess),
+                    YesterdayFail = statistics.Sum(s => s.YesterdayFail),
+                    AccumulatedUsers = statistics.Sum(s => s.AccumulatedUsers),
+                    YesterdayActiveUsers = statistics.Sum(s => s.YesterdayActiveUsers),
+                    AccumulatedChannlesRakePrice = statistics.Sum(s => s.AccumulatedChannlesRakePrice)
                 };
+                if (channleList.Count() == 0)
+                {
+                    /// 璐︽埛浣欓
+                    topStatisticsOutput.Amount = totalRechargeReceipts - await _lifePayOrderRepository.Where(x => x.ACOOLYStatus == ACOOLYStatusEnum.鍏呭�兼垚鍔� || x.ACOOLYStatus == ACOOLYStatusEnum.宸插畬鎴� || x.ACOOLYStatus == ACOOLYStatusEnum.閮ㄥ垎鍏呭�兼垚鍔�)
+                      .SumAsync(x => x.PlatformDeductionAmount) ?? 0;
+                }
+
                 return topStatisticsOutput;
             }
         }
+
+        /// <summary>
+        /// 杩�30鏃ユ敹娆炬暟鎹�
+        /// </summary>
+        /// <param name="channleList"></param>
+        /// <returns></returns>
+        public async Task<ReceiptsListOutPut> GetReceiptsList(List<string> channleList)
+        {
+            var today = DateTime.Now.Date;
+            var statistics = await _dallyStatisticsRepository.Where(x => x.CreationTime.Date <= today && x.CreationTime.Date >= today.AddDays(-30))
+                .WhereIf(channleList.Count() > 0, x => channleList.Contains(x.ChannelId))
+                .OrderBy(o => o.CreationTime)
+                .ToListAsync();
+            CheckExtensions.IfTrueThrowUserFriendlyException(statistics == null, "鏀舵缁熻澶辫触");
+            var groupedStatistics = statistics
+                .GroupBy(x => x.CreationTime)
+                .Select(g => new
+                {
+                    CreationTime = g.Key,
+                    TotalReceiptsYesterday = g.Sum(x => x.ReceiptsYesterday),
+                    TotalIncomeYesterday = g.Sum(x => x.IncomeYesterday)
+                })
+                .ToList();
+            ReceiptsListOutPut receiptsListOutPut = new ReceiptsListOutPut();
+
+            foreach (var item in groupedStatistics)
+            {
+                /// 瀹為檯鏀舵鏃ユ湡
+                var creationTime = item.CreationTime.AddDays(-1).ToString("yyyy-MM-dd");
+                ReceiptsDetail receive = new ReceiptsDetail()
+                {
+                    CreationTime = creationTime,
+                    Amount = item.TotalReceiptsYesterday
+                };
+                ReceiptsDetail income = new ReceiptsDetail()
+                {
+                    CreationTime = creationTime,
+                    Amount = item.TotalIncomeYesterday
+                };
+                receiptsListOutPut.ReceiveList.Add(receive);
+                receiptsListOutPut.IncomeList.Add(income);
+            }
+
+            return receiptsListOutPut;
+        }
+
+        /// <summary>
+        /// 鑾峰彇30澶╀剑閲�
+        /// </summary>
+        /// <param name="channleList"></param>
+        /// <returns></returns>
+        public async Task<ChannlesRakeListOutPut> GetChannlesRakeList(List<string> channleList)
+        {
+            var today = DateTime.Now.Date;
+            var statistics = await _lifePayChannlesRakeRepository.Where(x => x.FinishTime.Date <= today && x.FinishTime.Date >= today.AddDays(-30))
+                            .WhereIf(channleList.Count() > 0, x => channleList.Contains(x.ChannelId))
+                            .ToListAsync();
+            CheckExtensions.IfTrueThrowUserFriendlyException(statistics == null, "浣i噾缁熻澶辫触");
+            var groupedStatistics = statistics
+               .GroupBy(x => x.FinishTime.ToString("yyyy-MM-dd"))
+               .Select(g => new
+               {
+                   FinishTime = g.Key,
+                   ChannlesRakePrice = g.Sum(x => x.ChannlesRakePrice),
+               })
+               .ToList();
+
+            ChannlesRakeListOutPut channlesRakeListOutPut = new ChannlesRakeListOutPut();
+
+            foreach (var item in groupedStatistics)
+            {
+                ReceiptsDetail receive = new ReceiptsDetail()
+                {
+                    CreationTime = item.FinishTime,
+                    Amount = item.ChannlesRakePrice
+                };
+                channlesRakeListOutPut.ChannlesRakeList.Add(receive);
+            }
+
+            return channlesRakeListOutPut;
+        }
+
+        public async Task<ChannelDataListOutPut> GetChannelDataList(List<string> channleList)
+        {
+            int maxStatisticsNumber = 5;
+            var statistics = await _lifePayChannlesRakeRepository
+                            .WhereIf(channleList != null && channleList.Count() > 0, x => channleList.Contains(x.ChannelId))
+            .ToListAsync();
+            CheckExtensions.IfTrueThrowUserFriendlyException(statistics == null, "娓犻亾鏀舵缁熻澶辫触");
+            var groupedStatistics = statistics
+               .GroupBy(x => x.ChannelId)
+               .Select(g => new
+               {
+                   ChannelId = g.Key,
+                   ReceivePrice = g.Sum(x => x.PayAmount),
+                   ChannlesRakePrice = g.Sum(x => x.ChannlesRakePrice),
+               })
+               .OrderByDescending(o => o.ReceivePrice)
+               .ToList();
+
+            ChannelDataListOutPut channelDataList = new ChannelDataListOutPut();
+
+            foreach (var item in groupedStatistics)
+            {
+                ChannelDataReceive receive = new ChannelDataReceive()
+                {
+                    ChannelName = _lifePayChannlesRep.Where(x => x.ChannlesNum == item.ChannelId).FirstOrDefault()?.ChannlesName,
+                    ReceivePrice = item.ReceivePrice,
+                    ChannlesRakePrice = item.ChannlesRakePrice,
+                };
+                if (channelDataList.ReceiveList.Count() < maxStatisticsNumber)
+                {
+                    channelDataList.ReceiveList.Add(receive);
+                }
+            }
+
+            /// 绱鐢ㄦ埛
+            var users = await _lifePayUserRepository.WhereIf(channleList.Count() > 0, x => channleList.Contains(x.CreationChannleNum))
+                .ToListAsync();
+            CheckExtensions.IfTrueThrowUserFriendlyException(statistics == null, "绱鐢ㄦ埛缁熻澶辫触");
+            var groupedUsers = users
+              .GroupBy(x => x.CreationChannleNum)
+              .Select(g => new
+              {
+                  ChannelId = g.Key,
+                  Number = g.Count(),
+              })
+              .OrderByDescending(o => o.Number)
+              .ToList();
+            foreach (var item in groupedUsers)
+            {
+                ChannelDataUserNumber usernumber = new ChannelDataUserNumber()
+                {
+                    ChannelName = _lifePayChannlesRep.Where(x => x.ChannlesNum == item.ChannelId).FirstOrDefault()?.ChannlesName,
+                    Number = item.Number,
+                };
+                if (channelDataList.UserNumberList.Count() < maxStatisticsNumber)
+                {
+                    channelDataList.UserNumberList.Add(usernumber);
+                }
+            }
+
+
+
+            return channelDataList;
+        }
+
+        public async Task StatisticsByDate(int days)
+        {
+            var today = DateTime.Now.Date;
+            for (var i = 0; i < days; i++)
+            {
+                var statistics = await _dallyStatisticsRepository.Where(x => x.CreationTime.Date == today)
+                .ToListAsync();
+
+                if (statistics == null || statistics.Count() == 0)
+                {
+                    TopStatisticsOutput topStatisticsOutput = new TopStatisticsOutput() { };
+                    var allChannle = await _lifePayChannlesRep.ToListAsync();
+                    foreach (var item in allChannle)
+                    {
+                        var entity = await TopStatistics(item.ChannlesNum, today);
+                    }
+                }
+
+                today = today.AddDays(-1);
+            }
+        }
+
+        private async Task<DallyStatistics> TopStatistics(string channleId, DateTime today)
+        {
+            /// 绱鏀舵锛氱粺璁″钩鍙拌处鎴蜂笅璁㈠崟鍒涘缓鏃堕棿鍦ㄦ槰澶╁強涔嬪墠鏀跺埌鐨勩�愮敤鎴锋敮浠樻垚鍔熺殑閲戦-閫�娆剧粰鐢ㄦ埛鐨勯噾棰濄�戯紱
+            var accumulatedReceipts = await _lifePayOrderRepository.Where(x => x.CreationTime < today && x.PayStatus != LifePayStatusEnum.鏈敮浠�)
+            .WhereIf(!string.IsNullOrWhiteSpace(channleId), x => x.ChannelId == channleId).SumAsync(x => x.PayAmount) - 
+            await _lifePayOrderRepository.Where(x => x.CreationTime < today && x.LifePayRefundStatus == LifePayRefundStatusEnum.宸查��娆�)
+            .WhereIf(!string.IsNullOrWhiteSpace(channleId), x => x.ChannelId == channleId).SumAsync(x => (x.RefundPrice ?? 0));
+            /// 鏄ㄦ棩鏀舵锛氱粺璁″钩鍙拌处鎴蜂笅璁㈠崟鍒涘缓鏃堕棿鍦ㄦ槰澶╂敹鍒扮殑銆愮敤鎴锋敮浠樻垚鍔熺殑閲戦-閫�娆剧粰鐢ㄦ埛鐨勯噾棰濄�戯紱
+            var receiptsYesterday = await _lifePayOrderRepository.Where(x => x.CreationTime >= today.AddDays(-1) && x.CreationTime < today && x.PayStatus == LifePayStatusEnum.宸叉敮浠�)
+                .WhereIf(!string.IsNullOrWhiteSpace(channleId), x => x.ChannelId == channleId).SumAsync(x => x.PayAmount) -
+                await _lifePayOrderRepository.Where(x => x.CreationTime >= today.AddDays(-1) && x.CreationTime < today && x.LifePayRefundStatus == LifePayRefundStatusEnum.宸查��娆�)
+                .WhereIf(!string.IsNullOrWhiteSpace(channleId), x => x.ChannelId == channleId).SumAsync(x => (x.RefundPrice ?? 0));
+            /// 绱鏀跺叆锛氱粺璁″钩鍙拌处鎴蜂笅璁㈠崟鐘舵�佷负鈥滃凡瀹屾垚鈥濅笖璁㈠崟鍒涘缓鏃堕棿鍦ㄦ槰澶╁強涔嬪墠鏀跺埌鐨勩�愮敤鎴峰疄浠橀噾棰�-骞冲彴鎵f閲戦-閮ㄥ垎閫�娆鹃噾棰濄�戯紱
+            var accumulatedIncome = await _lifePayOrderRepository.Where(x => x.CreationTime < today && x.LifePayOrderStatus == LifePayOrderStatusEnum.宸插畬鎴�)
+                .WhereIf(!string.IsNullOrWhiteSpace(channleId), x => x.ChannelId == channleId).SumAsync(x => x.PayAmount - (x.PlatformDeductionAmount ?? 0) - (x.RefundPrice ?? 0));
+            /// 鏄ㄦ棩鏀跺叆锛氱粺璁″钩鍙拌处鎴蜂笅璁㈠崟鐘舵�佷负鈥滃凡瀹屾垚鈥濅笖璁㈠崟鍒涘缓鏃堕棿鍦ㄦ槰澶╂敹鍒扮殑銆愮敤鎴峰疄浠橀噾棰�-骞冲彴鎵f閲戦-閮ㄥ垎閫�娆鹃噾棰濄�戯紱
+            var yesterdayIncome = await _lifePayOrderRepository.Where(x => x.CreationTime >= today.AddDays(-1) && x.CreationTime < today && x.LifePayOrderStatus == LifePayOrderStatusEnum.宸插畬鎴�)
+                .WhereIf(!string.IsNullOrWhiteSpace(channleId), x => x.ChannelId == channleId).SumAsync(x => x.PayAmount - (x.PlatformDeductionAmount ?? 0) - (x.RefundPrice ?? 0));
+            /// 绱涓嬪崟锛氱粺璁″钩鍙颁腑璁㈠崟涓嬪崟鏃堕棿鍦ㄦ槰澶╁強涔嬪墠鏃堕棿鐨勮鍗曡褰曪紱
+            var accumulatedOrders = await _lifePayOrderRepository.Where(x => x.CreationTime < today).WhereIf(!string.IsNullOrWhiteSpace(channleId), x => x.ChannelId == channleId).CountAsync();
+            /// 鏄ㄦ棩涓嬪崟锛氱粺璁″钩鍙颁腑璁㈠崟涓嬪崟鏃堕棿鍦ㄦ槰澶╃殑璁㈠崟璁板綍锛�
+            var ordersNumYesterday = await _lifePayOrderRepository.Where(x => x.CreationTime >= today.AddDays(-1) && x.CreationTime < today)
+                .WhereIf(!string.IsNullOrWhiteSpace(channleId), x => x.ChannelId == channleId).CountAsync();
+            /// 鏄ㄦ棩鎴愬姛锛氱粺璁″钩鍙颁腑璁㈠崟鐘舵�佷负鈥滃凡瀹屾垚/閮ㄥ垎鍏呭�兼垚鍔熲�濅笖璁㈠崟涓嬪崟鏃堕棿鍦ㄦ槰澶╃殑璁㈠崟璁板綍锛�
+            var yesterdaySuccess = await _lifePayOrderRepository.Where(x => x.CreationTime >= today.AddDays(-1) && x.CreationTime < today && x.LifePayOrderStatus == LifePayOrderStatusEnum.宸插畬鎴�)
+                .WhereIf(string.IsNullOrWhiteSpace(channleId), x => x.ChannelId == channleId).CountAsync();
+            /// 鏄ㄦ棩澶辫触锛氱粺璁″钩鍙颁腑璁㈠崟鐘舵�佷负鈥滃厖鍊煎け璐�/宸查��娆锯�濅笖璁㈠崟涓嬪崟鏃堕棿鍦ㄦ槰澶╃殑璁㈠崟璁板綍锛�
+            var yesterdayFail = await _lifePayOrderRepository.Where(x => x.CreationTime >= today.AddDays(-1) && x.CreationTime < today && x.LifePayOrderStatus == LifePayOrderStatusEnum.宸查��娆�)
+                .WhereIf(!string.IsNullOrWhiteSpace(channleId), x => x.ChannelId == channleId).CountAsync();
+            /// 绱鐢ㄦ埛
+            var accumulatedUsers = await _lifePayUserRepository.Where(x => x.CreationTime < today)
+                .WhereIf(!string.IsNullOrWhiteSpace(channleId), x => x.CreationChannleNum == channleId).CountAsync();
+            /// 鏄ㄦ棩娲昏穬鐢ㄦ埛
+            var yesterdayActiveUsers = await (from a in _lifePayUserRepository
+                                              join b in _lifePayOrderRepository on a.Id equals b.UserId
+                                              where b.CreationTime >= today.AddDays(-1) && b.CreationTime < today
+                                              && (b.ACOOLYStatus == ACOOLYStatusEnum.鍏呭�间腑 || b.ACOOLYStatus == ACOOLYStatusEnum.鍏呭�兼垚鍔� || b.ACOOLYStatus == ACOOLYStatusEnum.宸插畬鎴� || b.ACOOLYStatus == ACOOLYStatusEnum.閮ㄥ垎鍏呭�兼垚鍔�)
+                                              select b).Distinct().CountAsync();
+            /// 绱浣i噾
+            var accumulatedChannlesRakePrice = await _lifePayChannlesRakeRepository.Where(x => x.FinishTime < today)
+                .WhereIf(!string.IsNullOrWhiteSpace(channleId), x => x.ChannelId == channleId).SumAsync(x => x.ChannlesRakePrice);
+
+            var entity = new DallyStatistics()
+            {
+                Id = GuidGenerator.Create(),
+                CreationTime = today,
+                AccumulatedReceipts = accumulatedReceipts ?? 0,
+                AccumulatedIncome = accumulatedIncome ?? 0,
+                IncomeYesterday = yesterdayIncome ?? 0,
+                ReceiptsYesterday = receiptsYesterday ?? 0,
+                AccumulatedOrders = accumulatedOrders,
+                OrdersNumYesterday = ordersNumYesterday,
+                YesterdaySuccess = yesterdaySuccess,
+                YesterdayFail = yesterdayFail,
+                AccumulatedUsers = accumulatedUsers,
+                YesterdayActiveUsers = yesterdayActiveUsers,
+                ChannelId = channleId,
+                AccumulatedChannlesRakePrice = accumulatedChannlesRakePrice,
+                Date = today.AddDays(-1)
+            };
+            await _dallyStatisticsRepository.InsertAsync(entity);
+            return entity;
+        }
     }
 }

--
Gitblit v1.9.1