From 02f5cf149ac0fecd8c7ee67bf57fb814d8464ba4 Mon Sep 17 00:00:00 2001
From: zhengyuxuan <zhengyuxuan1995>
Date: 星期三, 02 四月 2025 16:31:09 +0800
Subject: [PATCH] fix:统计bug修复

---
 LifePayment/LifePayment.Application/LifePay/StatisticsService.cs |   54 +++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 47 insertions(+), 7 deletions(-)

diff --git a/LifePayment/LifePayment.Application/LifePay/StatisticsService.cs b/LifePayment/LifePayment.Application/LifePay/StatisticsService.cs
index be6e9e8..6869c94 100644
--- a/LifePayment/LifePayment.Application/LifePay/StatisticsService.cs
+++ b/LifePayment/LifePayment.Application/LifePay/StatisticsService.cs
@@ -59,6 +59,7 @@
             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.IsDeleted == false && x.CreationTime < today).SumAsync(x => x.RechargeAmount);
             if (statistics == null || statistics.Count() == 0)
             {
                 TopStatisticsOutput topStatisticsOutput = new TopStatisticsOutput() { };
@@ -68,7 +69,6 @@
                     var entity = await TopStatistics(item.ChannlesNum, today);
                     if (channleList.Count() == 0 || channleList.Contains(item.ChannlesNum))
                     {
-                        topStatisticsOutput.Amount += entity.Amount;
                         topStatisticsOutput.AccumulatedReceipts += entity.AccumulatedReceipts;
                         topStatisticsOutput.AccumulatedIncome += entity.AccumulatedIncome;
                         topStatisticsOutput.ReceiptsYesterday += entity.ReceiptsYesterday;
@@ -78,15 +78,26 @@
                         topStatisticsOutput.YesterdayFail += entity.YesterdayFail;
                         topStatisticsOutput.AccumulatedUsers += entity.AccumulatedUsers;
                         topStatisticsOutput.YesterdayActiveUsers += entity.YesterdayActiveUsers;
+                        topStatisticsOutput.AccumulatedChannlesRakePrice += entity.AccumulatedChannlesRakePrice;
                     }
                 }
+
+                if (channleList.Count() == 0)
+                {
+                    /// 璐︽埛浣欓
+                    var accountBalance = totalRechargeReceipts - await _lifePayOrderRepository.Where(x => x.CreationTime < today && x.PayStatus == LifePayStatusEnum.宸叉敮浠�
+                    && (x.ACOOLYStatus == ACOOLYStatusEnum.鍏呭�兼垚鍔� || x.ACOOLYStatus == ACOOLYStatusEnum.宸插畬鎴� || x.ACOOLYStatus == ACOOLYStatusEnum.閮ㄥ垎鍏呭�兼垚鍔�))
+                      .SumAsync(x => x.PayAmount);
+                    topStatisticsOutput.Amount = accountBalance ?? 0;
+
+                }
+
                 return topStatisticsOutput;
             }
             else
             {
                 TopStatisticsOutput topStatisticsOutput = new TopStatisticsOutput()
                 {
-                    Amount = statistics.Sum(s => s.Amount),
                     AccumulatedReceipts = statistics.Sum(s => s.AccumulatedReceipts),
                     AccumulatedIncome = statistics.Sum(s => s.AccumulatedIncome),
                     ReceiptsYesterday = statistics.Sum(s => s.ReceiptsYesterday),
@@ -96,7 +107,17 @@
                     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)
+                {
+                    /// 璐︽埛浣欓
+                    var accountBalance = totalRechargeReceipts - await _lifePayOrderRepository.Where(x => x.CreationTime < today && x.PayStatus == LifePayStatusEnum.宸叉敮浠�
+                    && (x.ACOOLYStatus == ACOOLYStatusEnum.鍏呭�兼垚鍔� || x.ACOOLYStatus == ACOOLYStatusEnum.宸插畬鎴� || x.ACOOLYStatus == ACOOLYStatusEnum.閮ㄥ垎鍏呭�兼垚鍔�))
+                      .SumAsync(x => x.PayAmount);
+                    topStatisticsOutput.Amount = accountBalance ?? 0;
+
+                }
                 return topStatisticsOutput;
             }
         }
@@ -240,13 +261,30 @@
             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.Where(x => x.IsDeleted == false).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 totalRechargeReceipts = await _lifePayRechargeReceiptsRepository.Where(x => x.IsDeleted == false && x.CreationTime < today).SumAsync(x => x.RechargeAmount);
-            var accountBalance = totalRechargeReceipts - await _lifePayOrderRepository.Where(x => x.CreationTime < today && x.PayStatus == LifePayStatusEnum.宸叉敮浠� 
-            && (x.ACOOLYStatus == ACOOLYStatusEnum.鍏呭�兼垚鍔� || x.ACOOLYStatus == ACOOLYStatusEnum.宸插畬鎴� || x.ACOOLYStatus == ACOOLYStatusEnum.閮ㄥ垎鍏呭�兼垚鍔�))
-                .WhereIf(!string.IsNullOrWhiteSpace(channleId), x => x.ChannelId == channleId).SumAsync(x => x.PayAmount);
             /// 绱鏀舵锛氱粺璁″钩鍙拌处鎴蜂笅璁㈠崟鍒涘缓鏃堕棿鍦ㄦ槰澶╁強涔嬪墠鏀跺埌鐨勩�愮敤鎴锋敮浠樻垚鍔熺殑閲戦-閫�娆剧粰鐢ㄦ埛鐨勯噾棰濄�戯紱
             var accumulatedReceipts = await _lifePayOrderRepository.Where(x => x.CreationTime < today && x.PayStatus != LifePayStatusEnum.鏈敮浠�)
             .WhereIf(!string.IsNullOrWhiteSpace(channleId), x => x.ChannelId == channleId).SumAsync(x => x.PayAmount) - 
@@ -279,12 +317,13 @@
             /// 鏄ㄦ棩娲昏穬鐢ㄦ埛
             var yesterdayActiveUsers = await _lifePayUserRepository.Where(x => x.IsDeleted == false).WhereIf(!string.IsNullOrWhiteSpace(channleId), x => x.CreationChannleNum == channleId).Where(x => x.LastLoginTime >= today.AddDays(-1)).CountAsync();
 
+            var accumulatedChannlesRakePrice = await _lifePayChannlesRakeRepository.Where(x => x.IsDeleted == false && x.FinishTime < today)
+                .WhereIf(!string.IsNullOrWhiteSpace(channleId), x => x.ChannelId == channleId).SumAsync(x => x.ChannlesRakePrice);
 
             var entity = new DallyStatistics()
             {
                 Id = GuidGenerator.Create(),
                 CreationTime = today,
-                Amount = accountBalance ?? 0,
                 AccumulatedReceipts = accumulatedReceipts ?? 0,
                 AccumulatedIncome = accumulatedIncome ?? 0,
                 IncomeYesterday = yesterdayIncome ?? 0,
@@ -296,6 +335,7 @@
                 AccumulatedUsers = accumulatedUsers,
                 YesterdayActiveUsers = yesterdayActiveUsers,
                 ChannelId = channleId,
+                AccumulatedChannlesRakePrice = accumulatedChannlesRakePrice,
                 Date = today.AddDays(-1)
             };
             await _dallyStatisticsRepository.InsertAsync(entity);

--
Gitblit v1.9.1