|  |  | 
 |  |  |                           IRepository<LifePayUser, Guid> lifePayUserRepository, | 
 |  |  |                           IRepository<LifePayPremium, Guid> lifePayPremiumRepository, | 
 |  |  |                           IRepository<LifePayIntroInfo, Guid> lifePayIntroInfoRepository, | 
 |  |  |                           IRepository<DallyStatistics, Guid> dallyStatisticsRepository, | 
 |  |  |                           IRepository<OperateHistory, Guid> operateHistory, | 
 |  |  |                           IAliPayApi aliPayApi, | 
 |  |  |                           IAlipayInterfaceManager aliPayInterfaceManager, | 
 |  |  | 
 |  |  |         _lifePayUserRepository = lifePayUserRepository; | 
 |  |  |         _lifePayPremiumRepository = lifePayPremiumRepository; | 
 |  |  |         _lifePayIntroInfoRepository = lifePayIntroInfoRepository; | 
 |  |  |         _dallyStatisticsRepository = dallyStatisticsRepository; | 
 |  |  |         _aliPayApi = aliPayApi; | 
 |  |  |         _alipayInterfaceManager = aliPayInterfaceManager; | 
 |  |  |         _wxPayApi = wxPayApi; | 
 |  |  | 
 |  |  |  | 
 |  |  |     #region 查询 | 
 |  |  |  | 
 |  |  |     public async Task<TopStatisticsOutput> GetTopStatistics() | 
 |  |  |     { | 
 |  |  |         var today = DateTime.Now.Date; | 
 |  |  |         var statistics = await _dallyStatisticsRepository.Where(x => x.CreationTime.Date == today).FirstOrDefaultAsync(); | 
 |  |  |         if (statistics == null) | 
 |  |  |         { | 
 |  |  |             var accumulatedReceipts = await _lifePayOrderRepository.Where(x => x.CreationTime < today).SumAsync(x => x.PayAmount); | 
 |  |  |             var receiptsYesterday = await _lifePayOrderRepository.Where(x => x.CreationTime >= today.AddDays(-1) && x.CreationTime < today).SumAsync(x => x.PayAmount); | 
 |  |  |             var accumulatedOrders = await _lifePayOrderRepository.Where(x => x.CreationTime < today).CountAsync(); | 
 |  |  |             var accumulatedIncome = await _lifePayOrderRepository.Where(x => x.CreationTime < today).SumAsync(x => x.ActualRechargeAmount); | 
 |  |  |             var ordersNumYesterday = await _lifePayOrderRepository.Where(x => x.CreationTime >= today.AddDays(-1) && x.CreationTime < today).CountAsync(); | 
 |  |  |             var yesterdaySuccess = 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.已失败).CountAsync(); | 
 |  |  |             var accumulatedUsers = await _lifePayUserRepository.CountAsync(); | 
 |  |  |  | 
 |  |  |             var entity = new DallyStatistics() | 
 |  |  |             { | 
 |  |  |                 Id = GuidGenerator.Create(), | 
 |  |  |                 CreationTime = DateTime.Now, | 
 |  |  |                 Amount = 0, | 
 |  |  |                 AccumulatedReceipts = accumulatedReceipts, | 
 |  |  |                 ReceiptsYesterday = receiptsYesterday, | 
 |  |  |                 AccumulatedOrders = accumulatedOrders, | 
 |  |  |                 OrdersNumYesterday = ordersNumYesterday, | 
 |  |  |                 YesterdaySuccess = yesterdaySuccess, | 
 |  |  |                 YesterdayFail = yesterdayFail, | 
 |  |  |                 AccumulatedUsers = accumulatedUsers, | 
 |  |  |             }; | 
 |  |  |             await _dallyStatisticsRepository.InsertAsync(entity); | 
 |  |  |  | 
 |  |  |             TopStatisticsOutput topStatisticsOutput = new TopStatisticsOutput() | 
 |  |  |             { | 
 |  |  |                 Amount = entity.Amount, | 
 |  |  |                 AccumulatedReceipts = entity.AccumulatedReceipts, | 
 |  |  |                 ReceiptsYesterday = entity.ReceiptsYesterday, | 
 |  |  |                 AccumulatedOrders = entity.AccumulatedOrders, | 
 |  |  |                 OrdersNumYesterday = entity.OrdersNumYesterday, | 
 |  |  |                 YesterdaySuccess = entity.YesterdaySuccess, | 
 |  |  |                 YesterdayFail = entity.YesterdayFail, | 
 |  |  |                 AccumulatedUsers = entity.AccumulatedUsers, | 
 |  |  |             }; | 
 |  |  |             return topStatisticsOutput; | 
 |  |  |         } | 
 |  |  |         else | 
 |  |  |         { | 
 |  |  |             TopStatisticsOutput topStatisticsOutput = new TopStatisticsOutput() | 
 |  |  |             { | 
 |  |  |                 Amount = statistics.Amount, | 
 |  |  |                 AccumulatedReceipts = statistics.AccumulatedReceipts, | 
 |  |  |                 ReceiptsYesterday = statistics.ReceiptsYesterday, | 
 |  |  |                 AccumulatedOrders = statistics.AccumulatedOrders, | 
 |  |  |                 OrdersNumYesterday = statistics.OrdersNumYesterday, | 
 |  |  |                 YesterdaySuccess = statistics.YesterdaySuccess, | 
 |  |  |                 YesterdayFail = statistics.YesterdayFail, | 
 |  |  |                 AccumulatedUsers = statistics.AccumulatedUsers, | 
 |  |  |             }; | 
 |  |  |             return topStatisticsOutput; | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /// <summary> | 
 |  |  |     /// 获取电费面值 | 
 |  |  | 
 |  |  |             ChannlesRakeRate = channle.ChannlesRakeRate, | 
 |  |  |             ChannlesRakePrice = channlesRakePrice.HasValue ? 0 : Math.Round(channlesRakePrice.Value, 2), | 
 |  |  |             PremiumRate = order.PremiumRate, | 
 |  |  |             PremiumPrice = Math.Round(order.PayAmount * order.PremiumRate, 2), | 
 |  |  |             Profit = (order.PayAmount - order.PlatformDeductionAmount) * (1.00m - channle.ChannlesRakeRate / 100) - Math.Round(order.PayAmount * order.PremiumRate, 2) | 
 |  |  |             PremiumPrice = Math.Round(order.PayAmount * (order.PremiumRate.HasValue ? order.PremiumRate.Value:0), 2), | 
 |  |  |             Profit = (order.PayAmount - order.PlatformDeductionAmount) * (1.00m - channle.ChannlesRakeRate / 100) - Math.Round(order.PayAmount * (order.PremiumRate.HasValue ? order.PremiumRate.Value : 0), 2) | 
 |  |  |         }; | 
 |  |  |  | 
 |  |  |         return result; | 
 |  |  | 
 |  |  |             order.FinishTime = DateTime.Now; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         if (order.LifePayOrderStatus == LifePayOrderStatusEnum.已失败 && order.PayStatus != LifePayStatusEnum.已退款) | 
 |  |  |         if (order.LifePayOrderStatus == LifePayOrderStatusEnum.已失败 && order.LifePayRefundStatus != LifePayRefundStatusEnum.已退款) | 
 |  |  |         { | 
 |  |  |             order.PayStatus = LifePayStatusEnum.待退款; | 
 |  |  |             order.LifePayRefundStatus = LifePayRefundStatusEnum.待退款; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         order.LifePayOrderStatus = status; | 
 |  |  | 
 |  |  |         var order = await _lifePayOrderRepository.FirstOrDefaultAsync(x => x.Id == input.Id); | 
 |  |  |         CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "订单不存在"); | 
 |  |  |  | 
 |  |  |         if (order.PayStatus == LifePayStatusEnum.已退款) | 
 |  |  |         if (order.LifePayRefundStatus == LifePayRefundStatusEnum.已退款) | 
 |  |  |         { | 
 |  |  |             return; | 
 |  |  |         } | 
 |  |  | 
 |  |  |                 var wxRefundResult = await WxPayDomesticRefunds(order.OrderNo, outRefundNo,order.RefundApplyRemark, Convert.ToInt32(input.RefundPrice * 100), Convert.ToInt32(order.PayAmount * 100)); | 
 |  |  |                 if (wxRefundResult.Status == "SUCCESS") | 
 |  |  |                 { | 
 |  |  |                     order.PayStatus = LifePayStatusEnum.已退款; | 
 |  |  |                     order.LifePayOrderStatus = LifePayOrderStatusEnum.已退款; | 
 |  |  |                     order.LifePayRefundStatus = LifePayRefundStatusEnum.已退款; | 
 |  |  |                 } | 
 |  |  |                 else if (wxRefundResult.Status == "PROCESSING") | 
 |  |  |                 { | 
 |  |  |                     order.PayStatus = LifePayStatusEnum.退款中; | 
 |  |  |                     order.LifePayOrderStatus = LifePayOrderStatusEnum.退款中; | 
 |  |  |                     order.LifePayRefundStatus = LifePayRefundStatusEnum.退款中; | 
 |  |  |                 } | 
 |  |  |                 else | 
 |  |  |                 { | 
 |  |  |                     order.PayStatus = LifePayStatusEnum.待退款; | 
 |  |  |                     order.LifePayOrderStatus = LifePayOrderStatusEnum.退款失败; | 
 |  |  |                     order.LifePayRefundStatus = LifePayRefundStatusEnum.待退款; | 
 |  |  |                 } | 
 |  |  | 
 |  |  |                 { | 
 |  |  |                     throw new UserFriendlyException("退款失败"); | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 order.PayStatus = LifePayStatusEnum.已退款; | 
 |  |  |                 order.LifePayOrderStatus = LifePayOrderStatusEnum.已退款; | 
 |  |  |                 break; | 
 |  |  |             default: throw new UserFriendlyException("退款失败"); | 
 |  |  | 
 |  |  |             throw new UserFriendlyException("非用户本人退款"); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         if (order.PayStatus == LifePayStatusEnum.已退款) | 
 |  |  |         if (order.LifePayRefundStatus == LifePayRefundStatusEnum.已退款) | 
 |  |  |         { | 
 |  |  |             return; | 
 |  |  |         } | 
 |  |  | 
 |  |  |         var order = await _lifePayOrderRepository.FirstOrDefaultAsync(x => x.Id == input.Id); | 
 |  |  |         CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "订单不存在"); | 
 |  |  |  | 
 |  |  |         if (order.PayStatus == LifePayStatusEnum.已退款) | 
 |  |  |         if(order.LifePayRefundStatus == LifePayRefundStatusEnum.已退款) | 
 |  |  |         { | 
 |  |  |             return; | 
 |  |  |         } |