| | |
| | | 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) |
| | |
| | | RefundApplyRemark = a.RefundApplyRemark, |
| | | RefundTime = a.RefundTime, |
| | | ChannelName = b.ChannlesName, |
| | | ActualRechargeAmount = a.ActualRechargeAmount, |
| | | ActualRechargeAmount = a.RechargeAmount, |
| | | PlatformDeductionAmount = a.PlatformDeductionAmount, |
| | | ACOOLYStatus = a.ACOOLYStatus, |
| | | LifePayRefundStatus = a.LifePayRefundStatus, |
| | |
| | | |
| | | var result = await (from a in _channelFilter.GetChannelLifePayOrderFilter(_lifePayOrderRepository) |
| | | .Where(x => x.LifePayOrderStatus == LifePayOrderStatusEnum.待退款 || x.LifePayOrderStatus == LifePayOrderStatusEnum.已退款 || x.LifePayOrderStatus == LifePayOrderStatusEnum.退款中 |
| | | || x.LifePayRefundStatus > LifePayRefundStatusEnum.无需退款) |
| | | || (x.LifePayRefundStatus > LifePayRefundStatusEnum.无需退款 && x.LifePayRefundStatus != LifePayRefundStatusEnum.退款驳回)) |
| | | .WhereIf(input.BeginRefundTime.HasValue, x => x.RefundTime >= input.BeginRefundTime) |
| | | .WhereIf(input.EndRefundTime.HasValue, x => x.RefundTime <= input.EndRefundTime) |
| | | .WhereIf(input.BeginRefundApplyTime.HasValue, x => x.RefundApplyTime >= input.BeginRefundApplyTime) |
| | |
| | | RefundCheckRemark = a.RefundCheckRemark, |
| | | RefundApplyRemark = a.RefundApplyRemark, |
| | | RefundApplyTime = a.RefundApplyTime, |
| | | RefundOrderNo = a.RefundOrderNo, |
| | | RefundTime = a.RefundTime, |
| | | RefundPrice = a.RefundPrice, |
| | | ChannelName = b.ChannlesName, |
| | | ActualRechargeAmount = a.ActualRechargeAmount, |
| | | ActualRechargeAmount = a.RechargeAmount, |
| | | PlatformDeductionAmount = a.PlatformDeductionAmount, |
| | | ACOOLYStatus = a.ACOOLYStatus, |
| | | LifePayRefundStatus = a.LifePayRefundStatus, |
| | |
| | | PayAmount = x.PayAmount, |
| | | PhoneNumber = x.PhoneNumber, |
| | | RefundOrderNo = x.RefundOrderNo, |
| | | RefundApplyTime = x.RefundApplyTime, |
| | | ChannelName = x.ChannelName, |
| | | CreationTime = x.CreationTime, |
| | | ACOOLYStatus = x.ACOOLYStatus, |
| | |
| | | s.SerialNumber = ++i; |
| | | s.ACOOLYStatusStr = s.ACOOLYStatus.GetDescription(); |
| | | s.LifePayOrderTypeStr = s.LifePayOrderType.GetDescription(); |
| | | s.CreationTimeStr = s.CreationTime.ToString(LifePaymentConstant.DateTimeFormatStr.yyyyMMddHHmm); |
| | | 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); |
| | | }); |
| | | 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); |
| | | var orderpirce = await GetOrderPrice(order.RechargeAmount, order.PayAmount, order.PlatformRate, order.ChannleRate, order.ChannlesRakeRate, order.PremiumRate); |
| | | |
| | | |
| | | var result = new LifePayOrderOutput() |
| | | { |
| | | { |
| | | UserName = user.Name, |
| | | UserPhoneNumber = user.PhoneNumber, |
| | | DiscountAmount = order.DiscountAmount, |
| | |
| | | RefundTime = order.RefundTime, |
| | | ACOOLYOrderNo = order.ACOOLYOrderNo, |
| | | LifePayRefundStatus = order.LifePayRefundStatus, |
| | | ActualRechargeAmount = order.ActualRechargeAmount, |
| | | ActualRechargeAmount = order.RechargeAmount, |
| | | RefundPrice = order.RefundPrice, |
| | | PlatformRate = order.PlatformRate, |
| | | PlatformPrice = order.PlatformDeductionAmount, |
| | |
| | | { |
| | | 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.LifePayRefundStatusStr.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 rate = await GetRate(); |
| | | CheckExtensions.IfTrueThrowUserFriendlyException(rate.IsNullOrEmpty(), "未配置折扣"); |
| | | //var rate = await GetRate(); |
| | | //CheckExtensions.IfTrueThrowUserFriendlyException(rate.IsNullOrEmpty(), "未配置折扣"); |
| | | |
| | | //var rate = await GetLifePayRate(); |
| | | var rate = await GetLifePayRate(channle, LifePayRateTypeEnum.默认话费折扣); |
| | | |
| | | var amount = CalculateAmount(input.ProductData.ParValue, rate.FirstOrDefault(x => x.RateType == LifePayRateTypeEnum.默认话费折扣).Rate); |
| | | var amount = CalculateAmount(input.ProductData.ParValue, rate); |
| | | |
| | | var platformRate = await _lifePayRateRepository.FirstOrDefaultAsync(r => r.RateType == LifePayRateTypeEnum.供应商折扣价); |
| | | |
| | | |
| | | |
| | | var orderInput = new CreateLifePayOrderInput |
| | | { |
| | |
| | | ChannelId = channle.ChannlesNum, |
| | | PlatformRate = platformRate.Rate, |
| | | PlatformDeductionAmount = amount.RechargeAmount * platformRate.Rate /100, |
| | | ChannleRate = channle.ChannlesRate, |
| | | ChannleRate = rate, |
| | | ChannlesRakeRate = channle.ChannlesRakeRate, |
| | | //ChannlesRakePrice = amount.RechargeAmount * (channle.ChannlesRate - platformRate.Rate) / 100 * channle.ChannlesRakeRate / 100 |
| | | }; |
| | |
| | | CheckExtensions.IfTrueThrowUserFriendlyException(channle == null, "渠道不存在"); |
| | | CheckExtensions.IfTrueThrowUserFriendlyException(channle.Status == LifePayChannelsStatsEnum.禁用, "渠道已被禁用"); |
| | | |
| | | var rate = await GetRate(); |
| | | CheckExtensions.IfTrueThrowUserFriendlyException(rate.IsNullOrEmpty(), "未配置折扣"); |
| | | //var rate = await GetRate(); |
| | | //CheckExtensions.IfTrueThrowUserFriendlyException(rate.IsNullOrEmpty(), "未配置折扣"); |
| | | |
| | | var amount = CalculateAmount(input.ProductData.ParValue, rate.FirstOrDefault(x => x.RateType == LifePayRateTypeEnum.默认电费折扣).Rate); |
| | | |
| | | var rate = await GetLifePayRate(channle, LifePayRateTypeEnum.默认电费折扣); |
| | | |
| | | var amount = CalculateAmount(input.ProductData.ParValue, rate); |
| | | |
| | | var platformRate = await _lifePayRateRepository.FirstOrDefaultAsync(r => r.RateType == LifePayRateTypeEnum.供应商折扣价); |
| | | |
| | |
| | | RechargeAmount = amount.RechargeAmount, |
| | | ChannelId = channle.ChannlesNum, |
| | | PlatformRate = platformRate.Rate, |
| | | ChannleRate = channle.ChannlesRate, |
| | | ChannleRate = rate, |
| | | ChannlesRakeRate = channle.ChannlesRakeRate, |
| | | }; |
| | | |
| | |
| | | CheckExtensions.IfTrueThrowUserFriendlyException(channle == null, "渠道不存在"); |
| | | CheckExtensions.IfTrueThrowUserFriendlyException(channle.Status == LifePayChannelsStatsEnum.禁用, "渠道已被禁用"); |
| | | |
| | | var rate = await GetRate(); |
| | | CheckExtensions.IfTrueThrowUserFriendlyException(rate.IsNullOrEmpty(), "未配置折扣"); |
| | | //var rate = await GetRate(); |
| | | //CheckExtensions.IfTrueThrowUserFriendlyException(rate.IsNullOrEmpty(), "未配置折扣"); |
| | | |
| | | var amount = CalculateAmount(input.ProductData.ParValue, rate.FirstOrDefault(x => x.RateType == LifePayRateTypeEnum.默认燃气折扣).Rate); |
| | | |
| | | var rate = await GetLifePayRate(channle, LifePayRateTypeEnum.默认燃气折扣); |
| | | |
| | | var amount = CalculateAmount(input.ProductData.ParValue, rate); |
| | | |
| | | var platformRate = await _lifePayRateRepository.FirstOrDefaultAsync(r => r.RateType == LifePayRateTypeEnum.供应商折扣价); |
| | | |
| | |
| | | PayAmount = amount.PayAmont, |
| | | DiscountAmount = amount.DiscountAmount, |
| | | RechargeAmount = amount.RechargeAmount, |
| | | ChannelId = channle.ChannlesNum |
| | | ChannelId = channle.ChannlesNum, |
| | | PlatformRate = platformRate.Rate, |
| | | ChannleRate = rate, |
| | | ChannlesRakeRate = channle.ChannlesRakeRate, |
| | | }; |
| | | |
| | | await CreateLifePayOrder(orderInput); |
| | |
| | | } |
| | | |
| | | /// <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 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); |
| | |
| | | |
| | | break; |
| | | case LifePayTypeEnum.AliPay: |
| | | var aliRefundResult = await AliTradeRefund(new AlipayTradeRefundRequest() { OutTradeNo = order.OrderNo, RefundAmount = Convert.ToInt32(input.RefundPrice * 100).ToString() }); |
| | | var aliRefundResult = await AliTradeRefund(new AlipayTradeRefundRequest() { OutTradeNo = order.OrderNo, RefundAmount = input.RefundPrice.ToString() }); |
| | | if (aliRefundResult.Code != AlipayResultCode.Success) |
| | | { |
| | | throw new UserFriendlyException("退款失败"); |
| | | throw new UserFriendlyException("退款失败:" + aliRefundResult.SubMsg); |
| | | } |
| | | |
| | | order.LifePayOrderStatus = LifePayOrderStatusEnum.已退款; |
| | |
| | | private (decimal PayAmont, decimal DiscountAmount, decimal RechargeAmount) CalculateAmount(decimal amount, decimal rate) |
| | | { |
| | | /// 正常支付 |
| | | //var payAmount = decimal.Round(amount * rate / 100, 2, MidpointRounding.AwayFromZero); |
| | | var payAmount = decimal.Round(amount * rate / 100, 2, MidpointRounding.AwayFromZero); |
| | | |
| | | /// 1分钱支付 |
| | | decimal payAmount = 0.01m; |
| | | //decimal payAmount = 0.01m; |
| | | |
| | | CheckExtensions.IfTrueThrowUserFriendlyException(payAmount < 0.01m, "支付金额错误"); |
| | | |
| | |
| | | { |
| | | 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) |
| | |
| | | RefundApplyRemark = a.RefundApplyRemark, |
| | | RefundApplyTime = a.RefundApplyTime, |
| | | RefundTime = a.RefundTime, |
| | | RefundOrderNo = a.RefundOrderNo, |
| | | RefundPrice = a.RefundPrice, |
| | | ChannelName = b.ChannlesName, |
| | | ActualRechargeAmount = a.ActualRechargeAmount, |
| | |
| | | }; |
| | | } |
| | | |
| | | public async Task<decimal> GetLifePayRate(string channelId, LifePayRateTypeEnum lifePayRateType) |
| | | public async Task<decimal> GetLifePayRate(CreateEditPayChannelsInput channel, LifePayRateTypeEnum lifePayRateType) |
| | | { |
| | | if (string.IsNullOrEmpty(channelId)) |
| | | if (channel == null) |
| | | { |
| | | var rate = await GetRate(); |
| | | CheckExtensions.IfTrueThrowUserFriendlyException(rate.IsNullOrEmpty(), "未配置折扣"); |
| | |
| | | } |
| | | else |
| | | { |
| | | var channel = await _lifePayChannlesRep.Where(x => x.ChannlesNum == channelId).FirstOrDefaultAsync(); |
| | | |
| | | CheckExtensions.IfTrueThrowUserFriendlyException(channel == null, "未找到对应渠道"); |
| | | return channel.ChannlesRate; |
| | | } |
| | | } |