From d7399b083de823860a56b68c79f8e36603fb4ea3 Mon Sep 17 00:00:00 2001
From: zhengyuxuan <zhengyuxuan1995>
Date: 星期一, 31 三月 2025 13:37:19 +0800
Subject: [PATCH] fix:获取渠道分佣分页列表

---
 LifePayment/LifePayment.Application/LifePay/StatisticsService.cs |   53 +++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 37 insertions(+), 16 deletions(-)

diff --git a/LifePayment/LifePayment.Application/LifePay/StatisticsService.cs b/LifePayment/LifePayment.Application/LifePay/StatisticsService.cs
index 3c6ff34..7547c44 100644
--- a/LifePayment/LifePayment.Application/LifePay/StatisticsService.cs
+++ b/LifePayment/LifePayment.Application/LifePay/StatisticsService.cs
@@ -35,46 +35,59 @@
             _dallyStatisticsRepository = dallyStatisticsRepository;
         }
 
-        public async Task<TopStatisticsOutput> GetTopStatistics()
+        /// <summary>
+        /// 椤堕儴缁熻
+        /// </summary>
+        /// <param name="channleId"></param>
+        /// <returns></returns>
+        public async Task<TopStatisticsOutput> GetTopStatistics(string channleId = "")
         {
             var today = DateTime.Now.Date;
-            var statistics = await _dallyStatisticsRepository.Where(x => x.CreationTime.Date == today).FirstOrDefaultAsync();
+            var statistics = await _dallyStatisticsRepository.Where(x => x.CreationTime.Date == today)
+                .WhereIf(!string.IsNullOrWhiteSpace(channleId), x => x.ChannelId == channleId)
+                .FirstOrDefaultAsync();
             if (statistics == null)
             {
                 /// 绱鏀舵锛氱粺璁″钩鍙拌处鎴蜂笅璁㈠崟鍒涘缓鏃堕棿鍦ㄦ槰澶╁強涔嬪墠鏀跺埌鐨勩�愮敤鎴锋敮浠樻垚鍔熺殑閲戦-閫�娆剧粰鐢ㄦ埛鐨勯噾棰濄�戯紱
-                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);
+                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.宸查��娆�).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.PayAmount);
+                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.宸查��娆�).SumAsync(x => (x.RefundPrice ?? 0));
                 /// 绱鏀跺叆锛氱粺璁″钩鍙拌处鎴蜂笅璁㈠崟鐘舵�佷负鈥滃凡瀹屾垚鈥濅笖璁㈠崟鍒涘缓鏃堕棿鍦ㄦ槰澶╁強涔嬪墠鏀跺埌鐨勩�愮敤鎴峰疄浠橀噾棰�-骞冲彴鎵f閲戦-閮ㄥ垎閫�娆鹃噾棰濄�戯紱
-                var accumulatedIncome = await _lifePayOrderRepository.Where(x => x.CreationTime < today && x.LifePayOrderStatus == LifePayOrderStatusEnum.宸插畬鎴�).SumAsync(x => x.PayAmount - x.PlatformDeductionAmount) -
-                    await _lifePayOrderRepository.Where(x => x.CreationTime < today && x.LifePayRefundStatus == LifePayRefundStatusEnum.宸查��娆�).SumAsync(x => x.RefundPrice);
+                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 accumulatedOrders = await _lifePayOrderRepository.Where(x => x.CreationTime < today).CountAsync();
+                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).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.宸插畬鎴�).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.宸查��娆�).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.CountAsync();
+                var accumulatedUsers = await _lifePayUserRepository.WhereIf(!string.IsNullOrWhiteSpace(channleId), x => x.CreationChannleNum == channleId).CountAsync();
                 /// 鏄ㄦ棩娲昏穬鐢ㄦ埛
-                var yesterdayActiveUsers = await _lifePayUserRepository.Where(x => x.LastLoginTime >= today.AddDays(-1)).CountAsync();
+                var yesterdayActiveUsers = await _lifePayUserRepository.WhereIf(!string.IsNullOrWhiteSpace(channleId), x => x.CreationChannleNum == channleId).Where(x => x.LastLoginTime >= today.AddDays(-1)).CountAsync();
 
                 var entity = new DallyStatistics()
                 {
                     Id = GuidGenerator.Create(),
                     CreationTime = DateTime.Now,
                     Amount = 0,
-                    AccumulatedReceipts = accumulatedReceipts.HasValue? accumulatedReceipts.Value:0,
-                    AccumulatedIncome = accumulatedIncome.HasValue ? accumulatedIncome.Value : 0,
-                    ReceiptsYesterday = receiptsYesterday,
+                    AccumulatedReceipts = accumulatedReceipts??0,
+                    AccumulatedIncome = accumulatedIncome ?? 0,
+                    ReceiptsYesterday = receiptsYesterday ?? 0,
                     AccumulatedOrders = accumulatedOrders,
                     OrdersNumYesterday = ordersNumYesterday,
                     YesterdaySuccess = yesterdaySuccess,
                     YesterdayFail = yesterdayFail,
                     AccumulatedUsers = accumulatedUsers,
-                    YesterdayActiveUsers = yesterdayActiveUsers
+                    YesterdayActiveUsers = yesterdayActiveUsers,
+                    ChannelId = channleId
                 };
                 await _dallyStatisticsRepository.InsertAsync(entity);
 
@@ -99,15 +112,23 @@
                 {
                     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,
                 };
                 return topStatisticsOutput;
             }
         }
+
+        //public async Task<ReceiptsListOutPut> GetReceiptsList(string channleId = "")
+        //{
+        //    var today = DateTime.Now.Date;
+
+        //}
     }
 }

--
Gitblit v1.9.1