zhengyuxuan
2025-04-02 02f5cf149ac0fecd8c7ee67bf57fb814d8464ba4
fix:统计bug修复
7个文件已修改
91 ■■■■■ 已修改文件
LifePayment/LifePayment.Application.Contracts/LifePay/IStatisticsService.cs 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
LifePayment/LifePayment.Application.Contracts/LifePay/LifePayOutput.cs 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
LifePayment/LifePayment.Application/LifePay/StatisticsService.cs 54 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
LifePayment/LifePayment.Domain/LifePay/DallyStatistics.cs 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
LifePayment/LifePayment.Host/LifePaymentService.HttpApi.xml 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
LifePayment/LifePayment.Host/LifePaymentServices.Application.Contracts.xml 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
LifePayment/LifePayment.HttpApi/LifePay/LifePayController.cs 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
LifePayment/LifePayment.Application.Contracts/LifePay/IStatisticsService.cs
@@ -12,6 +12,8 @@
{
    Task<TopStatisticsOutput> GetTopStatistics(List<string>? channleList = null);
    Task StatisticsByDate(int days);
    Task<ReceiptsListOutPut> GetReceiptsList(List<string>? channleList = null);
    Task<ChannelDataListOutPut> GetChannelDataList(List<string>? channleList = null);
LifePayment/LifePayment.Application.Contracts/LifePay/LifePayOutput.cs
@@ -1096,7 +1096,10 @@
    /// </summary>
    public int YesterdayActiveUsers { get; set; }
    /// <summary>
    /// 累计佣金
    /// </summary>
    public decimal AccumulatedChannlesRakePrice { get; set; }
}
public class ChannelRateOutput
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);
LifePayment/LifePayment.Domain/LifePay/DallyStatistics.cs
@@ -79,4 +79,9 @@
    /// 统计日期
    /// </summary>
    public DateTime Date { get; set; }
    /// <summary>
    /// 累计佣金
    /// </summary>
    public decimal AccumulatedChannlesRakePrice { get; set; }
}
LifePayment/LifePayment.Host/LifePaymentService.HttpApi.xml
@@ -70,6 +70,13 @@
            <param name="input"></param>
            <returns></returns>
        </member>
        <member name="M:LifePayment.HttpApi.LifePayController.StatisticsByDate(System.Int32)">
            <summary>
            获取指定天数的统计数据
            </summary>
            <param name="days"></param>
            <returns></returns>
        </member>
        <member name="M:LifePayment.HttpApi.LifePayController.GetReceiptsList(LifePayment.Application.Contracts.TopStatisticsInput)">
            <summary>
            获取30日收款统计
LifePayment/LifePayment.Host/LifePaymentServices.Application.Contracts.xml
@@ -1789,6 +1789,11 @@
            昨日活跃用户
            </summary>
        </member>
        <member name="P:LifePayment.Application.Contracts.TopStatisticsOutput.AccumulatedChannlesRakePrice">
            <summary>
            累计佣金
            </summary>
        </member>
        <member name="P:LifePayment.Application.Contracts.OnlineServiceInput.Link">
            <summary>
            在线客服链接
LifePayment/LifePayment.HttpApi/LifePay/LifePayController.cs
@@ -61,6 +61,19 @@
        }
        /// <summary>
        /// 获取指定天数的统计数据
        /// </summary>
        /// <param name="days"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<int> StatisticsByDate(int days)
        {
            await _statisticsService.StatisticsByDate(days);
            return Constant.SUCCESS;
        }
        /// <summary>
        /// 获取30日收款统计
        /// </summary>
        /// <param name="input"></param>