|  |  | 
 |  |  | using Volo.Abp.ObjectMapping; | 
 |  |  | using NPOI.SS.Formula.Functions; | 
 |  |  | using StackExchange.Redis; | 
 |  |  | using static Volo.Abp.Identity.Settings.IdentitySettingNames; | 
 |  |  |  | 
 |  |  | namespace LifePayment.Application; | 
 |  |  |  | 
 |  |  | 
 |  |  |     /// <returns></returns> | 
 |  |  |     public async Task<ChannelRateOutput> GetChannelRate(ChannelsBaseInput input) | 
 |  |  |     { | 
 |  |  |         return  _lifePayChannlesRep.Where(x => x.IsDeleted == false && x.ChannlesNum == input.CheckChannelId).Select(x => new ChannelRateOutput() { ChannlesRate = x.ChannlesRate }) | 
 |  |  |         return _lifePayChannlesRep.Where(x => x.IsDeleted == false && x.ChannlesNum == input.CheckChannelId).Select(x => new ChannelRateOutput() { ChannlesRate = x.ChannlesRate }) | 
 |  |  |                                            .FirstOrDefault(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |     { | 
 |  |  |         var channles = await _lifePayChannlesRep.Where(x => x.ChannlesName.Contains(input.KeyWords)).Select(x => x.ChannlesNum).ToListAsync(); | 
 |  |  |         var result = await (from a in _channelFilter.GetChannelLifePayOrderFilter(_lifePayOrderRepository) | 
 |  |  |                             .Where(x => x.PayStatus != LifePayStatusEnum.未支付) | 
 |  |  |                       .WhereIf(input.BeginFinishTime.HasValue, x => x.FinishTime >= input.BeginFinishTime) | 
 |  |  |                                             .WhereIf(input.EndFinishTime.HasValue, x => x.FinishTime <= input.EndFinishTime) | 
 |  |  |                                             .WhereIf(input.BeginPayTime.HasValue, x => x.PayTime >= input.BeginPayTime) | 
 |  |  | 
 |  |  |                             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(), | 
 |  |  | 
 |  |  |                             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(), | 
 |  |  | 
 |  |  |             s.LifePayOrderTypeStr = s.LifePayOrderType.GetDescription(); | 
 |  |  |             s.RechargeAmountStr = s.RechargeAmount.ToString("F2"); | 
 |  |  |             s.ActualReceivedAmount = s.ActualReceivedAmount; | 
 |  |  |             s.LifePayRefundStatusStr = s.LifePayRefundStatus.GetDescription(); | 
 |  |  |             s.LifePayRefundStatusStr = s.LifePayRefundStatus == LifePayRefundStatusEnum.无需退款 ? "" : s.LifePayRefundStatus.GetDescription(); | 
 |  |  |             s.PayAmountStr = s.PayAmount.ToString("F2"); | 
 |  |  |             s.LifePayTypeStr = s.LifePayType.GetDescription(); | 
 |  |  |             s.FinishTimeStr = !s.FinishTime.HasValue ? string.Empty : s.FinishTime.Value.ToString(LifePaymentConstant.DateTimeFormatStr.yyyyMMddHHmm); | 
 |  |  |             s.RefundApplyTimeStr = !s.RefundApplyTime.HasValue? string.Empty:s.RefundApplyTime.Value.ToString(LifePaymentConstant.DateTimeFormatStr.yyyyMMddHHmm); | 
 |  |  |             s.RefundApplyTimeStr = !s.RefundApplyTime.HasValue ? string.Empty : s.RefundApplyTime.Value.ToString(LifePaymentConstant.DateTimeFormatStr.yyyyMMddHHmm); | 
 |  |  |         }); | 
 |  |  |         return result; | 
 |  |  |     } | 
 |  |  | 
 |  |  |     { | 
 |  |  |         var order = await _lifePayOrderRepository.Where(x => x.OrderNo == orderNo).FirstOrDefaultAsync(); | 
 |  |  |         var channle = await _lifePayChannlesRep.FirstOrDefaultAsync(r => r.ChannlesNum == order.ChannelId); | 
 |  |  |          CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "订单不存在"); | 
 |  |  |         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(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |                                                         OrderNo = x.OrderNo, | 
 |  |  |                                                         RefundCheckRemark = x.RefundCheckRemark, | 
 |  |  |                                                         RefundApplyRemark = x.RefundApplyRemark, | 
 |  |  |                                                         LifePayOrderStatus = x.LifePayOrderStatus, | 
 |  |  |                                                         LifePayOrderStatus = x.LifePayOrderStatus ?? 0, | 
 |  |  |                                                     }).FirstOrDefaultAsync(); | 
 |  |  |  | 
 |  |  |         CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "未找到订单信息"); | 
 |  |  | 
 |  |  |         { | 
 |  |  |             DiscountAmount = x.DiscountAmount, | 
 |  |  |             FinishTime = x.FinishTime, | 
 |  |  |             //LifePayOrderStatus = x.LifePayOrderStatus, | 
 |  |  |             LifePayOrderStatus = x.LifePayOrderStatus, | 
 |  |  |             LifePayOrderType = x.LifePayOrderType, | 
 |  |  |             LifePayType = x.LifePayType, | 
 |  |  |             OrderNo = x.OrderNo, | 
 |  |  |             PayAmount = x.PayAmount, | 
 |  |  |             ActualRechargeAmount = x.ActualRechargeAmount.HasValue?x.ActualRechargeAmount.Value:0, | 
 |  |  |             ActualRechargeAmount = x.RechargeAmount, | 
 |  |  |             PhoneNumber = x.PhoneNumber, | 
 |  |  |             RechargeAmount = x.RechargeAmount, | 
 |  |  |             OutOrderNo = x.OutOrderNo, | 
 |  |  | 
 |  |  |             s.LifePayTypeStr = s.LifePayType.GetDescription(); | 
 |  |  |             s.PayStatusStr = s.PayStatus.GetDescription(); | 
 |  |  |             s.ActualRechargeAmountStr = s.ActualRechargeAmount.ToString("F2"); | 
 |  |  |             s.LifePayRefundStatusStr = s.LifePayRefundStatus.GetDescription(); | 
 |  |  |             s.LifePayRefundStatusStr = s.LifePayRefundStatus == LifePayRefundStatusEnum.无需退款 ? "" : s.LifePayRefundStatus.GetDescription(); | 
 |  |  |             s.ACOOLYStatusStr = s.ACOOLYStatus.GetDescription(); | 
 |  |  |             //s.LifePayOrderStatusStr = s.LifePayOrderStatus.GetDescription(); | 
 |  |  |             s.LifePayOrderStatusStr = s.LifePayOrderStatus.GetDescription(); | 
 |  |  |             s.FinishTimeStr = !s.FinishTime.HasValue ? string.Empty : s.FinishTime.Value.ToString(LifePaymentConstant.DateTimeFormatStr.yyyyMMddHHmmss); | 
 |  |  |         }); | 
 |  |  |         return result; | 
 |  |  | 
 |  |  |         var channle = await GetLifePayChannlesDtoByNum(input.ChannelId); | 
 |  |  |         CheckExtensions.IfTrueThrowUserFriendlyException(channle == null, "渠道不存在"); | 
 |  |  |  | 
 |  |  |         var repeatOrder = await _lifePayOrderRepository.Where(x => x.LifePayOrderType == LifePayOrderTypeEnum.话费订单 && x.PayStatus == LifePayStatusEnum.已支付 | 
 |  |  |         && x.LifePayOrderStatus == LifePayOrderStatusEnum.充值中 && x.OrderParamDetailJsonStr.Contains(input.ProductData.IspCode) | 
 |  |  |         && x.OrderParamDetailJsonStr.Contains(input.ProductData.Phone)).ToListAsync(); | 
 |  |  |         CheckExtensions.IfTrueThrowUserFriendlyException(repeatOrder.Count() > 0, "您有同户号订单正在充值中,请勿重复充值"); | 
 |  |  |  | 
 |  |  |         //var rate = await GetRate(); | 
 |  |  |         //CheckExtensions.IfTrueThrowUserFriendlyException(rate.IsNullOrEmpty(), "未配置折扣"); | 
 |  |  |  | 
 |  |  | 
 |  |  |         var amount = CalculateAmount(input.ProductData.ParValue, rate); | 
 |  |  |  | 
 |  |  |         var platformRate = await _lifePayRateRepository.FirstOrDefaultAsync(r => r.RateType == LifePayRateTypeEnum.供应商折扣价); | 
 |  |  |          | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         var orderInput = new CreateLifePayOrderInput | 
 |  |  |         { | 
 |  |  | 
 |  |  |             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.电费订单 && 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 rate = await GetRate(); | 
 |  |  |         //CheckExtensions.IfTrueThrowUserFriendlyException(rate.IsNullOrEmpty(), "未配置折扣"); | 
 |  |  |         var repeatOrder = await _lifePayOrderRepository.Where(x => x.LifePayOrderType == LifePayOrderTypeEnum.燃气订单 && 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.默认燃气折扣); | 
 |  |  | 
 |  |  |  | 
 |  |  | #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(order.LifePayType.Value, order.OrderNo, desc, order.PayAmount ?? 0, 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(order.LifePayType.Value, order.OrderNo, desc, order.PayAmount??0, ip, input.H5Type); | 
 |  |  | #endif | 
 |  |  |  | 
 |  |  |         return payUrl; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /// <summary> | 
 |  |  |     /// 设置生活缴费支付类型 | 
 |  |  |     /// 获取微信支付的JSAPI | 
 |  |  |     /// </summary> | 
 |  |  |     /// <param name="input"></param> | 
 |  |  |     /// <returns></returns> | 
 |  |  | 
 |  |  |         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 = "生活缴费-"; | 
 |  |  | 
 |  |  |  | 
 |  |  |         //  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 result = await PayTransactionsJsAPI(input.OpenId, input.PayAppId, input.Attach, order.PayAmount ?? 0, input.OrderNo, 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> | 
 |  |  |     /// 修改实际到账金额 | 
 |  |  |     /// </summary> | 
 |  |  |     /// <param name="input"></param> | 
 |  |  |     /// <returns></returns> | 
 |  |  |     public async Task<int> UpdateLifePayOrderActualReceivedAmount(UpdateLifePayOrderInput input) | 
 |  |  |     { | 
 |  |  |         var order = await _lifePayOrderRepository.Where(x => x.Id == input.Id).FirstOrDefaultAsync(); | 
 |  |  |  | 
 |  |  |         CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "订单不存在"); | 
 |  |  |         CheckExtensions.IfTrueThrowUserFriendlyException(order.ACOOLYStatus != ACOOLYStatusEnum.部分充值成功, "该订单无法修改到账金额"); | 
 |  |  |  | 
 |  |  |         order.ActualReceivedAmount = input.ActualReceivedAmount; | 
 |  |  |  | 
 |  |  |         await _lifePayOrderRepository.UpdateAsync(order); | 
 |  |  |  | 
 |  |  |         return Constant.SUCCESS; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /// <summary> | 
 |  |  | 
 |  |  | #endif | 
 |  |  |  | 
 |  |  |         CheckExtensions.IfTrueThrowUserFriendlyException(!result.Success || (result.Code != ACOOLYConstant.Code.SUCCESS && result.Code != ACOOLYConstant.Code.PROCESSING), | 
 |  |  |                                                         "调用ACOOLY接口ConfirmElectricOrder返回错误:" + JsonConvert.SerializeObject(result)); | 
 |  |  |                                                         result.Message); | 
 |  |  |  | 
 |  |  |         return (result.Code, requestInput.RequestNo, result.PhoneChargeOrder.BusiOrderNo); | 
 |  |  |     } | 
 |  |  | 
 |  |  | #endif | 
 |  |  |  | 
 |  |  |         CheckExtensions.IfTrueThrowUserFriendlyException(!result.Success || (result.Code != ACOOLYConstant.Code.SUCCESS && result.Code != ACOOLYConstant.Code.PROCESSING), | 
 |  |  |                                                         "调用ACOOLY接口ConfirmElectricOrder返回错误:" + JsonConvert.SerializeObject(result)); | 
 |  |  |                                                         result.Message); | 
 |  |  |  | 
 |  |  |         return (result.Code, requestInput.RequestNo, result.ElectricChargeOrder.BusiOrderNo); | 
 |  |  |     } | 
 |  |  | 
 |  |  | #endif | 
 |  |  |  | 
 |  |  |         CheckExtensions.IfTrueThrowUserFriendlyException(!result.Success || (result.Code != ACOOLYConstant.Code.SUCCESS && result.Code != ACOOLYConstant.Code.PROCESSING), | 
 |  |  |                                                         "调用ACOOLY接口ConfirmElectricOrder返回错误:" + JsonConvert.SerializeObject(result)); | 
 |  |  |                                                         result.Message); | 
 |  |  |  | 
 |  |  |         return (result.Code, requestInput.RequestNo, result.GasChargeOrder.BusiOrderNo); | 
 |  |  |     } | 
 |  |  | 
 |  |  |             _logger.LogError(ex, "处理生活缴费支付成功回调时异常"); | 
 |  |  |             order.LifePayOrderStatus = LifePayOrderStatusEnum.待退款; | 
 |  |  |             order.LifePayRefundStatus = LifePayRefundStatusEnum.待退款; | 
 |  |  |             order.RefundApplyRemark = ex.Message; | 
 |  |  |         } | 
 |  |  |         _logger.LogError("生活缴费订单状态:" + order.LifePayOrderStatus.ToString()); | 
 |  |  |         await _lifePayOrderRepository.UpdateAsync(order); | 
 |  |  | 
 |  |  |             case LifePayRefundStatusEnum.退款中: | 
 |  |  |                 order.LifePayOrderStatus = LifePayOrderStatusEnum.退款中; | 
 |  |  |                 break; | 
 |  |  |             default:break; | 
 |  |  |             default: break; | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |     /// <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 (input.LifePayRefundType == LifePayRefundTypeEnum.全额退款) | 
 |  |  |         { | 
 |  |  |             input.RefundPrice = order.PayAmount; | 
 |  |  |             input.RefundPrice = order.PayAmount ?? 0; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         if (order.LifePayOrderStatus != LifePayOrderStatusEnum.待退款 || order.PayStatus != LifePayStatusEnum.已支付 || order.LifePayRefundStatus != LifePayRefundStatusEnum.待退款) | 
 |  |  | 
 |  |  |         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)); | 
 |  |  |                 var wxRefundResult = await WxPayDomesticRefunds(order.OrderNo, outRefundNo, order.RefundApplyRemark, Convert.ToInt32(input.RefundPrice * 100), Convert.ToInt32(order.PayAmount * 100)); | 
 |  |  |                 if (wxRefundResult.Status == "SUCCESS") | 
 |  |  |                 { | 
 |  |  |                     order.LifePayOrderStatus = LifePayOrderStatusEnum.已退款; | 
 |  |  | 
 |  |  |     /// <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 | 
 |  |  |         { | 
 |  |  | 
 |  |  |             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 | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |     { | 
 |  |  |         var channles = await _lifePayChannlesRep.Where(x => x.ChannlesName.Contains(input.KeyWords)).Select(x => x.ChannlesNum).ToListAsync(); | 
 |  |  |         var result = (from a in _channelFilter.GetChannelLifePayOrderFilter(_lifePayOrderRepository) | 
 |  |  |                             .Where(x => x.PayStatus != LifePayStatusEnum.未支付) | 
 |  |  |                       .WhereIf(input.BeginFinishTime.HasValue, x => x.FinishTime >= input.BeginFinishTime) | 
 |  |  |                                             .WhereIf(input.EndFinishTime.HasValue, x => x.FinishTime <= input.EndFinishTime) | 
 |  |  |                                             .WhereIf(input.BeginPayTime.HasValue, x => x.PayTime >= input.BeginPayTime) | 
 |  |  | 
 |  |  |                                             .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; | 
 |  |  |         var profit = grossProfit - channlesRakePrice - (premiumRate); | 
 |  |  |  | 
 |  |  |         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 | 
 |  |  |         }; | 
 |  |  |     } | 
 |  |  |  |