|  |  | 
 |  |  | using NPOI.SS.Formula.Functions; | 
 |  |  | using StackExchange.Redis; | 
 |  |  | using static Volo.Abp.Identity.Settings.IdentitySettingNames; | 
 |  |  | using static Microsoft.EntityFrameworkCore.DbLoggerCategory; | 
 |  |  | using LifePayment.Application.LifePay; | 
 |  |  | using Alipay.AopSdk.Core.Domain; | 
 |  |  |  | 
 |  |  | 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 ILifePayOrderService _lifePayOrderService; | 
 |  |  |     private readonly IDataFilter dataFilter; | 
 |  |  |     private readonly IChannelFilter _channelFilter; | 
 |  |  |     private readonly IAliPayApi _aliPayApi; | 
 |  |  |     private readonly IAlipayInterfaceManager _alipayInterfaceManager; | 
 |  |  |     private readonly IWxPayApi _wxPayApi; | 
 |  |  |     private readonly WxPayOption _wxPayOptions; | 
 |  |  |     private readonly InitSetting _initSettingOptions; | 
 |  |  |  | 
 |  |  |     private readonly IACOOLYManager _aCOOLYManager; | 
 |  |  |  | 
 |  |  | 
 |  |  |                           IRepository<LifePayUser, Guid> lifePayUserRepository, | 
 |  |  |                           IRepository<LifePayPremium, Guid> lifePayPremiumRepository, | 
 |  |  |                           IRepository<LifePayIntroInfo, Guid> lifePayIntroInfoRepository, | 
 |  |  |                           IRepository<LifePayChannlesRake, Guid> lifePayChannlesRakeRepository, | 
 |  |  |                           IRepository<OperateHistory, Guid> operateHistory, | 
 |  |  |                           ILifePayOrderService lifePayOrderService, | 
 |  |  |                           IAliPayApi aliPayApi, | 
 |  |  |                           IAlipayInterfaceManager aliPayInterfaceManager, | 
 |  |  |                           IWxPayApi wxPayApi, | 
 |  |  |                           IOptions<WxPayOption> wxPayOptions, | 
 |  |  |                           IOptions<InitSetting> initSettingOptions, | 
 |  |  |                           IRepository<LifePayChannles, Guid> lifePayChannlesRep, | 
 |  |  |                           IRepository<LifePayAccount, Guid> lifePayAccount, | 
 |  |  |                           IDataFilter dataFilter, | 
 |  |  | 
 |  |  |         _lifePayRateRepository = lifePayRateRepository; | 
 |  |  |         _lifePayOrderRepository = lifePayOrderRepository; | 
 |  |  |         _lifePayUserRepository = lifePayUserRepository; | 
 |  |  |         _lifePayChannlesRakeRepository = lifePayChannlesRakeRepository; | 
 |  |  |         _lifePayPremiumRepository = lifePayPremiumRepository; | 
 |  |  |         _lifePayIntroInfoRepository = lifePayIntroInfoRepository; | 
 |  |  |         _aliPayApi = aliPayApi; | 
 |  |  |         _lifePayOrderService = lifePayOrderService; | 
 |  |  |         _alipayInterfaceManager = aliPayInterfaceManager; | 
 |  |  |         _wxPayApi = wxPayApi; | 
 |  |  |         _wxPayOptions = wxPayOptions.Value; | 
 |  |  |         _initSettingOptions = initSettingOptions.Value; | 
 |  |  |         _distributedEventBus = distributedEventBus; | 
 |  |  |         _lifePayChannlesRep = lifePayChannlesRep; | 
 |  |  |         _lifePayAccount = lifePayAccount; | 
 |  |  | 
 |  |  |             .WhereIf(!string.IsNullOrEmpty(input.QueryCondition), x => x.PhoneNumber.Contains(input.QueryCondition) || x.Name.Contains(input.QueryCondition)) | 
 |  |  |             .WhereIf(input.CreationTimeBegin.HasValue, x => x.CreationTime >= input.CreationTimeBegin) | 
 |  |  |             .WhereIf(input.CreationTimeEnd.HasValue, x => x.CreationTime <= input.CreationTimeEnd) | 
 |  |  |             .WhereIf(input.LoginTimeBegin.HasValue, x => x.LastLoginTime >= input.LoginTimeBegin) | 
 |  |  |             .WhereIf(input.LoginTimeEnd.HasValue, x => x.LastLoginTime <= input.LoginTimeEnd) | 
 |  |  |                                             .Select(x => | 
 |  |  |                                                    new UserListOutput() | 
 |  |  |                                                    { | 
 |  |  | 
 |  |  |                             from b in temp.DefaultIfEmpty() | 
 |  |  |                             select new LifePayOrderListOutput | 
 |  |  |                             { | 
 |  |  |                                 DiscountAmount = a.DiscountAmount, | 
 |  |  |                                 DiscountAmount = a.DiscountAmount ?? 0, | 
 |  |  |                                 FinishTime = a.FinishTime, | 
 |  |  |                                 Id = a.Id, | 
 |  |  |                                 LifePayOrderStatus = a.LifePayOrderStatus, | 
 |  |  |                                 LifePayOrderStatus = a.LifePayOrderStatus?? 0, | 
 |  |  |                                 LifePayOrderType = a.LifePayOrderType, | 
 |  |  |                                 LifePayType = a.LifePayType, | 
 |  |  |                                 OrderNo = a.OrderNo, | 
 |  |  |                                 PayAmount = a.PayAmount, | 
 |  |  |                                 PayAmount = a.PayAmount ?? 0, | 
 |  |  |                                 PhoneNumber = a.PhoneNumber, | 
 |  |  |                                 RechargeAmount = a.RechargeAmount, | 
 |  |  |                                 RechargeAmount = a.RechargeAmount??0, | 
 |  |  |                                 UserId = a.UserId, | 
 |  |  |                                 OutOrderNo = a.OutOrderNo, | 
 |  |  |                                 PayStatus = a.PayStatus, | 
 |  |  |                                 PayStatus = a.PayStatus?? 0, | 
 |  |  |                                 PayTime = a.PayTime, | 
 |  |  |                                 ACOOLYOrderNo = a.ACOOLYOrderNo, | 
 |  |  |                                 RefundCredentialsImgUrl = a.RefundCredentialsImgUrl.GetOssPath(), | 
 |  |  | 
 |  |  |                                             .WhereIf(input.ACOOLYStatus.HasValue, x => x.ACOOLYStatus == input.ACOOLYStatus.Value) | 
 |  |  |                                             .WhereIf(input.LifePayOrderType.HasValue, x => x.LifePayOrderType == input.LifePayOrderType.Value) | 
 |  |  |                                             .WhereIf(input.UserId.HasValue, x => x.UserId == input.UserId.Value) | 
 |  |  |                                             .WhereIf(input.KeyWords.IsNotNullOrEmpty(), x => x.PhoneNumber.Contains(input.KeyWords) || x.OrderNo.Contains(input.KeyWords) || x.OutOrderNo.Contains(input.KeyWords) || x.ACOOLYOrderNo.Contains(input.KeyWords)) | 
 |  |  |                                             .WhereIf(input.KeyWords.IsNotNullOrEmpty(), x => x.PhoneNumber.Contains(input.KeyWords) || x.RefundOrderNo.Contains(input.KeyWords) || x.OutOrderNo.Contains(input.KeyWords) || x.ACOOLYOrderNo.Contains(input.KeyWords)) | 
 |  |  |                             join b in _lifePayChannlesRep on a.ChannelId equals b.ChannlesNum into temp | 
 |  |  |                             from b in temp.DefaultIfEmpty() | 
 |  |  |                             select new LifePayOrderListOutput | 
 |  |  |                             { | 
 |  |  |                                 DiscountAmount = a.DiscountAmount, | 
 |  |  |                                 DiscountAmount = a.DiscountAmount ?? 0, | 
 |  |  |                                 FinishTime = a.FinishTime, | 
 |  |  |                                 Id = a.Id, | 
 |  |  |                                 LifePayOrderStatus = a.LifePayOrderStatus, | 
 |  |  |                                 LifePayOrderStatus = a.LifePayOrderStatus ?? 0, | 
 |  |  |                                 LifePayOrderType = a.LifePayOrderType, | 
 |  |  |                                 LifePayType = a.LifePayType, | 
 |  |  |                                 OrderNo = a.OrderNo, | 
 |  |  |                                 PayAmount = a.PayAmount, | 
 |  |  |                                 PayAmount = a.PayAmount ?? 0, | 
 |  |  |                                 PhoneNumber = a.PhoneNumber, | 
 |  |  |                                 RechargeAmount = a.RechargeAmount, | 
 |  |  |                                 RechargeAmount = a.RechargeAmount ?? 0, | 
 |  |  |                                 UserId = a.UserId, | 
 |  |  |                                 OutOrderNo = a.OutOrderNo, | 
 |  |  |                                 PayStatus = a.PayStatus, | 
 |  |  |                                 PayStatus = a.PayStatus ?? 0, | 
 |  |  |                                 PayTime = a.PayTime, | 
 |  |  |                                 ACOOLYOrderNo = a.ACOOLYOrderNo, | 
 |  |  |                                 RefundCredentialsImgUrl = a.RefundCredentialsImgUrl.GetOssPath(), | 
 |  |  | 
 |  |  |         var channle = await _lifePayChannlesRep.FirstOrDefaultAsync(r => r.ChannlesNum == order.ChannelId); | 
 |  |  |         CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "订单不存在"); | 
 |  |  |         var user = await _lifePayUserRepository.FirstOrDefaultAsync(x => x.Id == order.UserId); | 
 |  |  |         var channlesRakePrice = (order.PayAmount - (order.PlatformDeductionAmount == null ? 0 : order.PlatformDeductionAmount)) * channle.ChannlesRakeRate / 100; | 
 |  |  |         var orderpirce = await GetOrderPrice(order.RechargeAmount, order.PayAmount, order.PlatformRate, order.ChannleRate, order.ChannlesRakeRate, order.PremiumRate); | 
 |  |  |  | 
 |  |  |         CheckExtensions.IfTrueThrowUserFriendlyException(user == null, "用户不存在"); | 
 |  |  |         var orderpirce = await GetOrderPrice(order.RechargeAmount ?? 0, order.PayAmount ?? 0, order.PlatformRate ?? 0, order.ChannleRate ?? 0, order.ChannlesRakeRate ?? 0, order.PremiumRate ?? 0); | 
 |  |  |  | 
 |  |  |         var result = new LifePayOrderOutput() | 
 |  |  |         { | 
 |  |  |             UserName = user.Name, | 
 |  |  |             UserPhoneNumber = user.PhoneNumber, | 
 |  |  |             DiscountAmount = order.DiscountAmount, | 
 |  |  |             DiscountAmount = order.DiscountAmount ?? 0, | 
 |  |  |             FinishTime = order.FinishTime, | 
 |  |  |             Id = order.Id, | 
 |  |  |             OutOrderNo = order.OutOrderNo, | 
 |  |  |             LifePayChannle = channle.ChannlesName, | 
 |  |  |             Status = order.LifePayOrderStatus, | 
 |  |  |             Status = order.LifePayOrderStatus ?? 0, | 
 |  |  |             LifePayOrderType = order.LifePayOrderType, | 
 |  |  |             LifePayType = order.LifePayType, | 
 |  |  |             OrderNo = order.OrderNo, | 
 |  |  |             PayAmount = order.PayAmount, | 
 |  |  |             RechargeAmount = order.RechargeAmount, | 
 |  |  |             PayStatus = order.PayStatus, | 
 |  |  |             PayAmount = order.PayAmount ?? 0, | 
 |  |  |             RechargeAmount = order.RechargeAmount ?? 0, | 
 |  |  |             PayStatus = order.PayStatus ?? 0, | 
 |  |  |             PayTime = order.PayTime, | 
 |  |  |             OrderParamDetailJsonStr = order.OrderParamDetailJsonStr, | 
 |  |  |             RefundCredentialsImgUrl = order.RefundCredentialsImgUrl.GetOssPath(), | 
 |  |  | 
 |  |  |             ChannlesRakePrice = orderpirce.ChannlesRakePrice, | 
 |  |  |             PremiumRate = order.PremiumRate, | 
 |  |  |             PremiumPrice = orderpirce.PremiumPrice, | 
 |  |  |             Profit = orderpirce.Profit | 
 |  |  |             Profit = orderpirce.Profit, | 
 |  |  |             RefundOrderNo = order.RefundOrderNo, | 
 |  |  |         }; | 
 |  |  |  | 
 |  |  |         return result; | 
 |  |  | 
 |  |  |         { | 
 |  |  |             UserName = user.Name, | 
 |  |  |             UserPhoneNumber = user.PhoneNumber, | 
 |  |  |             DiscountAmount = order.DiscountAmount, | 
 |  |  |             DiscountAmount = order.DiscountAmount ?? 0, | 
 |  |  |             FinishTime = order.FinishTime, | 
 |  |  |             Id = order.Id, | 
 |  |  |             OutOrderNo = order.OutOrderNo, | 
 |  |  |             LifePayChannle = channle.ChannlesName, | 
 |  |  |             Status = order.LifePayOrderStatus, | 
 |  |  |             Status = order.LifePayOrderStatus ?? 0, | 
 |  |  |             LifePayOrderType = order.LifePayOrderType, | 
 |  |  |             LifePayType = order.LifePayType, | 
 |  |  |             OrderNo = order.OrderNo, | 
 |  |  |             PayAmount = order.PayAmount, | 
 |  |  |             RechargeAmount = order.RechargeAmount, | 
 |  |  |             PayStatus = order.PayStatus, | 
 |  |  |             PayAmount = order.PayAmount ?? 0, | 
 |  |  |             RechargeAmount = order.RechargeAmount ?? 0, | 
 |  |  |             PayStatus = order.PayStatus ?? 0, | 
 |  |  |             PayTime = order.PayTime, | 
 |  |  |             RefundCredentialsImgUrl = order.RefundCredentialsImgUrl.GetOssPath(), | 
 |  |  |             CreationTime = order.CreationTime, | 
 |  |  | 
 |  |  |                                             .Select(x => | 
 |  |  |                                                     new UserLifePayOrderOutput | 
 |  |  |                                                     { | 
 |  |  |                                                         DiscountAmount = x.DiscountAmount, | 
 |  |  |                                                         DiscountAmount = x.DiscountAmount ?? 0, | 
 |  |  |                                                         FinishTime = x.FinishTime, | 
 |  |  |                                                         Id = x.Id, | 
 |  |  |                                                         LifePayOrderStatus = x.LifePayOrderStatus, | 
 |  |  |                                                         LifePayOrderStatus = x.LifePayOrderStatus ?? 0, | 
 |  |  |                                                         LifePayOrderType = x.LifePayOrderType, | 
 |  |  |                                                         LifePayType = x.LifePayType, | 
 |  |  |                                                         OrderNo = x.OrderNo, | 
 |  |  |                                                         PayAmount = x.PayAmount, | 
 |  |  |                                                         RechargeAmount = x.RechargeAmount, | 
 |  |  |                                                         PayStatus = x.PayStatus, | 
 |  |  |                                                         PayAmount = x.PayAmount ?? 0, | 
 |  |  |                                                         RechargeAmount = x.RechargeAmount ?? 0, | 
 |  |  |                                                         PayStatus = x.PayStatus ?? 0, | 
 |  |  |                                                         PayTime = x.PayTime, | 
 |  |  |                                                         OrderParamDetailJsonStr = x.OrderParamDetailJsonStr, | 
 |  |  |                                                         RefundCredentialsImgUrl = x.RefundCredentialsImgUrl.GetOssPath(), | 
 |  |  | 
 |  |  |                                             .Select(x => | 
 |  |  |                                                     new UserLifePayOrderOutput | 
 |  |  |                                                     { | 
 |  |  |                                                         DiscountAmount = x.DiscountAmount, | 
 |  |  |                                                         DiscountAmount = x.DiscountAmount ?? 0, | 
 |  |  |                                                         FinishTime = x.FinishTime, | 
 |  |  |                                                         Id = x.Id, | 
 |  |  |                                                         LifePayOrderStatus = x.LifePayOrderStatus, | 
 |  |  |                                                         LifePayOrderStatus = x.LifePayOrderStatus?? 0 , | 
 |  |  |                                                         LifePayOrderType = x.LifePayOrderType, | 
 |  |  |                                                         LifePayType = x.LifePayType, | 
 |  |  |                                                         OrderNo = x.OrderNo, | 
 |  |  |                                                         PayAmount = x.PayAmount, | 
 |  |  |                                                         RechargeAmount = x.RechargeAmount, | 
 |  |  |                                                         PayStatus = x.PayStatus, | 
 |  |  |                                                         PayAmount = x.PayAmount ?? 0, | 
 |  |  |                                                         RechargeAmount = x.RechargeAmount ?? 0, | 
 |  |  |                                                         PayStatus = x.PayStatus ?? 0, | 
 |  |  |                                                         PayTime = x.PayTime, | 
 |  |  |                                                         OrderParamDetailJsonStr = x.OrderParamDetailJsonStr, | 
 |  |  |                                                         RefundCredentialsImgUrl = x.RefundCredentialsImgUrl.GetOssPath(), | 
 |  |  | 
 |  |  |     public async Task<LifePayStatusEnum> GetPayStatusByOrderNo(string orderNo) | 
 |  |  |     { | 
 |  |  |         return await _lifePayOrderRepository.Where(x => x.OrderNo == orderNo) | 
 |  |  |                                             .Select(x => x.PayStatus) | 
 |  |  |                                             .Select(x => x.PayStatus ?? 0) | 
 |  |  |                                             .FirstOrDefaultAsync(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |         return await GetLifePayChannlesListFilter().GetPageResult(input.PageModel); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public async Task<List<CreateEditPayChannelsInput>> GetLifePayChannlesAllList() | 
 |  |  |     public async Task<List<CreateEditPayChannelsInput>> GetLifePayChannlesAllList(QueryLifePayChannlesInput input) | 
 |  |  |     { | 
 |  |  |         return await GetLifePayChannlesListFilter().Where(x => x.Status == LifePayChannelsStatsEnum.启用).ToListAsync(); | 
 |  |  |         return await GetLifePayChannlesListFilter().WhereIf(input.Status.HasValue,x => x.Status == input.Status).ToListAsync(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public async Task<CreateEditPayChannelsInput> GetLifePayChannlesDto(Guid id) | 
 |  |  | 
 |  |  |                                                         OrderNo = x.OrderNo, | 
 |  |  |                                                         RefundCheckRemark = x.RefundCheckRemark, | 
 |  |  |                                                         RefundApplyRemark = x.RefundApplyRemark, | 
 |  |  |                                                         LifePayOrderStatus = x.LifePayOrderStatus, | 
 |  |  |                                                         LifePayOrderStatus = x.LifePayOrderStatus ?? 0, | 
 |  |  |                                                     }).FirstOrDefaultAsync(); | 
 |  |  |  | 
 |  |  |         CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "未找到订单信息"); | 
 |  |  | 
 |  |  |             return ""; | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /// <summary> | 
 |  |  |     /// 查询支付宝支付订单信息 | 
 |  |  |     /// </summary> | 
 |  |  |     /// <param name="input"></param> | 
 |  |  |     /// <returns></returns> | 
 |  |  |     public async Task<AlipayTradeQueryResponse> QueryAlipayTrade(OrderInQuiryInput input) | 
 |  |  |     { | 
 |  |  |         var result = await _aliPayApi.OrderInQuiry(input); | 
 |  |  |  | 
 |  |  |         return result; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /// <summary> | 
 |  |  |     /// 查询支付宝退款订单信息 | 
 |  |  |     /// </summary> | 
 |  |  |     /// <param name="input"></param> | 
 |  |  |     /// <returns></returns> | 
 |  |  |     public async Task<AlipayTradeFastpayRefundQueryResponse> QueryAlipayTradeRefund(OrderInQuiryInput input) | 
 |  |  |     { | 
 |  |  |         var order = await _lifePayOrderRepository.Where(x => x.OrderNo == input.OutTradeNo || x.RefundOrderNo == input.OutRefundNo).FirstOrDefaultAsync(); | 
 |  |  |         CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "未找到订单信息"); | 
 |  |  |         input.OutTradeNo = order.OrderNo; | 
 |  |  |         input.OutRefundNo = order.RefundOrderNo; | 
 |  |  |         var result = await _aliPayApi.QueryAlipayTradeRefund(input); | 
 |  |  |         if (result.Code == AlipayResultCode.Success && result.RefundStatus == AlipayRefundStatus.Success) | 
 |  |  |         { | 
 |  |  |             order.LifePayOrderStatus = LifePayOrderStatusEnum.已退款; | 
 |  |  |             order.LifePayRefundStatus = LifePayRefundStatusEnum.已退款; | 
 |  |  |             await _lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput() | 
 |  |  |             { | 
 |  |  |                 OrderNo = order.RefundOrderNo, | 
 |  |  |                 OutOrderNo = result.TradeNo, | 
 |  |  |                 LifePayType = LifePayTypeEnum.AliPay, | 
 |  |  |                 ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Receipts | 
 |  |  |             }); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         return result; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /// <summary> | 
 |  |  |     /// 查询微信退款订单信息 | 
 |  |  |     /// </summary> | 
 |  |  |     /// <param name="outTradeNo"></param> | 
 |  |  |     /// <returns></returns> | 
 |  |  |     public async Task<WxPayDomesticRefundsQueryReponse> WxPayDomesticRefundsQuery(string outTradeNo) | 
 |  |  |     { | 
 |  |  |         var order = await _lifePayOrderRepository.Where(x => x.RefundOrderNo == outTradeNo).FirstOrDefaultAsync(); | 
 |  |  |         CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "未找到订单信息"); | 
 |  |  |         var result = await _wxPayApi.WxPayDomesticRefundsQuery(outTradeNo); | 
 |  |  |         if (order.LifePayRefundStatus != LifePayRefundStatusEnum.已退款 && result.Code == WxpayResultCode.Success && result.Status == WxPayRefundStatus.退款成功) | 
 |  |  |         { | 
 |  |  |             order.LifePayOrderStatus = LifePayOrderStatusEnum.已退款; | 
 |  |  |             order.LifePayRefundStatus = LifePayRefundStatusEnum.已退款; | 
 |  |  |             await _lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput() | 
 |  |  |             { | 
 |  |  |                 OrderNo = order.OrderNo, | 
 |  |  |                 OutRefundNo = order.RefundOrderNo, | 
 |  |  |                 OutOrderNo = order.OutOrderNo, | 
 |  |  |                 LifePayType = LifePayTypeEnum.AliPay, | 
 |  |  |                 ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Receipts | 
 |  |  |             }); | 
 |  |  |         } | 
 |  |  |         return result; | 
 |  |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /// <summary> | 
 |  |  |     /// 查询微信订单信息 | 
 |  |  |     /// </summary> | 
 |  |  |     /// <param name="outTradeNo"></param> | 
 |  |  |     /// <returns></returns> | 
 |  |  |     public async Task<WxPayTradeQueryReponse> WxPayTradeQuery(string outTradeNo) | 
 |  |  |     { | 
 |  |  |         return await _wxPayApi.WxPayTradeQuery(outTradeNo); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |    | 
 |  |  |  | 
 |  |  |     #endregion | 
 |  |  |  | 
 |  |  |     #region 操作 | 
 |  |  | 
 |  |  |         var channle = await GetLifePayChannlesDtoByNum(input.ChannelId); | 
 |  |  |         CheckExtensions.IfTrueThrowUserFriendlyException(channle == null, "渠道不存在"); | 
 |  |  |  | 
 |  |  |         var repeatOrder = await _lifePayOrderRepository.Where(x => x.LifePayOrderType == LifePayOrderTypeEnum.PhoneOrder  | 
 |  |  |         && x.PayStatus == LifePayStatusEnum.已支付 | 
 |  |  |         && x.LifePayOrderStatus == LifePayOrderStatusEnum.充值中 | 
 |  |  |         && x.OrderParamDetailJsonStr.Contains(input.ProductData.Phone)).ToListAsync(); | 
 |  |  |          CheckExtensions.IfTrueThrowUserFriendlyException(repeatOrder.Count() > 0, "您有同户号订单正在充值中,请勿重复充值"); | 
 |  |  |  | 
 |  |  |         //var rate = await GetRate(); | 
 |  |  |         //CheckExtensions.IfTrueThrowUserFriendlyException(rate.IsNullOrEmpty(), "未配置折扣"); | 
 |  |  |  | 
 |  |  | 
 |  |  |         { | 
 |  |  |             OrderNo = channle.ChannlesNum + CreateOrderNo(), | 
 |  |  |             LifePayOrderStatus = LifePayOrderStatusEnum.充值中, | 
 |  |  |             LifePayOrderType = LifePayOrderTypeEnum.话费订单, | 
 |  |  |             LifePayOrderType = LifePayOrderTypeEnum.PhoneOrder, | 
 |  |  |             //LifePayType = input.LifePayType, | 
 |  |  |             OrderParamDetailJsonStr = JsonConvert.SerializeObject(input.ProductData), | 
 |  |  |             UserId = user.Id, | 
 |  |  | 
 |  |  |             RechargeAmount = amount.RechargeAmount, | 
 |  |  |             ChannelId = channle.ChannlesNum, | 
 |  |  |             PlatformRate = platformRate.Rate, | 
 |  |  |             PlatformDeductionAmount = amount.RechargeAmount * platformRate.Rate /100, | 
 |  |  |             PlatformDeductionAmount = amount.RechargeAmount * platformRate.Rate / 100, | 
 |  |  |             ChannleRate = rate, | 
 |  |  |             ChannlesRakeRate = channle.ChannlesRakeRate, | 
 |  |  |             //ChannlesRakePrice = amount.RechargeAmount * (channle.ChannlesRate - platformRate.Rate) / 100 * channle.ChannlesRakeRate / 100 | 
 |  |  | 
 |  |  |  | 
 |  |  |         //var rate = await GetRate(); | 
 |  |  |         //CheckExtensions.IfTrueThrowUserFriendlyException(rate.IsNullOrEmpty(), "未配置折扣"); | 
 |  |  |         var repeatOrder = await _lifePayOrderRepository.Where(x => x.LifePayOrderType == LifePayOrderTypeEnum.ElectricOrder && x.PayStatus == LifePayStatusEnum.已支付 | 
 |  |  |          && x.LifePayOrderStatus == LifePayOrderStatusEnum.充值中 && x.OrderParamDetailJsonStr.Contains(input.ProductData.ElectricType) | 
 |  |  |          && x.OrderParamDetailJsonStr.Contains(input.ProductData.ElectricAccount)).ToListAsync(); | 
 |  |  |         CheckExtensions.IfTrueThrowUserFriendlyException(repeatOrder.Count() > 0, "您有同户号订单正在充值中,请勿重复充值"); | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         var rate = await GetLifePayRate(channle, LifePayRateTypeEnum.默认电费折扣); | 
 |  |  |  | 
 |  |  |         var amount = CalculateAmount(input.ProductData.ParValue, rate); | 
 |  |  |  | 
 |  |  |         var platformRate = await _lifePayRateRepository.FirstOrDefaultAsync(r => r.RateType == LifePayRateTypeEnum.供应商折扣价); | 
 |  |  |  | 
 |  |  |         var orderInput = new CreateLifePayOrderInput | 
 |  |  |         { | 
 |  |  |             OrderNo = channle.ChannlesNum + CreateOrderNo(), | 
 |  |  |             LifePayOrderStatus = LifePayOrderStatusEnum.充值中, | 
 |  |  |             LifePayOrderType = LifePayOrderTypeEnum.电费订单, | 
 |  |  |             LifePayOrderType = LifePayOrderTypeEnum.ElectricOrder, | 
 |  |  |             // LifePayType = input.LifePayType, | 
 |  |  |             OrderParamDetailJsonStr = JsonConvert.SerializeObject(input.ProductData), | 
 |  |  |             UserId = user.Id, | 
 |  |  | 
 |  |  |  | 
 |  |  |         //var rate = await GetRate(); | 
 |  |  |         //CheckExtensions.IfTrueThrowUserFriendlyException(rate.IsNullOrEmpty(), "未配置折扣"); | 
 |  |  |         var repeatOrder = await _lifePayOrderRepository.Where(x => x.LifePayOrderType == LifePayOrderTypeEnum.GasOrder && x.PayStatus == LifePayStatusEnum.已支付 | 
 |  |  |         && x.LifePayOrderStatus == LifePayOrderStatusEnum.充值中 && x.OrderParamDetailJsonStr.Contains(input.ProductData.GasOrgType) | 
 |  |  |         && x.OrderParamDetailJsonStr.Contains(input.ProductData.GasAccount)).ToListAsync(); | 
 |  |  |         CheckExtensions.IfTrueThrowUserFriendlyException(repeatOrder.Count() > 0, "您有同户号订单正在充值中,请勿重复充值"); | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         var rate = await GetLifePayRate(channle, LifePayRateTypeEnum.默认燃气折扣); | 
 |  |  | 
 |  |  |         { | 
 |  |  |             OrderNo = channle.ChannlesNum + CreateOrderNo(), | 
 |  |  |             LifePayOrderStatus = LifePayOrderStatusEnum.充值中, | 
 |  |  |             LifePayOrderType = LifePayOrderTypeEnum.燃气订单, | 
 |  |  |             LifePayOrderType = LifePayOrderTypeEnum.GasOrder, | 
 |  |  |             // LifePayType = input.LifePayType, | 
 |  |  |             OrderParamDetailJsonStr = JsonConvert.SerializeObject(input.ProductData), | 
 |  |  |             UserId = user.Id, | 
 |  |  | 
 |  |  |     /// <returns></returns> | 
 |  |  |     public async Task<string> SetLifePayOrderPayType(SetLifePayOrderPayTypeInput input, string ip) | 
 |  |  |     { | 
 |  |  |         var order = await _lifePayOrderRepository.Where(x => x.OrderNo == input.OrderNo).FirstOrDefaultAsync(); | 
 |  |  |         CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "订单不存在"); | 
 |  |  |  | 
 |  |  |         CheckExtensions.IfTrueThrowUserFriendlyException(order.LifePayType.HasValue, "当前订单已选择支付类型"); | 
 |  |  |  | 
 |  |  |         order.LifePayType = input.LifePayType; | 
 |  |  |         var premium = await _lifePayPremiumRepository.Where(x => x.IsDeleted == false && x.PremiumType == order.LifePayType).FirstOrDefaultAsync(); | 
 |  |  |         order.PremiumRate = premium == null ? 0 : premium.Rate; | 
 |  |  |         await _lifePayOrderRepository.UpdateAsync(order); | 
 |  |  |  | 
 |  |  |         var desc = "生活缴费-"; | 
 |  |  |         switch (order.LifePayOrderType) | 
 |  |  |         { | 
 |  |  |             case LifePayOrderTypeEnum.话费订单: | 
 |  |  |                 desc += "话费"; | 
 |  |  |                 break; | 
 |  |  |             case LifePayOrderTypeEnum.电费订单: | 
 |  |  |                 desc += "电费"; | 
 |  |  |                 break; | 
 |  |  |             case LifePayOrderTypeEnum.燃气订单: | 
 |  |  |                 desc += "燃气"; | 
 |  |  |                 break; | 
 |  |  |             default: | 
 |  |  |                 break; | 
 |  |  |         } | 
 |  |  |         var res = await SetPayType(input.OrderNo, input.LifePayType, ip); | 
 |  |  |  | 
 |  |  | #if DEBUG | 
 |  |  |         //var payUrl = await GetPayQRCode(order.LifePayType.Value, order.OrderNo, desc, 0.01m, ip, input.H5Type); | 
 |  |  |         var payUrl = await GetPayQRCode(order.LifePayType.Value, order.OrderNo, desc, order.PayAmount, ip, input.H5Type); | 
 |  |  |         var payUrl = await GetPayQRCode(res.LifePayType, res.OrderNo, res.Desc, res.PayAmount, ip, input.H5Type); | 
 |  |  | #else | 
 |  |  |       //var payUrl = await GetPayQRCode(order.LifePayType.Value, order.OrderNo, desc, 0.01m, ip, input.H5Type); | 
 |  |  |         var payUrl = await GetPayQRCode(order.LifePayType.Value, order.OrderNo, desc, order.PayAmount, ip, input.H5Type); | 
 |  |  |       //var payUrl = await GetPayQRCode(res.LifePayType, res.OrderNo, res.Desc, 0.01m, ip, input.H5Type); | 
 |  |  |         var payUrl = await GetPayQRCode(res.LifePayType, res.OrderNo, res.Desc, res.PayAmount, ip, input.H5Type); | 
 |  |  | #endif | 
 |  |  |  | 
 |  |  |         return payUrl; | 
 |  |  | 
 |  |  |     /// <returns></returns> | 
 |  |  |     public async Task<ModelPaymentMiniPay> GetPayOrderForJsAPI(GetPayOrderForJsAPIInput input, string ip) | 
 |  |  |     { | 
 |  |  |         var order = await _lifePayOrderRepository.Where(x => x.OrderNo == input.OrderNo).FirstOrDefaultAsync(); | 
 |  |  |         CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "订单不存在"); | 
 |  |  |  | 
 |  |  |         CheckExtensions.IfTrueThrowUserFriendlyException(order.LifePayType.HasValue, "当前订单已选择支付类型"); | 
 |  |  |  | 
 |  |  |         order.LifePayType = input.LifePayType; | 
 |  |  |         var premium = await _lifePayPremiumRepository.Where(x => x.IsDeleted == false && x.PremiumType == order.LifePayType).FirstOrDefaultAsync(); | 
 |  |  |         order.PremiumRate = premium == null ? 0 : premium.Rate; | 
 |  |  |         await _lifePayOrderRepository.UpdateAsync(order); | 
 |  |  |  | 
 |  |  |         var desc = "生活缴费-"; | 
 |  |  |         switch (order.LifePayOrderType) | 
 |  |  |         { | 
 |  |  |             case LifePayOrderTypeEnum.话费订单: | 
 |  |  |                 desc += "话费"; | 
 |  |  |                 break; | 
 |  |  |             case LifePayOrderTypeEnum.电费订单: | 
 |  |  |                 desc += "电费"; | 
 |  |  |                 break; | 
 |  |  |             case LifePayOrderTypeEnum.燃气订单: | 
 |  |  |                 desc += "燃气"; | 
 |  |  |                 break; | 
 |  |  |             default: | 
 |  |  |                 break; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         //var result = await PayTransactionsJsAPI(input.OpenId, input.Attach, 0.01m, input.OrderNo, desc); | 
 |  |  |         //return result; | 
 |  |  |  | 
 |  |  |         //  var result = await PayTransactionsJsAPI(input.OpenId, input.Attach,  order.PayAmount, input.OrderNo, desc); | 
 |  |  |  | 
 |  |  |         var result = await PayTransactionsJsAPI(input.OpenId, input.PayAppId, input.Attach, order.PayAmount, input.OrderNo, desc); | 
 |  |  |         var res = await SetPayType(input.OrderNo, input.LifePayType, ip); | 
 |  |  |         var result = await PayTransactionsJsAPI(input.OpenId, input.PayAppId, input.Attach, res.PayAmount, input.OrderNo, res.Desc); | 
 |  |  |         return result; | 
 |  |  |         //var payUrl = await GetPayQRCode(order.LifePayType.Value, order.OrderNo, desc, 0.01m, ip, input.H5Type); | 
 |  |  |         //var payUrl = await GetPayQRCode(order.LifePayType.Value, order.OrderNo, desc, order.PayAmount, ip, input.H5Type); | 
 |  |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /// <summary> | 
 |  |  | 
 |  |  |         CheckExtensions.IfTrueThrowUserFriendlyException(order.ACOOLYStatus != ACOOLYStatusEnum.部分充值成功, "该订单无法修改到账金额"); | 
 |  |  |  | 
 |  |  |         order.ActualReceivedAmount = input.ActualReceivedAmount; | 
 |  |  |  | 
 |  |  |         await _lifePayOrderRepository.UpdateAsync(order); | 
 |  |  |  | 
 |  |  |         return Constant.SUCCESS; | 
 |  |  | 
 |  |  |     /// <returns></returns> | 
 |  |  |     public async Task CreateLifePayOrder(CreateLifePayOrderInput input) | 
 |  |  |     { | 
 |  |  |         CheckExtensions.IfTrueThrowUserFriendlyException(input.RechargeAmount < 0.01m || input.PayAmount < 0.01m || input.DiscountAmount < 0, "订单金额错误"); | 
 |  |  |  | 
 |  |  |         var entity = ObjectMapper.Map<CreateLifePayOrderInput, LifePayOrder>(input); | 
 |  |  |         await _lifePayOrderRepository.InsertAsync(entity); | 
 |  |  |     } | 
 |  |  | 
 |  |  |             OutOrderNo = orderNo | 
 |  |  |         }; | 
 |  |  |         var result = await _aCOOLYManager.ConfirmElectricOrder(requestInput); | 
 |  |  | #if DEBUG | 
 |  |  |  | 
 |  |  |         _logger.LogInformation($"CreateACOOLYElectricOrder:{JsonConvert.SerializeObject(result)}"); | 
 |  |  |  | 
 |  |  | #endif | 
 |  |  |  | 
 |  |  |         CheckExtensions.IfTrueThrowUserFriendlyException(!result.Success || (result.Code != ACOOLYConstant.Code.SUCCESS && result.Code != ACOOLYConstant.Code.PROCESSING), | 
 |  |  |                                                         result.Message); | 
 |  |  | 
 |  |  |         order.PayStatus = LifePayStatusEnum.已支付; | 
 |  |  |         order.PayTime = DateTime.Now; | 
 |  |  |         order.OutOrderNo = outOrderNo; | 
 |  |  |  | 
 |  |  |         try | 
 |  |  |         { | 
 |  |  |             var result = (Code: "Fail", RequestNo: "", ACOOLYOrderNo: ""); | 
 |  |  |             switch (order.LifePayOrderType) | 
 |  |  |             { | 
 |  |  |                 case LifePayOrderTypeEnum.话费订单: | 
 |  |  |                 case LifePayOrderTypeEnum.PhoneOrder: | 
 |  |  |                     result = await CreateACOOLYPhoneOrder(JsonConvert.DeserializeObject<LifePhoneData>(order.OrderParamDetailJsonStr), order.OrderNo); | 
 |  |  |                     break; | 
 |  |  |                 case LifePayOrderTypeEnum.电费订单: | 
 |  |  |                 case LifePayOrderTypeEnum.ElectricOrder: | 
 |  |  |                     result = await CreateACOOLYElectricOrder(JsonConvert.DeserializeObject<LifeElectricData>(order.OrderParamDetailJsonStr), order.OrderNo); | 
 |  |  |                     break; | 
 |  |  |                 case LifePayOrderTypeEnum.燃气订单: | 
 |  |  |                 case LifePayOrderTypeEnum.GasOrder: | 
 |  |  |                     result = await CreateACOOLYGasOrder(JsonConvert.DeserializeObject<LifeGasData>(order.OrderParamDetailJsonStr), order.OrderNo); | 
 |  |  |                     break; | 
 |  |  |                 default: | 
 |  |  | 
 |  |  |             order.LifePayOrderStatus = LifePayOrderStatusEnum.充值中; | 
 |  |  |             //SetOrderStatus(order, result.Code); | 
 |  |  |             order.OutRequestNo = result.RequestNo.IsNullOrEmpty() ? null : result.RequestNo; | 
 |  |  |             order.ACOOLYOrderNo = result.ACOOLYOrderNo.IsNullOrEmpty() ? null : result.ACOOLYOrderNo; | 
 |  |  |             order.ACOOLYOrderNo = result.ACOOLYOrderNo; | 
 |  |  |             order.ACOOLYStatus = ACOOLYStatusEnum.充值中; | 
 |  |  |  | 
 |  |  |             /// 创建生活缴费消费记录 | 
 |  |  |             await _lifePayOrderService.CreatLifePayConsumption(ACOOLYStatusEnum.充值中, order.OrderNo, order.ACOOLYOrderNo, | 
 |  |  |                                 order.PlatformDeductionAmount ?? 0, order.ChannelId, order.CreationTime, order.FinishTime); | 
 |  |  |         } | 
 |  |  |         catch (Exception ex) | 
 |  |  |         { | 
 |  |  |             _logger.LogError(ex, "处理生活缴费支付成功回调时异常"); | 
 |  |  |             order.LifePayOrderStatus = LifePayOrderStatusEnum.待退款; | 
 |  |  |             order.LifePayRefundStatus = LifePayRefundStatusEnum.待退款; | 
 |  |  |             order.ACOOLYStatus = ACOOLYStatusEnum.充值失败; | 
 |  |  |             order.RefundApplyRemark = ex.Message; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         _logger.LogError("生活缴费订单状态:" + order.LifePayOrderStatus.ToString()); | 
 |  |  |         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, "订单不存在"); | 
 |  |  | 
 |  |  |         { | 
 |  |  |             case LifePayRefundStatusEnum.已退款: | 
 |  |  |                 order.LifePayOrderStatus = LifePayOrderStatusEnum.已退款; | 
 |  |  |                 order.ACOOLYStatus = ACOOLYStatusEnum.已退款; | 
 |  |  |                 order.LifePayRefundStatus = LifePayRefundStatusEnum.已退款; | 
 |  |  |                 break; | 
 |  |  |             case LifePayRefundStatusEnum.退款中: | 
 |  |  |                 order.LifePayOrderStatus = LifePayOrderStatusEnum.退款中; | 
 |  |  |                 order.LifePayRefundStatus = LifePayRefundStatusEnum.退款中; | 
 |  |  |                 break; | 
 |  |  |             default:break; | 
 |  |  |             default: break; | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     /// <summary> | 
 |  |  |     /// ACOOLYO订单通知处理 | 
 |  |  | 
 |  |  |     /// <param name="orderNo"></param> | 
 |  |  |     /// <param name="outOrderNo"></param> | 
 |  |  |     /// <returns></returns> | 
 |  |  |     public async Task ACOOLYOrderNotifyHandler(string orderNo, string acoolyOrderNo, LifePayOrderStatusEnum status, ACOOLYStatusEnum acoolyStatus, decimal payAmount,string refundApplyRemark) | 
 |  |  |     public async Task ACOOLYOrderNotifyHandler(string orderNo, string acoolyOrderNo, LifePayOrderStatusEnum status, ACOOLYStatusEnum acoolyStatus, decimal payAmount, string refundApplyRemark) | 
 |  |  |     { | 
 |  |  |         var order = await _lifePayOrderRepository.Where(x => x.OrderNo == orderNo).FirstOrDefaultAsync(); | 
 |  |  |         CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "订单不存在"); | 
 |  |  |  | 
 |  |  |         //if (order.LifePayOrderStatus == LifePayOrderStatusEnum.已完成) | 
 |  |  |         //{ | 
 |  |  |         //    return; | 
 |  |  |         //} | 
 |  |  |         if (order.LifePayOrderStatus >= LifePayOrderStatusEnum.已完成) | 
 |  |  |         { | 
 |  |  |             return; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         order.PlatformDeductionAmount = payAmount; | 
 |  |  |         if (acoolyOrderNo.IsNotNullOrEmpty()) | 
 |  |  | 
 |  |  |         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.RechargeAmount ?? 0, | 
 |  |  |                     ChannlesRakeRate = order.ChannlesRakeRate ?? 0, | 
 |  |  |                     ChannlesRakePrice = channlesRakePrice ?? 0, | 
 |  |  |                     FinishTime = order.FinishTime.Value, | 
 |  |  |                     ChannelId = order.ChannelId, | 
 |  |  |                 }; | 
 |  |  |                 await _lifePayChannlesRakeRepository.InsertAsync(lifePayChannlesRake); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         /// 创建生活缴费消费记录 | 
 |  |  |         await _lifePayOrderService.CreatLifePayConsumption(acoolyStatus, order.OrderNo, order.ACOOLYOrderNo, | 
 |  |  |                     order.PlatformDeductionAmount ?? 0, order.ChannelId, order.CreationTime, order.FinishTime); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /// <summary> | 
 |  |  | 
 |  |  |  | 
 |  |  |         if (input.LifePayRefundType == LifePayRefundTypeEnum.全额退款) | 
 |  |  |         { | 
 |  |  |             input.RefundPrice = order.PayAmount; | 
 |  |  |             input.RefundPrice = order.PayAmount ?? 0; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         if (order.LifePayOrderStatus != LifePayOrderStatusEnum.待退款 || order.PayStatus != LifePayStatusEnum.已支付 || order.LifePayRefundStatus != LifePayRefundStatusEnum.待退款) | 
 |  |  | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         var outRefundNo = order.ChannelId + CreateRefundOrderNo(); | 
 |  |  |         order.RefundOrderNo = outRefundNo; | 
 |  |  |         switch (order.LifePayType) | 
 |  |  |         { | 
 |  |  |             case LifePayTypeEnum.WxPay: | 
 |  |  |                 var wxRefundResult = await WxPayDomesticRefunds(order.OrderNo, outRefundNo,order.RefundApplyRemark, Convert.ToInt32(input.RefundPrice * 100), Convert.ToInt32(order.PayAmount * 100)); | 
 |  |  |                 if (wxRefundResult.Status == "SUCCESS") | 
 |  |  |                 var wxRefundResult = await WxPayDomesticRefunds(order.OrderNo, outRefundNo, order.RefundApplyRemark, Convert.ToInt32(input.RefundPrice * 100), Convert.ToInt32(order.PayAmount * 100)); | 
 |  |  |                 if (wxRefundResult.Status == WxpayRefundResultStatus.SUCCESS) | 
 |  |  |                 { | 
 |  |  |                     order.LifePayOrderStatus = LifePayOrderStatusEnum.已退款; | 
 |  |  |                     order.LifePayRefundStatus = LifePayRefundStatusEnum.已退款; | 
 |  |  |                 } | 
 |  |  |                 else if (wxRefundResult.Status == "PROCESSING") | 
 |  |  |                 { | 
 |  |  |                     order.RefundOrderNo = outRefundNo; | 
 |  |  |                     order.LifePayOrderStatus = LifePayOrderStatusEnum.退款中; | 
 |  |  |                     order.LifePayRefundStatus = LifePayRefundStatusEnum.退款中; | 
 |  |  |                 } | 
 |  |  |                 else if (wxRefundResult.Message == "订单已全额退款") | 
 |  |  |                 else if (wxRefundResult.Status == WxpayRefundResultStatus.PROCESSING) | 
 |  |  |                 { | 
 |  |  |                     order.RefundOrderNo = outRefundNo; | 
 |  |  |                     order.LifePayOrderStatus = LifePayOrderStatusEnum.退款中; | 
 |  |  |                     order.LifePayRefundStatus = LifePayRefundStatusEnum.退款中; | 
 |  |  |                 } | 
 |  |  |                 else if (wxRefundResult.Status.IsNullOrEmpty() && wxRefundResult.Message == WxpayRefundResultMessage.FullRefund) | 
 |  |  |                 { | 
 |  |  |                     order.LifePayOrderStatus = LifePayOrderStatusEnum.已退款; | 
 |  |  |                     order.LifePayRefundStatus = LifePayRefundStatusEnum.已退款; | 
 |  |  |                 } | 
 |  |  |                 else | 
 |  |  |                 { | 
 |  |  |                     order.LifePayOrderStatus = LifePayOrderStatusEnum.待退款; | 
 |  |  |                     order.LifePayRefundStatus = LifePayRefundStatusEnum.待退款; | 
 |  |  |                     throw new UserFriendlyException("退款失败:" + wxRefundResult.Message); | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 break; | 
 |  |  |             case LifePayTypeEnum.AliPay: | 
 |  |  |                 var aliRefundResult = await AliTradeRefund(new AlipayTradeRefundRequest() { OutTradeNo = order.OrderNo, RefundAmount = input.RefundPrice.ToString() }); | 
 |  |  |                 var aliRefundResult = await AliTradeRefund(new AlipayTradeRefundRequest() { OutTradeNo = order.OrderNo, OutRefundNo = outRefundNo, RefundAmount = input.RefundPrice.ToString() }); | 
 |  |  |                 if (aliRefundResult.Code != AlipayResultCode.Success) | 
 |  |  |                 { | 
 |  |  |                     throw new UserFriendlyException("退款失败:" + aliRefundResult.SubMsg); | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 order.LifePayOrderStatus = LifePayOrderStatusEnum.已退款; | 
 |  |  |                 order.LifePayRefundStatus = LifePayRefundStatusEnum.已退款; | 
 |  |  |                 order.RefundOrderNo = outRefundNo; | 
 |  |  |                 order.LifePayOrderStatus = LifePayOrderStatusEnum.退款中; | 
 |  |  |                 order.LifePayRefundStatus = LifePayRefundStatusEnum.退款中; | 
 |  |  |                 break; | 
 |  |  |             default: throw new UserFriendlyException("退款失败"); | 
 |  |  |         } | 
 |  |  | 
 |  |  |     /// <param name="total"></param> | 
 |  |  |     /// <param name="currency"></param> | 
 |  |  |     /// <returns></returns> | 
 |  |  |     public async Task<WxPayDomesticRefundsReponse> WxPayDomesticRefunds(string outTradeNo,string outRefundNo, string reason, int refund, int total, string currency = "CNY") | 
 |  |  |     public async Task<WxPayDomesticRefundsReponse> WxPayDomesticRefunds(string outTradeNo, string outRefundNo, string reason, int refund, int total, string currency = "CNY") | 
 |  |  |     { | 
 |  |  |         WxPayDomesticRefundsRequest req = new WxPayDomesticRefundsRequest | 
 |  |  |         { | 
 |  |  | 
 |  |  |             var userAccount = await _lifePayAccount.Where(x => x.UserId == input.UserId && x.Id == input.Id) | 
 |  |  |                                             .FirstOrDefaultAsync(); | 
 |  |  |             CheckExtensions.IfTrueThrowUserFriendlyException(userAccount == null, "户号不存在"); | 
 |  |  |             var repeatAccountContent = await _lifePayAccount.Where(x => x.UserId == input.UserId && x.LifePayType == input.LifePayType && x.Content == input.Content && x.Id != input.Id) | 
 |  |  |             var repeatAccountContent = await _lifePayAccount.Where(x => x.UserId == input.UserId && x.LifePayType == input.LifePayType && x.Content == input.Content && x.Id != input.Id && x.IsDeleted == false) | 
 |  |  |                                             .FirstOrDefaultAsync(); | 
 |  |  |             CheckExtensions.IfTrueThrowUserFriendlyException(repeatAccountContent != null, "户号已存在"); | 
 |  |  |  | 
 |  |  | 
 |  |  |         } | 
 |  |  |         else | 
 |  |  |         { | 
 |  |  |             var repeatAccountContent = await _lifePayAccount.Where(x => x.UserId == input.UserId && x.LifePayType == input.LifePayType && x.Content == input.Content) | 
 |  |  |             var repeatAccountContent = await _lifePayAccount.Where(x => x.UserId == input.UserId && x.LifePayType == input.LifePayType && x.Content == input.Content && x.IsDeleted == false) | 
 |  |  |                                             .FirstOrDefaultAsync(); | 
 |  |  |             CheckExtensions.IfTrueThrowUserFriendlyException(repeatAccountContent != null, "户号已存在"); | 
 |  |  |             var userAccount = new LifePayAccount | 
 |  |  | 
 |  |  |             await _lifePayAccount.InsertAsync(userAccount); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         if (input.LifePayType == LifePayOrderTypeEnum.话费订单) | 
 |  |  |         if (input.LifePayType == LifePayOrderTypeEnum.PhoneOrder || input.LifePayType == LifePayOrderTypeEnum.ElectricOrder) | 
 |  |  |         { | 
 |  |  |             var extraProperties = JsonConvert.DeserializeObject<Model_UserAccountExtraProperties>(input.ExtraProperties); | 
 |  |  |             if (!string.IsNullOrEmpty(extraProperties.Name)) | 
 |  |  |             if (!string.IsNullOrEmpty(extraProperties.Name) && extraProperties.Phone == user.PhoneNumber) | 
 |  |  |             { | 
 |  |  |                 user.Name = extraProperties.Phone == user.PhoneNumber ? extraProperties.Name : string.Empty; | 
 |  |  |                 user.Name = extraProperties.Name; | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  | 
 |  |  |         userAccount.DeleterId = userAccount.UserId; | 
 |  |  |         userAccount.DeletionTime = DateTime.Now; | 
 |  |  |         userAccount.IsDeleted = true; | 
 |  |  |  | 
 |  |  |         return Constant.SUCCESS; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |             await _lifePayOrderRepository.UpdateAsync(order); | 
 |  |  |  | 
 |  |  |             #region 记录日志 | 
 |  |  |  | 
 |  |  |             await PublishLifePayOrderHistoryEvent("退款驳回", "退款", order.Id); | 
 |  |  |  | 
 |  |  |             await LifePayOrderHistory("退款驳回", "退款驳回", order.Id, (int)OperateHistoryTypeEnum.LifePayRefund); | 
 |  |  |             #endregion | 
 |  |  |         } | 
 |  |  |         else | 
 |  |  | 
 |  |  |             dto.Status = input.Status; | 
 |  |  |             #region 记录日志 | 
 |  |  |  | 
 |  |  |             await PublishLifePayOrderHistoryEvent("渠道管理", "编辑", input.Id.Value, TableType.LifePayChannles); | 
 |  |  |             await LifePayOrderHistory("渠道管理", "编辑", input.Id.Value, TableType.LifePayChannles); | 
 |  |  |  | 
 |  |  |             #endregion | 
 |  |  |         } | 
 |  |  | 
 |  |  |  | 
 |  |  |             #region 记录日志 | 
 |  |  |  | 
 |  |  |             await PublishLifePayOrderHistoryEvent("渠道管理", "新增", input.Id.Value, TableType.LifePayChannles); | 
 |  |  |             await LifePayOrderHistory("渠道管理", "新增", input.Id.Value, TableType.LifePayChannles); | 
 |  |  |  | 
 |  |  |             #endregion | 
 |  |  |         } | 
 |  |  | 
 |  |  |  | 
 |  |  |         #region 记录日志 | 
 |  |  |  | 
 |  |  |         await PublishLifePayOrderHistoryEvent("渠道管理", status.GetDescription(), id, TableType.LifePayChannles); | 
 |  |  |  | 
 |  |  |         await LifePayOrderHistory("渠道管理", status.GetDescription(), id, TableType.LifePayChannles); | 
 |  |  |         #endregion | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |  | 
 |  |  |     private (decimal PayAmont, decimal DiscountAmount, decimal RechargeAmount) CalculateAmount(decimal amount, decimal rate) | 
 |  |  |     { | 
 |  |  |         /// 正常支付 | 
 |  |  |         //var payAmount = decimal.Round(amount * rate / 100, 2, MidpointRounding.AwayFromZero); | 
 |  |  |         if (_initSettingOptions.OpenTheOnePennyTest) | 
 |  |  |         { | 
 |  |  |             /// 1分钱支付 | 
 |  |  |             decimal payAmount = 0.01m; | 
 |  |  |  | 
 |  |  |         /// 1分钱支付 | 
 |  |  |         decimal payAmount = 0.01m; | 
 |  |  |             CheckExtensions.IfTrueThrowUserFriendlyException(payAmount < 0.01m, "支付金额错误"); | 
 |  |  |  | 
 |  |  |         CheckExtensions.IfTrueThrowUserFriendlyException(payAmount < 0.01m, "支付金额错误"); | 
 |  |  |  | 
 |  |  |         return (payAmount, amount - payAmount, amount); | 
 |  |  |             return (payAmount, amount - payAmount, amount); | 
 |  |  |         } | 
 |  |  |         else | 
 |  |  |         { | 
 |  |  |             /// 正常支付 | 
 |  |  |             var payAmount = decimal.Round(amount * rate / 100, 2, MidpointRounding.AwayFromZero); | 
 |  |  |             return (payAmount, amount - payAmount, amount); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private void SetOrderStatus(LifePayOrder order, string code) | 
 |  |  | 
 |  |  |         return message; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     private async Task<IQueryable<LifePayOrderListOutput>> GetLifePayOrderListFilter(QueryLifePayOrderListInput input) | 
 |  |  |     { | 
 |  |  |         var channles = await _lifePayChannlesRep.Where(x => x.ChannlesName.Contains(input.KeyWords)).Select(x => x.ChannlesNum).ToListAsync(); | 
 |  |  | 
 |  |  |                                             .WhereIf(input.LifePayOrderType.HasValue, x => x.LifePayOrderType == input.LifePayOrderType.Value) | 
 |  |  |                                             .WhereIf(input.UserId.HasValue, x => x.UserId == input.UserId.Value) | 
 |  |  |                                             .WhereIf(input.KeyWords.IsNotNullOrEmpty(), x => x.OrderNo.Contains(input.KeyWords) || x.OutOrderNo.Contains(input.KeyWords) || x.ACOOLYOrderNo.Contains(input.KeyWords) || channles.Contains(x.ChannelId)) | 
 |  |  |                             join b in _lifePayChannlesRep on a.ChannelId equals b.ChannlesNum into temp | 
 |  |  |                             from b in temp.DefaultIfEmpty() | 
 |  |  |                             select new LifePayOrderListOutput | 
 |  |  |                             { | 
 |  |  |                                 DiscountAmount = a.DiscountAmount, | 
 |  |  |                                 FinishTime = a.FinishTime, | 
 |  |  |                                 Id = a.Id, | 
 |  |  |                                 LifePayOrderStatus = a.LifePayOrderStatus, | 
 |  |  |                                 LifePayOrderType = a.LifePayOrderType, | 
 |  |  |                                 LifePayType = a.LifePayType, | 
 |  |  |                                 OrderNo = a.OrderNo, | 
 |  |  |                                 PayAmount = a.PayAmount, | 
 |  |  |                                 PhoneNumber = a.PhoneNumber, | 
 |  |  |                                 RechargeAmount = a.RechargeAmount, | 
 |  |  |                                 UserId = a.UserId, | 
 |  |  |                                 OutOrderNo = a.OutOrderNo, | 
 |  |  |                                 PayStatus = a.PayStatus, | 
 |  |  |                                 PayTime = a.PayTime, | 
 |  |  |                                 ACOOLYOrderNo = a.ACOOLYOrderNo, | 
 |  |  |                                 RefundCredentialsImgUrl = a.RefundCredentialsImgUrl.GetOssPath(), | 
 |  |  |                                 RefundPrice = a.RefundPrice, | 
 |  |  |                                 CreationTime = a.CreationTime, | 
 |  |  |                                 RefundCheckRemark = a.RefundCheckRemark, | 
 |  |  |                                 RefundApplyRemark = a.RefundApplyRemark, | 
 |  |  |                                 RefundTime = a.RefundTime, | 
 |  |  |                                 ChannelName = b.ChannlesName, | 
 |  |  |                                 ActualRechargeAmount = a.ActualRechargeAmount, | 
 |  |  |                                 PlatformDeductionAmount = a.PlatformDeductionAmount, | 
 |  |  |                                 ACOOLYStatus = a.ACOOLYStatus, | 
 |  |  |                                 LifePayRefundStatus = a.LifePayRefundStatus, | 
 |  |  |                             }); | 
 |  |  |                       join b in _lifePayChannlesRep on a.ChannelId equals b.ChannlesNum into temp | 
 |  |  |                       from b in temp.DefaultIfEmpty() | 
 |  |  |                       select new LifePayOrderListOutput | 
 |  |  |                       { | 
 |  |  |                           DiscountAmount = a.DiscountAmount ?? 0, | 
 |  |  |                           FinishTime = a.FinishTime, | 
 |  |  |                           Id = a.Id, | 
 |  |  |                           LifePayOrderStatus = a.LifePayOrderStatus ?? 0, | 
 |  |  |                           LifePayOrderType = a.LifePayOrderType, | 
 |  |  |                           LifePayType = a.LifePayType, | 
 |  |  |                           OrderNo = a.OrderNo, | 
 |  |  |                           PayAmount = a.PayAmount ?? 0, | 
 |  |  |                           PhoneNumber = a.PhoneNumber, | 
 |  |  |                           RechargeAmount = a.RechargeAmount ?? 0, | 
 |  |  |                           UserId = a.UserId, | 
 |  |  |                           OutOrderNo = a.OutOrderNo, | 
 |  |  |                           PayStatus = a.PayStatus ?? 0, | 
 |  |  |                           PayTime = a.PayTime, | 
 |  |  |                           ACOOLYOrderNo = a.ACOOLYOrderNo, | 
 |  |  |                           RefundCredentialsImgUrl = a.RefundCredentialsImgUrl.GetOssPath(), | 
 |  |  |                           RefundPrice = a.RefundPrice, | 
 |  |  |                           CreationTime = a.CreationTime, | 
 |  |  |                           RefundCheckRemark = a.RefundCheckRemark, | 
 |  |  |                           RefundApplyRemark = a.RefundApplyRemark, | 
 |  |  |                           RefundTime = a.RefundTime, | 
 |  |  |                           ChannelName = b.ChannlesName, | 
 |  |  |                           ActualRechargeAmount = a.ActualRechargeAmount, | 
 |  |  |                           PlatformDeductionAmount = a.PlatformDeductionAmount, | 
 |  |  |                           ACOOLYStatus = a.ACOOLYStatus, | 
 |  |  |                           LifePayRefundStatus = a.LifePayRefundStatus, | 
 |  |  |                       }); | 
 |  |  |  | 
 |  |  |          | 
 |  |  |  | 
 |  |  |         return result; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |                                          .WhereIf(input.LifePayOrderType.HasValue, x => x.LifePayOrderType == input.LifePayOrderType.Value) | 
 |  |  |                                          .WhereIf(input.UserId.HasValue, x => x.UserId == input.UserId.Value) | 
 |  |  |                                          .WhereIf(input.KeyWords.IsNotNullOrEmpty(), x => x.PhoneNumber.Contains(input.KeyWords) || x.OrderNo.Contains(input.KeyWords) || x.OutOrderNo.Contains(input.KeyWords) || x.ACOOLYOrderNo.Contains(input.KeyWords)) | 
 |  |  |                             join b in _lifePayChannlesRep on a.ChannelId equals b.ChannlesNum into temp | 
 |  |  |                             from b in temp.DefaultIfEmpty() | 
 |  |  |                             select new LifePayOrderListOutput | 
 |  |  |                             { | 
 |  |  |                                 DiscountAmount = a.DiscountAmount, | 
 |  |  |                                 FinishTime = a.FinishTime, | 
 |  |  |                                 Id = a.Id, | 
 |  |  |                                 LifePayOrderStatus = a.LifePayOrderStatus, | 
 |  |  |                                 LifePayOrderType = a.LifePayOrderType, | 
 |  |  |                                 LifePayType = a.LifePayType, | 
 |  |  |                                 OrderNo = a.OrderNo, | 
 |  |  |                                 PayAmount = a.PayAmount, | 
 |  |  |                                 PhoneNumber = a.PhoneNumber, | 
 |  |  |                                 RechargeAmount = a.RechargeAmount, | 
 |  |  |                                 UserId = a.UserId, | 
 |  |  |                                 OutOrderNo = a.OutOrderNo, | 
 |  |  |                                 PayStatus = a.PayStatus, | 
 |  |  |                                 PayTime = a.PayTime, | 
 |  |  |                                 ACOOLYOrderNo = a.ACOOLYOrderNo, | 
 |  |  |                                 RefundCredentialsImgUrl = a.RefundCredentialsImgUrl.GetOssPath(), | 
 |  |  |                                 CreationTime = a.CreationTime, | 
 |  |  |                                 RefundCheckRemark = a.RefundCheckRemark, | 
 |  |  |                                 RefundApplyRemark = a.RefundApplyRemark, | 
 |  |  |                                 RefundApplyTime = a.RefundApplyTime, | 
 |  |  |                                 RefundTime = a.RefundTime, | 
 |  |  |                                 RefundOrderNo = a.RefundOrderNo, | 
 |  |  |                                 RefundPrice = a.RefundPrice, | 
 |  |  |                                 ChannelName = b.ChannlesName, | 
 |  |  |                                 ActualRechargeAmount = a.ActualRechargeAmount, | 
 |  |  |                                 PlatformDeductionAmount = a.PlatformDeductionAmount, | 
 |  |  |                                 ACOOLYStatus = a.ACOOLYStatus, | 
 |  |  |                                 LifePayRefundStatus = a.LifePayRefundStatus, | 
 |  |  |                                 ActualReceivedAmount = a.ActualReceivedAmount.HasValue? a.ActualReceivedAmount.Value : 0 | 
 |  |  |                             }); | 
 |  |  |                       join b in _lifePayChannlesRep on a.ChannelId equals b.ChannlesNum into temp | 
 |  |  |                       from b in temp.DefaultIfEmpty() | 
 |  |  |                       select new LifePayOrderListOutput | 
 |  |  |                       { | 
 |  |  |                           DiscountAmount = a.DiscountAmount ?? 0, | 
 |  |  |                           FinishTime = a.FinishTime, | 
 |  |  |                           Id = a.Id, | 
 |  |  |                           LifePayOrderStatus = a.LifePayOrderStatus ?? 0, | 
 |  |  |                           LifePayOrderType = a.LifePayOrderType, | 
 |  |  |                           LifePayType = a.LifePayType, | 
 |  |  |                           OrderNo = a.OrderNo, | 
 |  |  |                           PayAmount = a.PayAmount ?? 0, | 
 |  |  |                           PhoneNumber = a.PhoneNumber, | 
 |  |  |                           RechargeAmount = a.RechargeAmount ?? 0, | 
 |  |  |                           UserId = a.UserId, | 
 |  |  |                           OutOrderNo = a.OutOrderNo, | 
 |  |  |                           PayStatus = a.PayStatus ?? 0, | 
 |  |  |                           PayTime = a.PayTime, | 
 |  |  |                           ACOOLYOrderNo = a.ACOOLYOrderNo, | 
 |  |  |                           RefundCredentialsImgUrl = a.RefundCredentialsImgUrl.GetOssPath(), | 
 |  |  |                           CreationTime = a.CreationTime, | 
 |  |  |                           RefundCheckRemark = a.RefundCheckRemark, | 
 |  |  |                           RefundApplyRemark = a.RefundApplyRemark, | 
 |  |  |                           RefundApplyTime = a.RefundApplyTime, | 
 |  |  |                           RefundTime = a.RefundTime, | 
 |  |  |                           RefundOrderNo = a.RefundOrderNo, | 
 |  |  |                           RefundPrice = a.RefundPrice, | 
 |  |  |                           ChannelName = b.ChannlesName, | 
 |  |  |                           ActualRechargeAmount = a.ActualRechargeAmount, | 
 |  |  |                           PlatformDeductionAmount = a.PlatformDeductionAmount, | 
 |  |  |                           ACOOLYStatus = a.ACOOLYStatus, | 
 |  |  |                           LifePayRefundStatus = a.LifePayRefundStatus, | 
 |  |  |                           ActualReceivedAmount = a.ActualReceivedAmount.HasValue ? a.ActualReceivedAmount.Value : 0 | 
 |  |  |                       }); | 
 |  |  |         return result; | 
 |  |  |     } | 
 |  |  |     private IQueryable<CreateEditPayChannelsInput> GetLifePayChannlesListFilter() | 
 |  |  | 
 |  |  |                     }); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public async Task<OrderPriceReturn> GetOrderPrice(decimal price, decimal priceAmount, decimal? platformRate,decimal? channleRate, | 
 |  |  |         decimal? channlesRakeRate,decimal? premiumRate) | 
 |  |  |     public async Task<OrderPriceReturn> GetOrderPrice(decimal price, decimal priceAmount, decimal platformRate, decimal channleRate, | 
 |  |  |         decimal channlesRakeRate, decimal premiumRate) | 
 |  |  |     { | 
 |  |  |         /// 毛利 | 
 |  |  |         var grossProfit = price * (channleRate - platformRate) / 100; | 
 |  |  | 
 |  |  |         var platformPrice = price * platformRate / 100; | 
 |  |  |  | 
 |  |  |         /// 手续费 | 
 |  |  |         var premiumPrice = priceAmount * premiumRate / 100; | 
 |  |  |         var premiumPrice = priceAmount * (premiumRate) / 100; | 
 |  |  |  | 
 |  |  |         /// 渠道佣金  ((充值面额 * 渠道折扣比例)-(充值面额 * 平台折扣比例))* 佣金比例 | 
 |  |  |         var channlesRakePrice = grossProfit * channlesRakeRate / 100; | 
 |  |  |         var channlesRakePrice = grossProfit * (channlesRakeRate) / 100; | 
 |  |  |  | 
 |  |  |         /// 利润 | 
 |  |  |         var profit = grossProfit - channlesRakePrice - premiumPrice; | 
 |  |  |  | 
 |  |  |         return new OrderPriceReturn() | 
 |  |  |         { | 
 |  |  |             PlatformPrice = platformPrice.HasValue? platformPrice.Value :0, | 
 |  |  |             PremiumPrice = premiumPrice.HasValue ? premiumPrice.Value : 0, | 
 |  |  |             ChannlesRakePrice = channlesRakePrice.HasValue? channlesRakePrice.Value:0, | 
 |  |  |             Profit = profit.HasValue ? profit.Value : 0 | 
 |  |  |             PlatformPrice = platformPrice, | 
 |  |  |             PremiumPrice = premiumPrice, | 
 |  |  |             ChannlesRakePrice = channlesRakePrice, | 
 |  |  |             Profit = profit | 
 |  |  |         }; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public async Task<SetPayTypeReturn> SetPayType(string orderNo, LifePayTypeEnum lifePayType, string ip) | 
 |  |  |     { | 
 |  |  |         var order = await _lifePayOrderRepository.Where(x => x.OrderNo == orderNo).FirstOrDefaultAsync(); | 
 |  |  |         CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "订单不存在"); | 
 |  |  |  | 
 |  |  |         CheckExtensions.IfTrueThrowUserFriendlyException(order.LifePayType.HasValue, "当前订单已选择支付类型"); | 
 |  |  |  | 
 |  |  |         order.LifePayType = lifePayType; | 
 |  |  |         var premium = await _lifePayPremiumRepository.Where(x => x.IsDeleted == false && x.PremiumType == order.LifePayType).FirstOrDefaultAsync(); | 
 |  |  |         order.PremiumRate = premium == null ? 0 : premium.Rate; | 
 |  |  |         await _lifePayOrderRepository.UpdateAsync(order); | 
 |  |  |  | 
 |  |  |         var desc = "生活缴费-"; | 
 |  |  |         switch (order.LifePayOrderType) | 
 |  |  |         { | 
 |  |  |             case LifePayOrderTypeEnum.PhoneOrder: | 
 |  |  |                 desc += "话费"; | 
 |  |  |                 break; | 
 |  |  |             case LifePayOrderTypeEnum.ElectricOrder: | 
 |  |  |                 desc += "电费"; | 
 |  |  |                 break; | 
 |  |  |             case LifePayOrderTypeEnum.GasOrder: | 
 |  |  |                 desc += "燃气"; | 
 |  |  |                 break; | 
 |  |  |             default: | 
 |  |  |                 break; | 
 |  |  |         } | 
 |  |  |          | 
 |  |  |         return new SetPayTypeReturn() | 
 |  |  |         { | 
 |  |  |             Desc = desc, | 
 |  |  |             OrderNo = order.OrderNo, | 
 |  |  |             PayAmount = order.PayAmount.HasValue? order.PayAmount.Value : 0, | 
 |  |  |             LifePayType = lifePayType, | 
 |  |  |         }; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     #endregion | 
 |  |  | } |