From 0ee3e9996050bd0df360367af28738acea9cdfc6 Mon Sep 17 00:00:00 2001
From: sunpengfei <i@angelzzz.com>
Date: 星期三, 11 六月 2025 16:12:48 +0800
Subject: [PATCH] fix:修改统计公式 新增前端日志上传

---
 LifePayment/LifePayment.Application/LifePay/StatisticsService.cs |   74 ++++++++++++++++++++++++-------------
 1 files changed, 48 insertions(+), 26 deletions(-)

diff --git a/LifePayment/LifePayment.Application/LifePay/StatisticsService.cs b/LifePayment/LifePayment.Application/LifePay/StatisticsService.cs
index a4e22f2..7438b91 100644
--- a/LifePayment/LifePayment.Application/LifePay/StatisticsService.cs
+++ b/LifePayment/LifePayment.Application/LifePay/StatisticsService.cs
@@ -205,18 +205,39 @@
 
         public async Task<ChannelDataListOutPut> GetChannelDataList(List<string> channleList)
         {
+            var today = DateTime.Now.Date;
             int maxStatisticsNumber = 5;
+            /// 杩欓噷涓嶅姞鍏�.Where()浼氭姤閿�
             var statistics = await _lifePayChannlesRakeRepository
-                            .WhereIf(channleList != null && channleList.Count() > 0, x => channleList.Contains(x.ChannelId))
-            .ToListAsync();
+                .Where(x => x.IsDeleted == false && x.CreationTime < today)
+                .WhereIf(channleList.Count() > 0, x => channleList.Contains(x.ChannelId))
+                .ToListAsync();
+
+            var lifepayOrderBaseList = await _lifePayOrderRepository
+                .Where(x => x.CreationTime < today && x.PayStatus != LifePayStatusEnum.鏈敮浠�)
+                .WhereIf(channleList.Count() > 0, x => channleList.Contains(x.ChannelId))
+                .ToListAsync();
+
             CheckExtensions.IfTrueThrowUserFriendlyException(statistics == null, "娓犻亾鏀舵缁熻澶辫触");
             var groupedStatistics = statistics
                .GroupBy(x => x.ChannelId)
-               .Select(g => new
+               .Select(g =>
                {
-                   ChannelId = g.Key,
-                   ReceivePrice = g.Sum(x => x.PayAmount),
-                   ChannlesRakePrice = g.Sum(x => x.ChannlesRakePrice),
+                   /// 绱鏀舵锛氱粺璁″钩鍙拌处鎴蜂笅璁㈠崟鍒涘缓鏃堕棿鍦ㄦ槰澶╁強涔嬪墠鏀跺埌鐨勩�愮敤鎴锋敮浠樻垚鍔熺殑閲戦-閫�娆剧粰鐢ㄦ埛鐨勯噾棰濄�戯紱
+                   var accumulatedReceipts =
+                        lifepayOrderBaseList
+                            .Where(x => x.ChannelId == g.Key)
+                            .Sum(x => x.PayAmount)
+                        -
+                        lifepayOrderBaseList
+                            .Where(x => x.ChannelId == g.Key && x.LifePayRefundStatus == LifePayRefundStatusEnum.宸查��娆�)
+                            .Sum(x => (x.RefundPrice ?? 0));
+                   return new
+                   {
+                       ChannelId = g.Key,
+                       ReceivePrice = accumulatedReceipts ?? 0,
+                       ChannlesRakePrice = g.Sum(x => x.ChannlesRakePrice),
+                   };
                })
                .OrderByDescending(o => o.ReceivePrice)
                .ToList();
@@ -238,7 +259,7 @@
             }
 
             /// 绱鐢ㄦ埛
-            var users = await _lifePayUserRepository.WhereIf(channleList.Count() > 0, x => channleList.Contains(x.CreationChannleNum))
+            var users = await _lifePayUserRepository.Where(x => x.IsDeleted == false && x.CreationTime < today).WhereIf(channleList.Count() > 0, x => channleList.Contains(x.CreationChannleNum))
                 .ToListAsync();
             CheckExtensions.IfTrueThrowUserFriendlyException(statistics == null, "绱鐢ㄦ埛缁熻澶辫触");
             var groupedUsers = users
@@ -292,33 +313,34 @@
 
         private async Task<DallyStatistics> TopStatistics(string channleId, DateTime today)
         {
+            var lifepayOrderBaseList = await _lifePayOrderRepository.Where(x => x.CreationTime < today && x.PayStatus != LifePayStatusEnum.鏈敮浠�)
+                .WhereIf(!string.IsNullOrWhiteSpace(channleId), x => x.ChannelId == channleId).ToListAsync();
+
             /// 绱鏀舵锛氱粺璁″钩鍙拌处鎴蜂笅璁㈠崟鍒涘缓鏃堕棿鍦ㄦ槰澶╁強涔嬪墠鏀跺埌鐨勩�愮敤鎴锋敮浠樻垚鍔熺殑閲戦-閫�娆剧粰鐢ㄦ埛鐨勯噾棰濄�戯紱
-            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 accumulatedReceipts = lifepayOrderBaseList.Where(x => x.PayStatus != LifePayStatusEnum.鏈敮浠�).Sum(x => x.PayAmount)
+               - lifepayOrderBaseList.Where(x => x.LifePayRefundStatus == LifePayRefundStatusEnum.宸查��娆�).Sum(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));
+            var receiptsYesterday = lifepayOrderBaseList.Where(x => x.CreationTime >= today.AddDays(-1) && x.PayStatus == LifePayStatusEnum.宸叉敮浠�)
+                .Sum(x => x.PayAmount) -
+                lifepayOrderBaseList.Where(x => x.CreationTime >= today.AddDays(-1) && x.LifePayRefundStatus == LifePayRefundStatusEnum.宸查��娆�)
+                .Sum(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));
+            var accumulatedIncome = lifepayOrderBaseList.Where(x => x.LifePayOrderStatus == LifePayOrderStatusEnum.宸插畬鎴�)
+              .Sum(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 yesterdayIncome = lifepayOrderBaseList.Where(x => x.CreationTime >= today.AddDays(-1) && x.LifePayOrderStatus == LifePayOrderStatusEnum.宸插畬鎴�)
+                .Sum(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 accumulatedOrders = lifepayOrderBaseList.Count();
             /// 鏄ㄦ棩涓嬪崟锛氱粺璁″钩鍙颁腑璁㈠崟涓嬪崟鏃堕棿鍦ㄦ槰澶╃殑璁㈠崟璁板綍锛�
-            var ordersNumYesterday = await _lifePayOrderRepository.Where(x => x.CreationTime >= today.AddDays(-1) && x.CreationTime < today)
-                .WhereIf(!string.IsNullOrWhiteSpace(channleId), x => x.ChannelId == channleId).CountAsync();
+            var ordersNumYesterday = lifepayOrderBaseList.Where(x => x.CreationTime >= today.AddDays(-1)).Count();
             /// 鏄ㄦ棩鎴愬姛锛氱粺璁″钩鍙颁腑璁㈠崟鐘舵�佷负鈥滃凡瀹屾垚/閮ㄥ垎鍏呭�兼垚鍔熲�濅笖璁㈠崟涓嬪崟鏃堕棿鍦ㄦ槰澶╃殑璁㈠崟璁板綍锛�
-            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 yesterdaySuccess = lifepayOrderBaseList.Where(x => x.CreationTime >= today.AddDays(-1) && x.LifePayOrderStatus == LifePayOrderStatusEnum.宸插畬鎴�)
+                .Count();
             /// 鏄ㄦ棩澶辫触锛氱粺璁″钩鍙颁腑璁㈠崟鐘舵�佷负鈥滃厖鍊煎け璐�/宸查��娆锯�濅笖璁㈠崟涓嬪崟鏃堕棿鍦ㄦ槰澶╃殑璁㈠崟璁板綍锛�
-            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 yesterdayFail = lifepayOrderBaseList.Where(x => x.CreationTime >= today.AddDays(-1) && x.LifePayOrderStatus == LifePayOrderStatusEnum.宸查��娆�)
+                .Count();
             /// 绱鐢ㄦ埛
             var accumulatedUsers = await _lifePayUserRepository.Where(x => x.CreationTime < today)
                 .WhereIf(!string.IsNullOrWhiteSpace(channleId), x => x.CreationChannleNum == channleId).CountAsync();

--
Gitblit v1.9.1