From e08d70b9e610a2c176b88cb092d580754e009de5 Mon Sep 17 00:00:00 2001
From: zhengyuxuan <zhengyuxuan1995>
Date: 星期二, 01 四月 2025 15:41:04 +0800
Subject: [PATCH] 统计
---
LifePayment/LifePayment.Application/LifePay/StatisticsService.cs | 127 +++++++++++++++++++++++++++++++++++++++---
1 files changed, 118 insertions(+), 9 deletions(-)
diff --git a/LifePayment/LifePayment.Application/LifePay/StatisticsService.cs b/LifePayment/LifePayment.Application/LifePay/StatisticsService.cs
index 0ff2fb3..4998753 100644
--- a/LifePayment/LifePayment.Application/LifePay/StatisticsService.cs
+++ b/LifePayment/LifePayment.Application/LifePay/StatisticsService.cs
@@ -18,6 +18,7 @@
using Microsoft.EntityFrameworkCore;
using System.Threading.Channels;
using ZeroD.Util;
+using NPOI.SS.Formula.Functions;
namespace LifePayment.Application.LifePay
{
@@ -26,17 +27,20 @@
private readonly IRepository<LifePayOrder, Guid> _lifePayOrderRepository;
private readonly IRepository<LifePayUser, Guid> _lifePayUserRepository;
private readonly IRepository<DallyStatistics, Guid> _dallyStatisticsRepository;
+ private readonly IRepository<LifePayChannlesRake, Guid> _lifePayChannlesRakeRepository;
private readonly IRepository<LifePayChannles, Guid> _lifePayChannlesRep;
public StatisticsService(
IRepository<LifePayOrder, Guid> lifePayOrderRepository,
IRepository<LifePayUser, Guid> lifePayUserRepository,
IRepository<DallyStatistics, Guid> dallyStatisticsRepository,
+ IRepository<LifePayChannlesRake, Guid> lifePayChannlesRakeRepository,
IRepository<LifePayChannles, Guid> lifePayChannlesRep)
{
_lifePayOrderRepository = lifePayOrderRepository;
_lifePayUserRepository = lifePayUserRepository;
_dallyStatisticsRepository = dallyStatisticsRepository;
+ _lifePayChannlesRakeRepository = lifePayChannlesRakeRepository;
_lifePayChannlesRep = lifePayChannlesRep;
}
@@ -72,8 +76,6 @@
topStatisticsOutput.YesterdayActiveUsers += entity.YesterdayActiveUsers;
}
}
-
-
return topStatisticsOutput;
}
else
@@ -95,11 +97,114 @@
}
}
- //public async Task<ReceiptsListOutPut> GetReceiptsList(List<string> channleList)
- //{
- // var today = DateTime.Now.Date;
+ /// <summary>
+ /// 杩�30鏃ユ敹娆炬暟鎹�
+ /// </summary>
+ /// <param name="channleList"></param>
+ /// <returns></returns>
+ public async Task<ReceiptsListOutPut> GetReceiptsList(List<string> channleList)
+ {
+ var today = DateTime.Now.Date;
+ var statistics = await _dallyStatisticsRepository.Where(x => x.CreationTime.Date <= today && x.CreationTime.Date >= today.AddDays(-30))
+ .WhereIf(channleList.Count() > 0, x => channleList.Contains(x.ChannelId))
+ .OrderBy(o => o.CreationTime)
+ .ToListAsync();
- //}
+ var groupedStatistics = statistics
+ .GroupBy(x => x.CreationTime)
+ .Select(g => new
+ {
+ CreationTime = g.Key,
+ TotalReceiptsYesterday = g.Sum(x => x.ReceiptsYesterday),
+ TotalIncomeYesterday = g.Sum(x => x.IncomeYesterday)
+ })
+ .ToList();
+ ReceiptsListOutPut receiptsListOutPut = new ReceiptsListOutPut();
+
+ foreach (var item in groupedStatistics)
+ {
+ ReceiptsDetail receive = new ReceiptsDetail()
+ {
+ CreationTime = item.CreationTime.ToString("yyyy-MM-dd"),
+ Amount = item.TotalReceiptsYesterday
+ };
+ ReceiptsDetail income = new ReceiptsDetail()
+ {
+ CreationTime = item.CreationTime.ToString("yyyy-MM-dd"),
+ Amount = item.TotalIncomeYesterday
+ };
+ receiptsListOutPut.ReceiveList.Add(receive);
+ receiptsListOutPut.IncomeList.Add(income);
+ }
+
+ return receiptsListOutPut;
+
+ }
+
+ public async Task<ChannelDataListOutPut> GetChannelDataList(List<string> channleList)
+ {
+
+ var statistics = await _lifePayChannlesRakeRepository.Where(x => x.IsDeleted == false)
+ .WhereIf(channleList.Count() > 0, x => channleList.Contains(x.ChannelId))
+ .ToListAsync();
+ var groupedStatistics = statistics
+ .GroupBy(x => x.ChannelId)
+ .Select(g => new
+ {
+ ChannelId = g.Key,
+ ReceivePrice = g.Sum(x => x.PayAmount),
+ ChannlesRakePrice = g.Sum(x => x.ChannlesRakePrice),
+ })
+ .OrderByDescending(o => o.ReceivePrice)
+ .ToList();
+
+ ChannelDataListOutPut channelDataList = new ChannelDataListOutPut();
+
+ foreach (var item in groupedStatistics)
+ {
+ ChannelDataReceive receive = new ChannelDataReceive()
+ {
+ ChannelId = item.ChannelId,
+ ReceivePrice = item.ReceivePrice,
+ ChannlesRakePrice = item.ChannlesRakePrice,
+ };
+ if (channelDataList.ReceiveList.Count() < 5)
+ {
+ channelDataList.ReceiveList.Add(receive);
+ }
+ }
+
+ /// 绱鐢ㄦ埛
+ var users = await _lifePayUserRepository.Where(x => x.IsDeleted == false).WhereIf(channleList.Count() > 0, x => channleList.Contains(x.CreationChannleNum))
+ .ToListAsync();
+ var groupedUsers = users
+ .GroupBy(x => x.CreationChannleNum)
+ .Select(g => new
+ {
+ ChannelId = g.Key,
+ Number = g.Count(),
+ })
+ .OrderByDescending(o => o.Number)
+ .ToList();
+ foreach (var item in groupedUsers)
+ {
+ ChannelDataUserNumber usernumber = new ChannelDataUserNumber()
+ {
+ ChannelId = item.ChannelId,
+ Number = item.Number,
+ };
+ if (channelDataList.UserNumberList.Count() < 5)
+ {
+ channelDataList.UserNumberList.Add(usernumber);
+ }
+ }
+
+
+
+ return channelDataList;
+
+ }
+
private async Task<DallyStatistics> TopStatistics(string channleId, DateTime today)
{
@@ -116,6 +221,9 @@
/// 绱鏀跺叆锛氱粺璁″钩鍙拌处鎴蜂笅璁㈠崟鐘舵�佷负鈥滃凡瀹屾垚鈥濅笖璁㈠崟鍒涘缓鏃堕棿鍦ㄦ槰澶╁強涔嬪墠鏀跺埌鐨勩�愮敤鎴峰疄浠橀噾棰�-骞冲彴鎵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));
+ /// 鏄ㄦ棩鏀跺叆锛氱粺璁″钩鍙拌处鎴蜂笅璁㈠崟鐘舵�佷负鈥滃凡瀹屾垚鈥濅笖璁㈠崟鍒涘缓鏃堕棿鍦ㄦ槰澶╂敹鍒扮殑銆愮敤鎴峰疄浠橀噾棰�-骞冲彴鎵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 accumulatedOrders = await _lifePayOrderRepository.Where(x => x.CreationTime < today).WhereIf(!string.IsNullOrWhiteSpace(channleId), x => x.ChannelId == channleId).CountAsync();
/// 鏄ㄦ棩涓嬪崟锛氱粺璁″钩鍙颁腑璁㈠崟涓嬪崟鏃堕棿鍦ㄦ槰澶╃殑璁㈠崟璁板綍锛�
@@ -128,18 +236,19 @@
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.WhereIf(!string.IsNullOrWhiteSpace(channleId), x => x.CreationChannleNum == channleId).CountAsync();
+ var accumulatedUsers = await _lifePayUserRepository.Where(x => x.IsDeleted == false).WhereIf(!string.IsNullOrWhiteSpace(channleId), x => x.CreationChannleNum == channleId).CountAsync();
/// 鏄ㄦ棩娲昏穬鐢ㄦ埛
- var yesterdayActiveUsers = await _lifePayUserRepository.WhereIf(!string.IsNullOrWhiteSpace(channleId), x => x.CreationChannleNum == channleId).Where(x => x.LastLoginTime >= today.AddDays(-1)).CountAsync();
+ 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 entity = new DallyStatistics()
{
Id = GuidGenerator.Create(),
- CreationTime = DateTime.Now,
+ CreationTime = today,
Amount = 0,
AccumulatedReceipts = accumulatedReceipts ?? 0,
AccumulatedIncome = accumulatedIncome ?? 0,
+ IncomeYesterday = yesterdayIncome ?? 0,
ReceiptsYesterday = receiptsYesterday ?? 0,
AccumulatedOrders = accumulatedOrders,
OrdersNumYesterday = ordersNumYesterday,
--
Gitblit v1.9.1