zhengyuxuan
2025-03-28 5ff44c2f7396f585b237c26d3fd442878055da3c
LifePayment/LifePayment.Application/LifePay/StatisticsService.cs
@@ -42,11 +42,11 @@
            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.未支付).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.已支付).SumAsync(x => x.PayAmount) - await _lifePayOrderRepository.Where(x => x.CreationTime >= today.AddDays(-1) && x.CreationTime < today && x.LifePayRefundStatus == LifePayRefundStatusEnum.已退款).SumAsync(x => (x.RefundPrice ?? 0));
                /// 累计收入:统计平台账户下订单状态为“已完成”且订单创建时间在昨天及之前收到的【用户实付金额-平台扣款金额-部分退款金额】;
                var accumulatedIncome = await _lifePayOrderRepository.Where(x => x.CreationTime < today && x.LifePayOrderStatus == LifePayOrderStatusEnum.已完成).SumAsync(x => x.PayAmount - x.PlatformDeductionAmount - x.RefundPrice);
                var accumulatedIncome = await _lifePayOrderRepository.Where(x => x.CreationTime < today && x.LifePayOrderStatus == LifePayOrderStatusEnum.已完成).SumAsync(x => x.PayAmount - (x.PlatformDeductionAmount ?? 0) - (x.RefundPrice ?? 0));
                /// 累计下单:统计平台中订单下单时间在昨天及之前时间的订单记录;
                var accumulatedOrders = await _lifePayOrderRepository.Where(x => x.CreationTime < today).CountAsync();
                /// 昨日下单:统计平台中订单下单时间在昨天的订单记录;
@@ -65,9 +65,9 @@
                    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,
@@ -98,12 +98,14 @@
                {
                    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;
            }