zhengyuxuan
2025-04-03 d47921dc014dfaee234ce50cb4c296d342e09085
LifePayment/LifePayment.Application/LifePay/StatisticsService.cs
@@ -60,11 +60,11 @@
            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);
            var totalRechargeReceipts = await _lifePayRechargeReceiptsRepository.Where(x => x.CreationTime < today).SumAsync(x => x.RechargeAmount);
            if (statistics == null || statistics.Count() == 0)
            {
                TopStatisticsOutput topStatisticsOutput = new TopStatisticsOutput() { };
                var allChannle = await _lifePayChannlesRep.Where(x => x.IsDeleted == false).ToListAsync();
                var allChannle = await _lifePayChannlesRep.ToListAsync();
                foreach (var item in allChannle)
                {
                    var entity = await TopStatistics(item.ChannlesNum, today);
@@ -86,9 +86,8 @@
                if (channleList.Count() == 0)
                {
                    /// 账户余额
                    var accountBalance = totalRechargeReceipts - await _lifePayOrderRepository.Where(x => x.ACOOLYStatus == ACOOLYStatusEnum.充值成功 || x.ACOOLYStatus == ACOOLYStatusEnum.已完成 || x.ACOOLYStatus == ACOOLYStatusEnum.部分充值成功)
                      .SumAsync(x => x.PlatformDeductionAmount);
                    topStatisticsOutput.Amount = accountBalance ?? 0;
                    topStatisticsOutput.Amount = totalRechargeReceipts - await _lifePayOrderRepository.Where(x => x.ACOOLYStatus == ACOOLYStatusEnum.充值成功 || x.ACOOLYStatus == ACOOLYStatusEnum.已完成 || x.ACOOLYStatus == ACOOLYStatusEnum.部分充值成功)
                      .SumAsync(x => x.PlatformDeductionAmount) ?? 0;
                }
                return topStatisticsOutput;
@@ -111,9 +110,8 @@
                if (channleList.Count() == 0)
                {
                    /// 账户余额
                    var accountBalance = totalRechargeReceipts - await _lifePayOrderRepository.Where(x => x.ACOOLYStatus == ACOOLYStatusEnum.充值成功 || x.ACOOLYStatus == ACOOLYStatusEnum.已完成 || x.ACOOLYStatus == ACOOLYStatusEnum.部分充值成功)
                      .SumAsync(x => x.PlatformDeductionAmount);
                    topStatisticsOutput.Amount = accountBalance ?? 0;
                    topStatisticsOutput.Amount = totalRechargeReceipts - await _lifePayOrderRepository.Where(x => x.ACOOLYStatus == ACOOLYStatusEnum.充值成功 || x.ACOOLYStatus == ACOOLYStatusEnum.已完成 || x.ACOOLYStatus == ACOOLYStatusEnum.部分充值成功)
                      .SumAsync(x => x.PlatformDeductionAmount) ?? 0;
                }
                return topStatisticsOutput;
@@ -132,7 +130,7 @@
                .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
@@ -163,13 +161,18 @@
            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.IsDeleted == false &&
            x.FinishTime.Date <= today && x.FinishTime.Date >= today.AddDays(-30))
            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, "佣金统计失败");
            var groupedStatistics = statistics
               .GroupBy(x => x.FinishTime.ToString("yyyy-MM-dd"))
               .Select(g => new
@@ -188,22 +191,19 @@
                    CreationTime = item.FinishTime,
                    Amount = item.ChannlesRakePrice
                };
                channlesRakeListOutPut.ChannlesRakeList.Add(receive);
            }
            return channlesRakeListOutPut;
        }
        public async Task<ChannelDataListOutPut> GetChannelDataList(List<string> channleList)
        {
            var statistics = await _lifePayChannlesRakeRepository.Where(x => x.IsDeleted == false)
            int maxStatisticsNumber = 5;
            var statistics = await _lifePayChannlesRakeRepository
                            .WhereIf(channleList != null && channleList.Count() > 0, x => channleList.Contains(x.ChannelId))
            .ToListAsync();
            CheckExtensions.IfTrueThrowUserFriendlyException(statistics == null, "统计失败");
            CheckExtensions.IfTrueThrowUserFriendlyException(statistics == null, "渠道收款统计失败");
            var groupedStatistics = statistics
               .GroupBy(x => x.ChannelId)
               .Select(g => new
@@ -225,15 +225,16 @@
                    ReceivePrice = item.ReceivePrice,
                    ChannlesRakePrice = item.ChannlesRakePrice,
                };
                if (channelDataList.ReceiveList.Count() < 5)
                if (channelDataList.ReceiveList.Count() < maxStatisticsNumber)
                {
                    channelDataList.ReceiveList.Add(receive);
                }
            }
            /// 累计用户
            var users = await _lifePayUserRepository.Where(x => x.IsDeleted == false).WhereIf(channleList.Count() > 0, x => channleList.Contains(x.CreationChannleNum))
            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
@@ -250,7 +251,7 @@
                    ChannelName = _lifePayChannlesRep.Where(x => x.ChannlesNum == item.ChannelId).FirstOrDefault()?.ChannlesName,
                    Number = item.Number,
                };
                if (channelDataList.UserNumberList.Count() < 5)
                if (channelDataList.UserNumberList.Count() < maxStatisticsNumber)
                {
                    channelDataList.UserNumberList.Add(usernumber);
                }
@@ -272,7 +273,7 @@
                if (statistics == null || statistics.Count() == 0)
                {
                    TopStatisticsOutput topStatisticsOutput = new TopStatisticsOutput() { };
                    var allChannle = await _lifePayChannlesRep.Where(x => x.IsDeleted == false).ToListAsync();
                    var allChannle = await _lifePayChannlesRep.ToListAsync();
                    foreach (var item in allChannle)
                    {
                        var entity = await TopStatistics(item.ChannlesNum, today);
@@ -313,7 +314,7 @@
            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.IsDeleted == false && x.CreationTime < today)
            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
@@ -322,7 +323,7 @@
                                              && (b.ACOOLYStatus == ACOOLYStatusEnum.充值中 || b.ACOOLYStatus == ACOOLYStatusEnum.充值成功 || b.ACOOLYStatus == ACOOLYStatusEnum.已完成 || b.ACOOLYStatus == ACOOLYStatusEnum.部分充值成功)
                                              select b).Distinct().CountAsync();
            /// 累计佣金
            var accumulatedChannlesRakePrice = await _lifePayChannlesRakeRepository.Where(x => x.IsDeleted == false && x.FinishTime < today)
            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()