LifePayment/LifePayment.Application.Contracts/LifePay/ILifePayOrderService.cs
@@ -17,4 +17,6 @@ Task<LifePayExpensesReceiptsPageOutput<LifePayExpensesReceiptsListOutput>> GetLifePayExpensesReceiptsPage(LifePayExpensesReceiptsPageInput input); Task AddLifePayExpensesReceipts(AddLifePayExpensesReceiptsInput input); Task GetAllLifePayExpensesReceipts(); } LifePayment/LifePayment.Application.Contracts/LifePay/IStatisticsService.cs
@@ -10,6 +10,6 @@ public interface IStatisticsService : IApplicationService { Task<TopStatisticsOutput> GetTopStatistics(); Task<TopStatisticsOutput> GetTopStatistics(string channleId = ""); } LifePayment/LifePayment.Application.Contracts/LifePay/LifePayInput.cs
@@ -102,6 +102,11 @@ /// 客户身份证后6位,南网必传。 /// </summary> public string SixID { get; set; } /// <summary> /// 户主姓名 /// </summary> public string Name { get; set; } } public class LifeGasData { @@ -664,16 +669,12 @@ /// <summary> /// 收支类型 /// </summary> public ExpensesReceiptsTypeEnum ExpensesReceiptsType { get; set; } public ExpensesReceiptsTypeEnum? ExpensesReceiptsType { get; set; } /// <summary> /// 交易金额 /// </summary> public decimal Amount { get; set; } /// <summary> /// 拓展属性 /// </summary> public string ExtraProperties { get; set; } } public class LifePayExpensesReceiptsPageInput : ChannelsBaseInput { @@ -701,4 +702,38 @@ /// 交易结束时间 /// </summary> public DateTime? TimeEnd { get; set; } } public class LifePayExpensesReceiptsTemp { /// <summary> /// 平台订单号 /// </summary> public string OrderNo { get; set; } /// <summary> /// 退款订单编号 /// </summary> public string RefundOrderNo { get; set; } /// <summary> /// 渠道流水号 /// </summary> public string OutOrderNo { get; set; } /// <summary> /// 支付渠道 /// </summary> public LifePayTypeEnum LifePayType { get; set; } /// <summary> /// 收支类型 /// </summary> public ExpensesReceiptsTypeEnum? ExpensesReceiptsType { get; set; } /// <summary> /// 交易金额 /// </summary> public decimal Amount { get; set; } public string ExpensesReceiptsOrder { get; set; } } LifePayment/LifePayment.Application/LifePay/LifePayOrderService.cs
@@ -21,17 +21,20 @@ { private readonly IRepository<LifePayRechargeReceipts, Guid> _lifePayRechargeReceiptsRepository; private readonly IRepository<LifePayExpensesReceipts, Guid> _lifePayExpensesReceiptsRepository; private readonly IRepository<LifePayOrder, Guid> _lifePayOrderRepository; private readonly IAliPayApi _aliPayApi; private readonly IWxPayApi _wxPayApi; public LifePayOrderService( IRepository<LifePayRechargeReceipts, Guid> lifePayRechargeReceiptsRepository, IRepository<LifePayExpensesReceipts, Guid> lifePayExpensesReceiptsRepository, IRepository<LifePayOrder, Guid> lifePayOrderRepository, IAliPayApi aliPayApi, IWxPayApi wxPayApi) { _lifePayRechargeReceiptsRepository = lifePayRechargeReceiptsRepository; _lifePayExpensesReceiptsRepository = lifePayExpensesReceiptsRepository; _lifePayOrderRepository = lifePayOrderRepository; _aliPayApi = aliPayApi; _wxPayApi = wxPayApi; } @@ -121,7 +124,7 @@ OrderNo = x.OrderNo, OutOrderNo = x.OutOrderNo, LifePayType = x.LifePayType, ExpensesReceiptsType = x.ExpensesReceiptsType, ExpensesReceiptsType = x.ExpensesReceiptsType.Value, Amount = x.Amount, FinishTime = x.FinishTime }) @@ -198,7 +201,7 @@ else { var query = await _wxPayApi.WxPayDomesticRefundsQuery(input.OrderNo); if (query.Code == AlipayResultCode.Success && query.RefundStatus == WxPayRefundStatus.退款成功) if (query.Status == WxPayRefundStatus.退款成功) { data.ExtraProperties = JsonConvert.SerializeObject(query); data.FinishTime = Convert.ToDateTime(query.SuccessTime); @@ -210,5 +213,53 @@ } } } public async Task GetAllLifePayExpensesReceipts() { var orderlist = await (from a in _lifePayOrderRepository.Where(x => x.PayStatus >= LifePayStatusEnum.已支付) join b in _lifePayExpensesReceiptsRepository on a.OrderNo equals b.OrderNo into temp from b in temp.DefaultIfEmpty() select new LifePayExpensesReceiptsTemp() { OrderNo = a.OrderNo, OutOrderNo = a.OutOrderNo, RefundOrderNo = a.RefundOrderNo, LifePayType = a.LifePayType.Value, Amount = a.PayAmount.Value, ExpensesReceiptsType = b.ExpensesReceiptsType }).ToListAsync(); foreach (var item in orderlist) { if (!item.ExpensesReceiptsType.HasValue) { /// 入账 AddLifePayExpensesReceiptsInput input = new AddLifePayExpensesReceiptsInput() { OrderNo = item.OrderNo, OutOrderNo = item.OutOrderNo, LifePayType = item.LifePayType, Amount = item.Amount, ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Expenses }; await AddLifePayExpensesReceipts(input); /// 出账 if (item.RefundOrderNo.IsNotNullOrEmpty()) { if (input.LifePayType == LifePayTypeEnum.WxPay) { input.OrderNo = item.RefundOrderNo; } input.ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Receipts; await AddLifePayExpensesReceipts(input); } } } } } } LifePayment/LifePayment.Application/LifePay/StatisticsService.cs
@@ -35,30 +35,38 @@ _dallyStatisticsRepository = dallyStatisticsRepository; } public async Task<TopStatisticsOutput> GetTopStatistics() public async Task<TopStatisticsOutput> GetTopStatistics(string channleId = "") { var today = DateTime.Now.Date; var statistics = await _dallyStatisticsRepository.Where(x => x.CreationTime.Date == today).FirstOrDefaultAsync(); var statistics = await _dallyStatisticsRepository.Where(x => x.CreationTime.Date == today) .WhereIf(string.IsNullOrWhiteSpace(channleId), x => x.Channel == channleId) .FirstOrDefaultAsync(); 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 ?? 0)); var accumulatedReceipts = await _lifePayOrderRepository.Where(x => x.CreationTime < today && x.PayStatus != LifePayStatusEnum.未支付) .WhereIf(string.IsNullOrWhiteSpace(channleId), x => x.ChannelId == channleId).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.RefundPrice ?? 0)); var receiptsYesterday = await _lifePayOrderRepository.Where(x => x.CreationTime >= today.AddDays(-1) && x.CreationTime < today && x.PayStatus == LifePayStatusEnum.已支付) .WhereIf(string.IsNullOrWhiteSpace(channleId), x => x.ChannelId == channleId).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 ?? 0) - (x.RefundPrice ?? 0)); 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 accumulatedOrders = await _lifePayOrderRepository.Where(x => x.CreationTime < today).CountAsync(); var accumulatedOrders = await _lifePayOrderRepository.Where(x => x.CreationTime < today).WhereIf(string.IsNullOrWhiteSpace(channleId), x => x.ChannelId == channleId).CountAsync(); /// 昨日下单:统计平台中订单下单时间在昨天的订单记录; var ordersNumYesterday = await _lifePayOrderRepository.Where(x => x.CreationTime >= today.AddDays(-1) && x.CreationTime < today).CountAsync(); var ordersNumYesterday = await _lifePayOrderRepository.Where(x => x.CreationTime >= today.AddDays(-1) && x.CreationTime < today) .WhereIf(string.IsNullOrWhiteSpace(channleId), x => x.ChannelId == channleId).CountAsync(); /// 昨日成功:统计平台中订单状态为“已完成/部分充值成功”且订单下单时间在昨天的订单记录; var yesterdaySuccess = await _lifePayOrderRepository.Where(x => x.CreationTime >= today.AddDays(-1) && x.CreationTime < today && x.LifePayOrderStatus == LifePayOrderStatusEnum.已完成).CountAsync(); var yesterdaySuccess = 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 yesterdayFail = await _lifePayOrderRepository.Where(x => x.CreationTime >= today.AddDays(-1) && x.CreationTime < today && x.LifePayOrderStatus == LifePayOrderStatusEnum.已退款).CountAsync(); 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.CountAsync(); var accumulatedUsers = await _lifePayUserRepository.WhereIf(string.IsNullOrWhiteSpace(channleId), x => x.CreationChannleNum == channleId).CountAsync(); /// 昨日活跃用户 var yesterdayActiveUsers = await _lifePayUserRepository.Where(x => x.LastLoginTime >= today.AddDays(-1)).CountAsync(); var yesterdayActiveUsers = await _lifePayUserRepository.WhereIf(string.IsNullOrWhiteSpace(channleId), x => x.CreationChannleNum == channleId).Where(x => x.LastLoginTime >= today.AddDays(-1)).CountAsync(); var entity = new DallyStatistics() { @@ -73,7 +81,8 @@ YesterdaySuccess = yesterdaySuccess, YesterdayFail = yesterdayFail, AccumulatedUsers = accumulatedUsers, YesterdayActiveUsers = yesterdayActiveUsers YesterdayActiveUsers = yesterdayActiveUsers, Channel = channleId }; await _dallyStatisticsRepository.InsertAsync(entity); LifePayment/LifePayment.Domain.Shared/WeChat/WxPayPostBaseModel.cs
@@ -928,8 +928,8 @@ public string TradeStateDesc { get; set; } [JsonProperty("success_time ")] public string SuccessTime { get; set; } [JsonProperty("success_time")] public string? SuccessTime { get; set; } // <summary> /// 金额信息 LifePayment/LifePayment.Domain/Common/ChannelFilter.cs
@@ -23,11 +23,8 @@ if (CurrentUser.ClientId == Constant.ClientType.Back && !CurrentUser.IsSystem) { var queryUser = UserChannleRepository.Where(r => r.UserId == CurrentUser.Id).Select(s => s.ChannleId).ToList(); if (queryUser.Count() > 0) { var queryResult = query.Where(s => (!string.IsNullOrEmpty(s.ChannelId) && queryUser.Contains(s.ChannelId)) || string.IsNullOrEmpty(s.ChannelId) || queryUser.Count() == 0); return queryResult; } var queryResult = query.Where(s => (!string.IsNullOrEmpty(s.ChannelId) && queryUser.Contains(s.ChannelId))); return queryResult; } return query; @@ -38,11 +35,8 @@ if (CurrentUser.ClientId == Constant.ClientType.Back && !CurrentUser.IsSystem) { var queryUser = UserChannleRepository.Where(r => r.UserId == CurrentUser.Id).Select(s => s.ChannleId).ToList(); if (queryUser.Count() > 0) { var queryResult = query.Where(s => (!string.IsNullOrEmpty(s.CreationChannleNum) && queryUser.Contains(s.CreationChannleNum)) || string.IsNullOrEmpty(s.CreationChannleNum)); return queryResult; } var queryResult = query.Where(s => (!string.IsNullOrEmpty(s.CreationChannleNum) && queryUser.Contains(s.CreationChannleNum))); return queryResult; } return query; LifePayment/LifePayment.Domain/LifePay/DallyStatistics.cs
@@ -62,4 +62,9 @@ /// 昨日活跃用户 /// </summary> public int YesterdayActiveUsers { get; set; } /// <summary> /// 统计渠道 /// </summary> public string Channel { get; set; } } LifePayment/LifePayment.Domain/LifePay/LifePayExpensesReceipts.cs
@@ -36,7 +36,7 @@ /// <summary> /// 收支类型 /// </summary> public ExpensesReceiptsTypeEnum ExpensesReceiptsType { get; set; } public ExpensesReceiptsTypeEnum? ExpensesReceiptsType { get; set; } /// <summary> /// 交易金额 LifePayment/LifePayment.Host/LifePaymentService.HttpApi.xml
@@ -63,7 +63,7 @@ </summary> <returns></returns> </member> <member name="M:LifePayment.HttpApi.LifePayController.GetTopStatistics"> <member name="M:LifePayment.HttpApi.LifePayController.GetTopStatistics(System.String)"> <summary> 获取顶部统计数据 </summary> LifePayment/LifePayment.Host/LifePaymentServices.Application.Contracts.xml
@@ -346,6 +346,11 @@ 客户身份证后6位,南网必传。 </summary> </member> <member name="P:LifePayment.Application.Contracts.LifeElectricData.Name"> <summary> 户主姓名 </summary> </member> <member name="P:LifePayment.Application.Contracts.LifeGasData.ParValue"> <summary> 充值面额,单位为元。 @@ -776,11 +781,6 @@ 交易金额 </summary> </member> <member name="P:LifePayment.Application.Contracts.AddLifePayExpensesReceiptsInput.ExtraProperties"> <summary> 拓展属性 </summary> </member> <member name="P:LifePayment.Application.Contracts.LifePayExpensesReceiptsPageInput.KeyWord"> <summary> 查询条件 @@ -806,6 +806,36 @@ 交易结束时间 </summary> </member> <member name="P:LifePayment.Application.Contracts.LifePayExpensesReceiptsTemp.OrderNo"> <summary> 平台订单号 </summary> </member> <member name="P:LifePayment.Application.Contracts.LifePayExpensesReceiptsTemp.RefundOrderNo"> <summary> 退款订单编号 </summary> </member> <member name="P:LifePayment.Application.Contracts.LifePayExpensesReceiptsTemp.OutOrderNo"> <summary> 渠道流水号 </summary> </member> <member name="P:LifePayment.Application.Contracts.LifePayExpensesReceiptsTemp.LifePayType"> <summary> 支付渠道 </summary> </member> <member name="P:LifePayment.Application.Contracts.LifePayExpensesReceiptsTemp.ExpensesReceiptsType"> <summary> 收支类型 </summary> </member> <member name="P:LifePayment.Application.Contracts.LifePayExpensesReceiptsTemp.Amount"> <summary> 交易金额 </summary> </member> <member name="P:LifePayment.Application.Contracts.LifePayIntroInfoInput.LifePayType"> <summary> 生活缴费类型 LifePayment/LifePayment.HttpApi/LifePay/LifePayController.cs
@@ -53,9 +53,9 @@ /// <returns></returns> [HttpGet] [AllowAnonymous] public async Task<TopStatisticsOutput> GetTopStatistics() public async Task<TopStatisticsOutput> GetTopStatistics(string channleId = "") { return await _statisticsService.GetTopStatistics(); return await _statisticsService.GetTopStatistics(channleId); } /// <summary> @@ -495,7 +495,16 @@ [AllowAnonymous] public async Task<WxPayDomesticRefundsQueryReponse> WxPayDomesticRefundsQuery(string outTradeNo) { return await _lifePayService.WxPayDomesticRefundsQuery(outTradeNo); var res = await _lifePayService.WxPayDomesticRefundsQuery(outTradeNo); await _lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput() { OrderNo = res.OutTradeNo, OutOrderNo = res.TransactionId, LifePayType = LifePayTypeEnum.WxPay, ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Expenses, Amount = Convert.ToDecimal(res.Amount.Total) }); return res; } /// <summary> @@ -519,6 +528,13 @@ return res; } [HttpGet] [AllowAnonymous] public async Task GetAllLifePayExpensesReceipts() { await _lifePayOrderService.GetAllLifePayExpensesReceipts(); } #endregion #region 操作