LifePayment/LifePayment.Application.Contracts/LifePay/IStatisticsService.cs
@@ -12,4 +12,7 @@ { Task<TopStatisticsOutput> GetTopStatistics(List<string>? channleList = null); Task<ReceiptsListOutPut> GetReceiptsList(List<string>? channleList = null); Task<ChannelDataListOutPut> GetChannelDataList(List<string>? channleList = null); } LifePayment/LifePayment.Application.Contracts/LifePay/LifePayInput.cs
@@ -593,7 +593,28 @@ public decimal Profit { get; set; } } public class LifePayConsumptionPageInput : ChannelsBaseInput { /// <summary> /// 查询条件 /// </summary> public string? KeyWord { get; set; } /// <summary> /// 资金流向 /// </summary> public ConsumptionFlowEnum? Flow { get; set; } /// <summary> /// 记账开始时间 /// </summary> public DateTime? TimeBegin { get; set; } /// <summary> /// 记账结束时间 /// </summary> public DateTime? TimeEnd { get; set; } } public class LifePayRechargeReceiptsPageInput : ChannelsBaseInput { /// <summary> LifePayment/LifePayment.Application.Contracts/LifePay/LifePayOutput.cs
@@ -1096,6 +1096,7 @@ /// </summary> public int YesterdayActiveUsers { get; set; } } public class ChannelRateOutput @@ -1150,6 +1151,54 @@ /// 记账时间 /// </summary> public DateTime CreationTime { get; set; } } public class LifePayConsumptionListOutput { /// <summary> /// 编号 /// </summary> public Guid Id { get; set; } // <summary> /// 平台订单号 /// </summary> public string OrderNo { get; set; } /// <summary> /// 渠道流水号 /// </summary> public string OutOrderNo { get; set; } /// <summary> /// 交易金额 /// </summary> public decimal Amount { get; set; } /// <summary> /// 记账时间 /// </summary> public DateTime FinishTime { get; set; } /// <summary> /// 冻结状态 /// </summary> public ConsumptionFrozenStatusEnum FrozenStatus { get; set; } /// <summary> /// 资金流向 /// </summary> public ConsumptionFlowEnum Flow { get; set; } /// <summary> /// 扣款金额 /// </summary> public decimal DeductionAmount { get; set; } /// <summary> /// 冻结金额 /// </summary> public decimal FrozenAmount { get; set; } } public class LifePayPhoneMesssageCodeLoginOutput @@ -1262,13 +1311,77 @@ public class ReceiptsListOutPut { /// <summary> /// 30天收款 /// </summary> public List<ReceiptsDetail> ReceiveList { get; set; } = new List<ReceiptsDetail>(); /// <summary> /// 30天收入 /// </summary> public List<ReceiptsDetail> IncomeList { get; set; } = new List<ReceiptsDetail>(); } public class ReceiptsDetail { /// <summary> /// 创建时间 /// </summary> public DateTime CreationTime { get; set; } public string CreationTime { get; set; } /// <summary> /// 金额 /// </summary> public decimal Amount { get; set; } } public class ChannelDataListOutPut { /// <summary> /// Top5渠道收款 /// </summary> public List<ChannelDataReceive> ReceiveList { get; set; } = new List<ChannelDataReceive>(); /// <summary> /// Top5渠道用户 /// </summary> public List<ChannelDataUserNumber> UserNumberList { get; set; } = new List<ChannelDataUserNumber>(); } public class ChannelDataReceive { /// <summary> /// 渠道编号 /// </summary> public string ChannelId { get; set; } /// <summary> /// 收款 /// </summary> public decimal ReceivePrice { get; set; } /// <summary> /// 佣金 /// </summary> public decimal ChannlesRakePrice { get; set; } } public class ChannelDataUserNumber { /// <summary> /// 渠道编号 /// </summary> public string ChannelId { get; set; } /// <summary> /// 用户数量 /// </summary> public int Number { get; set; } } public class LifePayChannlesRakeListOutput { LifePayment/LifePayment.Application.Contracts/User/QrCodeLogin.cs
@@ -89,7 +89,7 @@ public string[] RoleNames { get; set; } /// <summary> /// 渠道列表 /// 渠道编号 /// </summary> public string[] ChannlesId { get; set; } LifePayment/LifePayment.Application/LifePay/LifePayOrderService.cs
@@ -23,6 +23,7 @@ { private readonly IRepository<LifePayRechargeReceipts, Guid> _lifePayRechargeReceiptsRepository; private readonly IRepository<LifePayExpensesReceipts, Guid> _lifePayExpensesReceiptsRepository; private readonly IRepository<LifePayConsumption, Guid> _lifePayConsumption; private readonly IRepository<LifePayChannlesRake, Guid> _lifePayChannlesRakeRepository; private readonly IRepository<LifePayOrder, Guid> _lifePayOrderRepository; private readonly IAliPayApi _aliPayApi; @@ -31,6 +32,7 @@ public LifePayOrderService( IRepository<LifePayRechargeReceipts, Guid> lifePayRechargeReceiptsRepository, IRepository<LifePayExpensesReceipts, Guid> lifePayExpensesReceiptsRepository, IRepository<LifePayConsumption, Guid> lifePayConsumptionRepository, IRepository<LifePayChannlesRake, Guid> lifePayChannlesRakeRepository, IRepository<LifePayOrder, Guid> lifePayOrderRepository, IAliPayApi aliPayApi, @@ -38,6 +40,7 @@ { _lifePayRechargeReceiptsRepository = lifePayRechargeReceiptsRepository; _lifePayExpensesReceiptsRepository = lifePayExpensesReceiptsRepository; _lifePayConsumption = lifePayConsumptionRepository; _lifePayChannlesRakeRepository = lifePayChannlesRakeRepository; _lifePayOrderRepository = lifePayOrderRepository; _aliPayApi = aliPayApi; @@ -45,6 +48,39 @@ } #region 查询 /// <summary> /// 获取消费流水 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task<PageOutput<LifePayConsumptionListOutput>> GetLifePayConsumptionPage(LifePayConsumptionPageInput input) { var list = await _lifePayConsumption.Where(x => x.IsDeleted == false) .WhereIf(input.KeyWord.IsNotNullOrEmpty(), x => x.OrderNo.Contains(input.KeyWord) || x.OutOrderNo.Contains(input.KeyWord) || x.ChannelId.Contains(input.KeyWord)) .WhereIf(input.Flow.HasValue,x => x.Flow == input.Flow) .WhereIf(input.TimeBegin.HasValue, x => x.FinishTime >= input.TimeBegin) .WhereIf(input.TimeEnd.HasValue, x => x.FinishTime <= input.TimeEnd) .Select(x => new LifePayConsumptionListOutput() { Id = x.Id, OrderNo = x.OrderNo, OutOrderNo = x.OutOrderNo, Amount = x.Amount, FinishTime = x.FinishTime, FrozenStatus = x.FrozenStatus, Flow = x.Flow, DeductionAmount = x.DeductionAmount, }) .GetPageResult(input.PageModel); var total = await _lifePayRechargeReceiptsRepository.Where(x => x.IsDeleted == false).SumAsync(x => x.RechargeAmount); LifePayRechargeReceiptsStatistics objectData = new LifePayRechargeReceiptsStatistics(); objectData.TotalRechargeAmount = total; list.ObjectData = objectData; return list; } /// <summary> /// 获取充值流水 /// </summary> 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 @@ /// 累计收入:统计平台账户下订单状态为“已完成”且订单创建时间在昨天及之前收到的【用户实付金额-平台扣款金额-部分退款金额】; 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 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, LifePayment/LifePayment.Domain.Shared/Enum/LifePay/LifePayEnum.cs
@@ -196,5 +196,21 @@ [Description("支出")] Receipts = 20, } public enum ConsumptionFrozenStatusEnum { [Description("冻结")] Frozen = 10, [Description("解冻")] Thaw = 20, } public enum ConsumptionFlowEnum { [Description("不变")] Unchanged = 10, [Description("出金")] Out = 20, } LifePayment/LifePayment.Domain/LifePay/DallyStatistics.cs
@@ -34,6 +34,11 @@ public decimal AccumulatedIncome { get; set; } /// <summary> /// 昨日收入 /// </summary> public decimal IncomeYesterday { get; set; } /// <summary> /// 累计下单 /// </summary> public int AccumulatedOrders { get; set; } LifePayment/LifePayment.Domain/LifePay/LifePayConsumption.cs
New file @@ -0,0 +1,72 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Volo.Abp.Domain.Entities.Auditing; using Volo.Abp; using LifePayment.Domain.Shared; namespace LifePayment.Domain.LifePay { /// <summary> /// 消费流水 /// </summary> public class LifePayConsumption : FullAuditedEntity<Guid>, IDataUserFilter { public LifePayConsumption() { } /// <summary> /// 平台订单号 /// </summary> public string OrderNo { get; set; } /// <summary> /// 渠道流水号 /// </summary> public string OutOrderNo { get; set; } /// <summary> /// 交易金额 /// </summary> public decimal Amount { get; set; } /// <summary> /// 记账时间 /// </summary> public DateTime FinishTime { get; set; } /// <summary> /// 拓展属性 /// </summary> public string ExtraProperties { get; set; } /// <summary> /// 冻结状态 /// </summary> public ConsumptionFrozenStatusEnum FrozenStatus { get; set; } /// <summary> /// 资金流向 /// </summary> public ConsumptionFlowEnum Flow { get; set; } /// <summary> /// 扣款金额 /// </summary> public decimal DeductionAmount { get; set; } /// <summary> /// 冻结金额 /// </summary> public decimal? FrozenAmount { get; set; } /// <summary> /// 渠道号 /// </summary> public string ChannelId { get; set; } } } LifePayment/LifePayment.EntityFrameworkCore/LifePaymentServicesDbContext.cs
@@ -25,6 +25,8 @@ public virtual DbSet<LifePayPremium> LifePayPremium { get; set; } public virtual DbSet<LifePayConsumption> LifePayConsumption { get; set; } public virtual DbSet<LifePayRechargeReceipts> LifePayRechargeReceipts { get; set; } public virtual DbSet<LifePayExpensesReceipts> LifePayExpensesReceipts { 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.GetReceiptsList(LifePayment.Application.Contracts.TopStatisticsInput)"> <summary> 获取30日收款统计 </summary> <param name="input"></param> <returns></returns> </member> <member name="M:LifePayment.HttpApi.LifePayController.GetElectricParValue(LifePayment.Domain.Shared.ChannelsBaseInput)"> <summary> 获取电费面值 LifePayment/LifePayment.Host/LifePaymentServices.Application.Contracts.xml
@@ -724,6 +724,26 @@ 利润 </summary> </member> <member name="P:LifePayment.Application.Contracts.LifePayConsumptionPageInput.KeyWord"> <summary> 查询条件 </summary> </member> <member name="P:LifePayment.Application.Contracts.LifePayConsumptionPageInput.Flow"> <summary> 资金流向 </summary> </member> <member name="P:LifePayment.Application.Contracts.LifePayConsumptionPageInput.TimeBegin"> <summary> 记账开始时间 </summary> </member> <member name="P:LifePayment.Application.Contracts.LifePayConsumptionPageInput.TimeEnd"> <summary> 记账结束时间 </summary> </member> <member name="P:LifePayment.Application.Contracts.LifePayRechargeReceiptsPageInput.KeyWord"> <summary> 查询条件 @@ -1759,6 +1779,47 @@ 记账时间 </summary> </member> <member name="P:LifePayment.Application.Contracts.LifePayConsumptionListOutput.Id"> <summary> 编号 </summary> </member> <!-- Badly formed XML comment ignored for member "P:LifePayment.Application.Contracts.LifePayConsumptionListOutput.OrderNo" --> <member name="P:LifePayment.Application.Contracts.LifePayConsumptionListOutput.OutOrderNo"> <summary> 渠道流水号 </summary> </member> <member name="P:LifePayment.Application.Contracts.LifePayConsumptionListOutput.Amount"> <summary> 交易金额 </summary> </member> <member name="P:LifePayment.Application.Contracts.LifePayConsumptionListOutput.FinishTime"> <summary> 记账时间 </summary> </member> <member name="P:LifePayment.Application.Contracts.LifePayConsumptionListOutput.FrozenStatus"> <summary> 冻结状态 </summary> </member> <member name="P:LifePayment.Application.Contracts.LifePayConsumptionListOutput.Flow"> <summary> 资金流向 </summary> </member> <member name="P:LifePayment.Application.Contracts.LifePayConsumptionListOutput.DeductionAmount"> <summary> 扣款金额 </summary> </member> <member name="P:LifePayment.Application.Contracts.LifePayConsumptionListOutput.FrozenAmount"> <summary> 冻结金额 </summary> </member> <member name="P:LifePayment.Application.Contracts.LifePayPhoneMesssageCodeLoginOutput.UserId"> <summary> 用户Id @@ -1839,9 +1900,59 @@ 合计佣金 </summary> </member> <member name="P:LifePayment.Application.Contracts.ReceiptsListOutPut.CreationTime"> <member name="P:LifePayment.Application.Contracts.ReceiptsListOutPut.ReceiveList"> <summary> 30天收款 </summary> </member> <member name="P:LifePayment.Application.Contracts.ReceiptsListOutPut.IncomeList"> <summary> 30天收入 </summary> </member> <member name="P:LifePayment.Application.Contracts.ReceiptsDetail.CreationTime"> <summary> 创建时间 </summary> </member> <member name="P:LifePayment.Application.Contracts.ReceiptsDetail.Amount"> <summary> 金额 </summary> </member> <member name="P:LifePayment.Application.Contracts.ChannelDataListOutPut.ReceiveList"> <summary> Top5渠道收款 </summary> </member> <member name="P:LifePayment.Application.Contracts.ChannelDataListOutPut.UserNumberList"> <summary> Top5渠道用户 </summary> </member> <member name="P:LifePayment.Application.Contracts.ChannelDataReceive.ChannelId"> <summary> 渠道编号 </summary> </member> <member name="P:LifePayment.Application.Contracts.ChannelDataReceive.ReceivePrice"> <summary> 收款 </summary> </member> <member name="P:LifePayment.Application.Contracts.ChannelDataReceive.ChannlesRakePrice"> <summary> 佣金 </summary> </member> <member name="P:LifePayment.Application.Contracts.ChannelDataUserNumber.ChannelId"> <summary> 渠道编号 </summary> </member> <member name="P:LifePayment.Application.Contracts.ChannelDataUserNumber.Number"> <summary> 用户数量 </summary> </member> <member name="P:LifePayment.Application.Contracts.LifePayChannlesRakeListOutput.Id"> @@ -2839,7 +2950,7 @@ </member> <member name="P:LifePayment.Application.Contracts.CreateAccountInput.ChannlesId"> <summary> 渠道列表 渠道编号 </summary> </member> <member name="P:LifePayment.Application.Contracts.CreateAccountInput.OpenId"> LifePayment/LifePayment.HttpApi/LifePay/LifePayController.cs
@@ -61,6 +61,25 @@ } /// <summary> /// 获取30日收款统计 /// </summary> /// <param name="input"></param> /// <returns></returns> [HttpPost] [AllowAnonymous] public async Task<ReceiptsListOutPut> GetReceiptsList(TopStatisticsInput input) { return await _statisticsService.GetReceiptsList(input.ChannleList); } [HttpPost] [AllowAnonymous] public async Task<ChannelDataListOutPut> GetChannelDataList(TopStatisticsInput input) { return await _statisticsService.GetChannelDataList(input.ChannleList); } /// <summary> /// 获取电费面值 /// </summary> /// <returns></returns>