|  |  | 
 |  |  | using NPOI.SS.Formula.Functions; | 
 |  |  | using StackExchange.Redis; | 
 |  |  | using static Volo.Abp.Identity.Settings.IdentitySettingNames; | 
 |  |  | using static Microsoft.EntityFrameworkCore.DbLoggerCategory; | 
 |  |  |  | 
 |  |  | namespace LifePayment.Application; | 
 |  |  |  | 
 |  |  | 
 |  |  |     private readonly IRepository<LifePayChannles, Guid> _lifePayChannlesRep; | 
 |  |  |     private readonly IRepository<LifePayAccount, Guid> _lifePayAccount; | 
 |  |  |     private readonly IRepository<OperateHistory, Guid> _operateHistory; | 
 |  |  |     private readonly IRepository<LifePayChannlesRake, Guid> _lifePayChannlesRakeRepository; | 
 |  |  |     private readonly IDataFilter dataFilter; | 
 |  |  |     private readonly IChannelFilter _channelFilter; | 
 |  |  |     private readonly IAliPayApi _aliPayApi; | 
 |  |  | 
 |  |  |                           IRepository<LifePayUser, Guid> lifePayUserRepository, | 
 |  |  |                           IRepository<LifePayPremium, Guid> lifePayPremiumRepository, | 
 |  |  |                           IRepository<LifePayIntroInfo, Guid> lifePayIntroInfoRepository, | 
 |  |  |                           IRepository<LifePayChannlesRake, Guid> lifePayChannlesRakeRepository, | 
 |  |  |                           IRepository<OperateHistory, Guid> operateHistory, | 
 |  |  |                           IAliPayApi aliPayApi, | 
 |  |  |                           IAlipayInterfaceManager aliPayInterfaceManager, | 
 |  |  | 
 |  |  |         _lifePayRateRepository = lifePayRateRepository; | 
 |  |  |         _lifePayOrderRepository = lifePayOrderRepository; | 
 |  |  |         _lifePayUserRepository = lifePayUserRepository; | 
 |  |  |         _lifePayChannlesRakeRepository = lifePayChannlesRakeRepository; | 
 |  |  |         _lifePayPremiumRepository = lifePayPremiumRepository; | 
 |  |  |         _lifePayIntroInfoRepository = lifePayIntroInfoRepository; | 
 |  |  |         _aliPayApi = aliPayApi; | 
 |  |  | 
 |  |  |     public async Task<AlipayTradeQueryResponse> QueryAlipayTrade(OrderInQuiryInput input) | 
 |  |  |     { | 
 |  |  |         var result = await _aliPayApi.OrderInQuiry(input); | 
 |  |  |  | 
 |  |  |         return result; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |     public async Task<AlipayTradeFastpayRefundQueryResponse> QueryAlipayTradeRefund(OrderInQuiryInput input) | 
 |  |  |     { | 
 |  |  |         var result = await _aliPayApi.QueryAlipayTradeRefund(input); | 
 |  |  |         var order = await _lifePayOrderRepository.Where(x => x.OrderNo == input.OutTradeNo).FirstOrDefaultAsync(); | 
 |  |  |         if (result.Code == AlipayResultCode.Success && result.RefundStatus == AlipayRefundStatus.Success) | 
 |  |  |         { | 
 |  |  |             order.LifePayOrderStatus = LifePayOrderStatusEnum.已退款; | 
 |  |  |             order.LifePayRefundStatus = LifePayRefundStatusEnum.已退款; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         return result; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |     /// </summary> | 
 |  |  |     /// <param name="outTradeNo"></param> | 
 |  |  |     /// <returns></returns> | 
 |  |  |     public async Task WxPayTradeQuery(string outTradeNo) | 
 |  |  |     public async Task<WxPayTradeQueryReponse> WxPayTradeQuery(string outTradeNo) | 
 |  |  |     { | 
 |  |  |         await _wxPayApi.WxPayTradeQuery(outTradeNo); | 
 |  |  |         return await _wxPayApi.WxPayTradeQuery(outTradeNo); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |    | 
 |  |  |  | 
 |  |  |     #endregion | 
 |  |  |  | 
 |  |  | 
 |  |  |         await _lifePayOrderRepository.UpdateAsync(order); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public async Task WxPayDomesticRefundsHandler(string orderNo, LifePayRefundStatusEnum refundStatus) | 
 |  |  |     public async Task LifePayRefundsHandler(string orderNo, LifePayRefundStatusEnum refundStatus) | 
 |  |  |     { | 
 |  |  |         var order = await _lifePayOrderRepository.Where(x => x.OrderNo == orderNo).FirstOrDefaultAsync(); | 
 |  |  |         CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "订单不存在"); | 
 |  |  | 
 |  |  |             default: break; | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     /// <summary> | 
 |  |  |     /// ACOOLYO订单通知处理 | 
 |  |  | 
 |  |  |         order.ACOOLYStatus = acoolyStatus; | 
 |  |  |         order.FinishTime = DateTime.Now; | 
 |  |  |         await _lifePayOrderRepository.UpdateAsync(order); | 
 |  |  |  | 
 |  |  |         if (order.LifePayOrderStatus == LifePayOrderStatusEnum.已完成) | 
 |  |  |         { | 
 |  |  |             /// 毛利 | 
 |  |  |             var grossProfit = order.RechargeAmount * (order.ChannleRate - order.PlatformRate) / 100; | 
 |  |  |             /// 渠道佣金  ((充值面额 * 渠道折扣比例)-(充值面额 * 平台折扣比例))* 佣金比例 | 
 |  |  |             var channlesRakePrice = grossProfit * (order.ChannlesRakeRate) / 100; | 
 |  |  |             if (channlesRakePrice.HasValue) | 
 |  |  |             { | 
 |  |  |                 LifePayChannlesRake lifePayChannlesRake = new LifePayChannlesRake() | 
 |  |  |                 { | 
 |  |  |                     OrderNo = order.OrderNo, | 
 |  |  |                     PayAmount = order.PayAmount.Value, | 
 |  |  |                     ChannlesRakeRate = order.ChannlesRakeRate.Value, | 
 |  |  |                     ChannlesRakePrice = channlesRakePrice.Value, | 
 |  |  |                     FinishTime = order.FinishTime.Value, | 
 |  |  |                     ChannelId = order.ChannelId, | 
 |  |  |                 }; | 
 |  |  |                 await _lifePayChannlesRakeRepository.InsertAsync(lifePayChannlesRake); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /// <summary> | 
 |  |  | 
 |  |  |             await _lifePayAccount.InsertAsync(userAccount); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         if (input.LifePayType == LifePayOrderTypeEnum.PhoneOrder) | 
 |  |  |         if (input.LifePayType == LifePayOrderTypeEnum.PhoneOrder || input.LifePayType == LifePayOrderTypeEnum.ElectricOrder) | 
 |  |  |         { | 
 |  |  |             var extraProperties = JsonConvert.DeserializeObject<Model_UserAccountExtraProperties>(input.ExtraProperties); | 
 |  |  |             if (!string.IsNullOrEmpty(extraProperties.Name) && extraProperties.Phone == user.PhoneNumber) | 
 |  |  | 
 |  |  |         string message = $"{method}\n{uri}\n{timestamp}\n{nonce}\n{body}\n"; | 
 |  |  |         return message; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     private async Task<IQueryable<LifePayOrderListOutput>> GetLifePayOrderListFilter(QueryLifePayOrderListInput input) | 
 |  |  |     { |