|  |  |  | 
|---|
|  |  |  | 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 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, order.PayAmount, order.PlatformRate ?? 0, order.ChannleRate ?? 0, order.ChannlesRakeRate ?? 0, order.PremiumRate ?? 0); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var result = new LifePayOrderOutput() | 
|---|
|  |  |  | 
|---|
|  |  |  | 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 | 
|---|
|  |  |  | 
|---|
|  |  |  | 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, "订单不存在"); | 
|---|
|  |  |  | 
|---|
|  |  |  | 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 | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | .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, | 
|---|
|  |  |  | 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, | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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, | 
|---|
|  |  |  | 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 | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | 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 | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|