| | |
| | | using Alipay.EasySDK.Payment.Common.Models; |
| | | using LifePayment.Application.Contracts; |
| | | using LifePayment.Application.LifePay; |
| | | using LifePayment.Domain; |
| | | using LifePayment.Domain.LifePay; |
| | | using LifePayment.Domain.Models; |
| | |
| | | private readonly IAliPayApi _aliPayApi; |
| | | private readonly IAlipayInterfaceManager _alipayInterfaceManager; |
| | | private readonly IWxPayApi _wxPayApi; |
| | | private readonly ILifePayRateService _lifePayRateService; |
| | | private readonly WxPayOption _wxPayOptions; |
| | | private readonly InitSetting _initSettingOptions; |
| | | |
| | |
| | | IRepository<LifePayAccount, Guid> lifePayAccount, |
| | | IDataFilter dataFilter, |
| | | IChannelFilter channelFilter, |
| | | ILifePayRateService lifePayRateService, |
| | | IAbpDistributedLock distributedLock) |
| | | { |
| | | _logger = logger; |
| | |
| | | _channelFilter = channelFilter; |
| | | this.distributedLock = distributedLock; |
| | | _operateHistory = operateHistory; |
| | | _lifePayRateService = lifePayRateService; |
| | | } |
| | | |
| | | #region 查询 |
| | |
| | | public async Task<LifePayRefundOrderOutput> GetLifePayRefundOrderDetail(string orderNo) |
| | | { |
| | | var order = await _lifePayOrderRepository.Where(x => x.OrderNo == orderNo).FirstOrDefaultAsync(); |
| | | var platformRate = await _lifePayRateRepository.FirstOrDefaultAsync(r => r.RateType == LifePayRateTypeEnum.供应商折扣价); |
| | | //var platformRate = await _lifePayRateRepository.FirstOrDefaultAsync(r => r.RateType == LifePayRateTypeEnum.供应商折扣价); |
| | | var channle = await _lifePayChannlesRep.FirstOrDefaultAsync(r => r.ChannlesNum == order.ChannelId); |
| | | var premium = await _lifePayPremiumRepository.Where(x => x.PremiumType == order.LifePayType).FirstOrDefaultAsync(); |
| | | CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "订单不存在"); |
| | |
| | | && x.OrderParamDetailJsonStr.Contains(input.ProductData.Phone)).AnyAsync(); |
| | | CheckExtensions.IfTrueThrowUserFriendlyException(repeatOrder, "您有同户号订单正在充值中,请勿重复充值"); |
| | | |
| | | var rate = await GetLifePayRate(channle, LifePayRateTypeEnum.默认话费折扣); |
| | | var rateChannel = await GetLifePayRate(channle,input.ProductData.IspCode); |
| | | //平台折扣 |
| | | var rate = rateChannel.Rate; |
| | | |
| | | var amount = CalculateAmount(input.ProductData.ParValue, rate); |
| | | |
| | | var platformRate = await _lifePayRateRepository.FirstOrDefaultAsync(r => r.RateType == LifePayRateTypeEnum.供应商折扣价); |
| | | //供应商折扣价 |
| | | var platformRate = rateChannel.SupplierRate; |
| | | |
| | | var orderInput = new CreateLifePayOrderInput |
| | | { |
| | |
| | | DiscountAmount = amount.DiscountAmount, |
| | | RechargeAmount = amount.RechargeAmount, |
| | | ChannelId = channle.ChannlesNum, |
| | | PlatformRate = platformRate.Rate, |
| | | PlatformDeductionAmount = amount.RechargeAmount * platformRate.Rate / 100, |
| | | PlatformRate = platformRate, |
| | | PlatformDeductionAmount = amount.RechargeAmount * platformRate / 100, |
| | | ChannleRate = rate, |
| | | ChannlesRakeRate = channle.ChannlesRakeRate, |
| | | }; |
| | |
| | | && x.OrderParamDetailJsonStr.Contains(input.ProductData.ElectricAccount)).AnyAsync(); |
| | | CheckExtensions.IfTrueThrowUserFriendlyException(repeatOrder, "您有同户号订单正在充值中,请勿重复充值"); |
| | | |
| | | var rateChannel = await GetLifePayRate(channle, input.ProductData.ElectricType); |
| | | //平台折扣 |
| | | var rate = rateChannel.Rate; |
| | | |
| | | var rate = await GetLifePayRate(channle, LifePayRateTypeEnum.默认电费折扣); |
| | | var amount = CalculateAmount(input.ProductData.ParValue, rate); |
| | | var platformRate = await _lifePayRateRepository.FirstOrDefaultAsync(r => r.RateType == LifePayRateTypeEnum.供应商折扣价); |
| | | //供应商折扣价 |
| | | var platformRate = rateChannel.SupplierRate; |
| | | |
| | | var orderInput = new CreateLifePayOrderInput |
| | | { |
| | |
| | | DiscountAmount = amount.DiscountAmount, |
| | | RechargeAmount = amount.RechargeAmount, |
| | | ChannelId = channle.ChannlesNum, |
| | | PlatformRate = platformRate.Rate, |
| | | PlatformDeductionAmount = amount.RechargeAmount * platformRate.Rate / 100, |
| | | PlatformRate = platformRate, |
| | | PlatformDeductionAmount = amount.RechargeAmount * platformRate / 100, |
| | | ChannleRate = rate, |
| | | ChannlesRakeRate = channle.ChannlesRakeRate, |
| | | }; |
| | |
| | | && x.OrderParamDetailJsonStr.Contains(input.ProductData.GasAccount)).AnyAsync(); |
| | | CheckExtensions.IfTrueThrowUserFriendlyException(repeatOrder, "您有同户号订单正在充值中,请勿重复充值"); |
| | | |
| | | |
| | | var rate = await GetLifePayRate(channle, LifePayRateTypeEnum.默认燃气折扣); |
| | | var rateChannel = await GetLifePayRate(channle, input.ProductData.GasOrgType); |
| | | //平台折扣 |
| | | var rate = rateChannel.Rate; |
| | | |
| | | var amount = CalculateAmount(input.ProductData.ParValue, rate); |
| | | |
| | | var platformRate = await _lifePayRateRepository.FirstOrDefaultAsync(r => r.RateType == LifePayRateTypeEnum.供应商折扣价); |
| | | //供应商折扣价 |
| | | var platformRate = rateChannel.SupplierRate; |
| | | |
| | | var orderInput = new CreateLifePayOrderInput |
| | | { |
| | |
| | | DiscountAmount = amount.DiscountAmount, |
| | | RechargeAmount = amount.RechargeAmount, |
| | | ChannelId = channle.ChannlesNum, |
| | | PlatformRate = platformRate.Rate, |
| | | PlatformDeductionAmount = amount.RechargeAmount * platformRate.Rate / 100, |
| | | PlatformRate = platformRate, |
| | | PlatformDeductionAmount = amount.RechargeAmount * platformRate / 100, |
| | | ChannleRate = rate, |
| | | ChannlesRakeRate = channle.ChannlesRakeRate, |
| | | }; |
| | |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 退款成功处理 |
| | | /// </summary> |
| | | /// <param name="input"></param> |
| | | /// <returns></returns> |
| | | public async Task<int> LifePayRefundsSuccessHandler(AddLifePayExpensesReceiptsInput input) |
| | | { |
| | | var order = await _lifePayOrderRepository.Where(x => x.OrderNo == input.OrderNo).FirstOrDefaultAsync(); |
| | | CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "订单不存在"); |
| | | CheckExtensions.IfTrueThrowUserFriendlyException(order.LifePayRefundStatus != LifePayRefundStatusEnum.待退款 && order.LifePayRefundStatus != LifePayRefundStatusEnum.退款中, "当前订单状态无法查看退款流水"); |
| | | CheckExtensions.IfTrueThrowUserFriendlyException(order.RefundOrderNo.IsNullOrEmpty(), "不存在退款流水订单"); |
| | | |
| | | await LifePayRefundsHandler(input.OrderNo, LifePayRefundStatusEnum.已退款); |
| | | // 插入收支流水 |
| | | await _lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput() |
| | | { |
| | | OrderNo = input.OrderNo, |
| | | OutRefundNo = input.OutRefundNo, |
| | | OutOrderNo = input.OutOrderNo, |
| | | LifePayType = input.LifePayType, |
| | | ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Receipts |
| | | }); |
| | | |
| | | #region 记录日志 |
| | | |
| | | await LifePayOrderHistory("更新订单退款状态", "更新订单退款状态", order.Id, (int)OperateHistoryTypeEnum.LifePayRefund); |
| | | |
| | | #endregion |
| | | |
| | | return Constant.SUCCESS; |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// ACOOLYO订单通知处理 |
| | |
| | | if (order.LifePayOrderStatus == status && order.ACOOLYStatus == acoolyStatus) |
| | | { |
| | | _logger.LogInformation($"订单({orderNo})已处理该状态"); |
| | | return; |
| | | } |
| | | |
| | | if (order.LifePayOrderStatus == LifePayOrderStatusEnum.已退款) |
| | | { |
| | | _logger.LogInformation($"订单已退款,不在处理"); |
| | | return; |
| | | } |
| | | |
| | |
| | | await _lifePayOrderService.CreatLifePayConsumption(acoolyStatus, order.OrderNo, order.ACOOLYOrderNo, |
| | | order.PlatformDeductionAmount ?? 0, order.ChannelId, order.CreationTime, order.FinishTime, order.ChannleRate, parValue, actualParValue); |
| | | |
| | | await CurrentUnitOfWork.CompleteAsync(); |
| | | await CurrentUnitOfWork.SaveChangesAsync(); |
| | | |
| | | _logger.LogInformation("事务完成"); |
| | | } |
| | |
| | | dto.PromoterId = promoter.Id; |
| | | } |
| | | |
| | | //TODO 后续需要修改 现在的供应商折扣价根据运营商不同 配置不同 不是统一配置了 |
| | | var rate = await _lifePayRateRepository.FirstOrDefaultAsync(it => it.RateType == LifePayRateTypeEnum.供应商折扣价); |
| | | CheckExtensions.IfTrueThrowUserFriendlyException(rate != null && input.ChannlesRate < rate.Rate, "渠道折扣无法低于供应商折扣"); |
| | | |
| | |
| | | await _distributedEventBus.PublishAsync(recordEto, false); |
| | | } |
| | | |
| | | private async Task LifePayOrderHistory(string operateContent, string operateName, Guid relationId, int? tableType = (int)OperateHistoryTypeEnum.LifePayRefund) |
| | | public async Task LifePayOrderHistory(string operateContent, string operateName, Guid relationId, int? tableType = (int)OperateHistoryTypeEnum.LifePayRefund) |
| | | { |
| | | var operateHistory = new OperateHistory |
| | | { |
| | |
| | | }; |
| | | } |
| | | |
| | | public async Task<decimal> GetLifePayRate(CreateEditPayChannelsInput channel, LifePayRateTypeEnum lifePayRateType) |
| | | public async Task<GetLifePayRateOutput> GetLifePayRate(CreateEditPayChannelsInput channel, string code) |
| | | { |
| | | var rateChannel = await _lifePayRateService.GetRateChannelByCode(code); |
| | | CheckExtensions.IfTrueThrowUserFriendlyException(rateChannel.Id.IsEmpty(), "未配置折扣"); |
| | | if (channel == null) |
| | | { |
| | | var rate = await GetRate(); |
| | | CheckExtensions.IfTrueThrowUserFriendlyException(rate.IsNullOrEmpty(), "未配置折扣"); |
| | | var result = rate.FirstOrDefault(x => x.RateType == lifePayRateType).Rate; |
| | | return result; |
| | | return new GetLifePayRateOutput |
| | | { |
| | | Rate = rateChannel.PlatformRate, |
| | | SupplierRate = rateChannel.SupplierRate |
| | | }; |
| | | } |
| | | else |
| | | { |
| | | return channel.ChannlesRate; |
| | | return new GetLifePayRateOutput { |
| | | Rate= channel.ChannlesRate, |
| | | SupplierRate = rateChannel.SupplierRate |
| | | }; |
| | | } |
| | | } |
| | | |