From f7bb0825bc06b8cea32caa44d2326dde51990e77 Mon Sep 17 00:00:00 2001 From: zhengyiming <540361168@qq.com> Date: 星期四, 11 九月 2025 11:10:55 +0800 Subject: [PATCH] feat: 公告 --- LifePayment/LifePayment.Application/LifePay/LifePayService.cs | 208 +++++++++++++++++++++++++++++---------------------- 1 files changed, 118 insertions(+), 90 deletions(-) diff --git a/LifePayment/LifePayment.Application/LifePay/LifePayService.cs b/LifePayment/LifePayment.Application/LifePay/LifePayService.cs index 258cc91..dcbc06f 100644 --- a/LifePayment/LifePayment.Application/LifePay/LifePayService.cs +++ b/LifePayment/LifePayment.Application/LifePay/LifePayService.cs @@ -1,5 +1,6 @@ 锘縰sing Alipay.EasySDK.Payment.Common.Models; using LifePayment.Application.Contracts; +using LifePayment.Application.LifePay; using LifePayment.Domain; using LifePayment.Domain.LifePay; using LifePayment.Domain.Models; @@ -50,6 +51,7 @@ private readonly IAliPayApi _aliPayApi; private readonly IAlipayInterfaceManager _alipayInterfaceManager; private readonly IWxPayApi _wxPayApi; + private readonly ILifePayRateService _lifePayRateService; private readonly WxPayOption _wxPayOptions; private readonly InitSetting _initSettingOptions; @@ -77,6 +79,7 @@ IRepository<LifePayAccount, Guid> lifePayAccount, IDataFilter dataFilter, IChannelFilter channelFilter, + ILifePayRateService lifePayRateService, IAbpDistributedLock distributedLock) { _logger = logger; @@ -101,6 +104,7 @@ _channelFilter = channelFilter; this.distributedLock = distributedLock; _operateHistory = operateHistory; + _lifePayRateService = lifePayRateService; } #region 鏌ヨ @@ -512,7 +516,7 @@ 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.渚涘簲鍟嗘姌鎵d环); + //var platformRate = await _lifePayRateRepository.FirstOrDefaultAsync(r => r.RateType == LifePayRateTypeEnum.渚涘簲鍟嗘姌鎵d环); 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, "璁㈠崟涓嶅瓨鍦�"); @@ -1086,11 +1090,14 @@ && 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.渚涘簲鍟嗘姌鎵d环); + //渚涘簲鍟嗘姌鎵d环 + var platformRate = rateChannel.SupplierRate; var orderInput = new CreateLifePayOrderInput { @@ -1106,8 +1113,8 @@ 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, }; @@ -1140,10 +1147,13 @@ && 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.渚涘簲鍟嗘姌鎵d环); + //渚涘簲鍟嗘姌鎵d环 + var platformRate = rateChannel.SupplierRate; var orderInput = new CreateLifePayOrderInput { @@ -1158,8 +1168,8 @@ 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, }; @@ -1192,12 +1202,14 @@ && 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.渚涘簲鍟嗘姌鎵d环); + //渚涘簲鍟嗘姌鎵d环 + var platformRate = rateChannel.SupplierRate; var orderInput = new CreateLifePayOrderInput { @@ -1213,8 +1225,8 @@ 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, }; @@ -1533,82 +1545,91 @@ { await using var orderLock = await distributedLock.TryAcquireAsync($"LockKey:UpdateOrder:{orderNo}", TimeSpan.FromSeconds(60)); _logger.LogInformation($"閿侊細LockKey:UpdateOrder:{orderNo} - {orderLock != null}"); - - var order = await _lifePayOrderRepository.Where(x => x.OrderNo == orderNo).FirstOrDefaultAsync(); - - CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "璁㈠崟涓嶅瓨鍦�"); - - if (order.ACOOLYStatus.HasValue && (int)order.ACOOLYStatus > (int)acoolyStatus) + try { - _logger.LogInformation($"璁㈠崟锛坽orderNo}锛夌敱{order.ACOOLYStatus}鑷硔acoolyStatus}澶辫触锛屼笉鍙洖婊氱姸鎬�"); - return; - } + var order = await _lifePayOrderRepository.Where(x => x.OrderNo == orderNo).FirstOrDefaultAsync(); - if (order.LifePayOrderStatus == status && order.ACOOLYStatus == acoolyStatus) - { - _logger.LogInformation($"璁㈠崟锛坽orderNo}锛夊凡澶勭悊璇ョ姸鎬�"); - return; - } + CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "璁㈠崟涓嶅瓨鍦�"); - order.ActualReceivedAmount = actualParValue; - order.PlatformDeductionAmount = Math.Round((order.ActualReceivedAmount ?? 0) * (order.PlatformRate ?? 0) / 100, 2); - - if (acoolyOrderNo.IsNotNullOrEmpty()) - { - order.ACOOLYOrderNo = acoolyOrderNo; - } - - if (status == LifePayOrderStatusEnum.寰呴��娆�) - { - order.LifePayRefundStatus = LifePayRefundStatusEnum.寰呴��娆�; - } - - if (refundApplyRemark.IsNotNullOrEmpty()) - { - order.RefundApplyRemark = refundApplyRemark; - } - - order.LifePayOrderStatus = status; - order.ACOOLYStatus = acoolyStatus; - - if (order.LifePayOrderStatus == LifePayOrderStatusEnum.宸插畬鎴� - || order.LifePayOrderStatus == LifePayOrderStatusEnum.宸查��娆�) - { - order.FinishTime = DateTime.Now; - } - - if (order.ACOOLYStatus == ACOOLYStatusEnum.宸查��娆� || order.ACOOLYStatus == ACOOLYStatusEnum.閮ㄥ垎鍏呭�兼垚鍔�) - { - order.RefundPrice = Math.Round((1 - ((order.ActualReceivedAmount ?? 0) / (order.RechargeAmount ?? 0))) * (order.PayAmount ?? 0), 2); - } - - if (order.LifePayOrderStatus == LifePayOrderStatusEnum.宸插畬鎴�) - { - ///缁撶畻娓犻亾浣i噾 - /// 姣涘埄 - var grossProfit = order.RechargeAmount * (order.ChannleRate - order.PlatformRate) / 100; - /// 娓犻亾浣i噾 锛�(鍏呭�奸潰棰� * 娓犻亾鎶樻墸姣斾緥)-(鍏呭�奸潰棰� * 骞冲彴鎶樻墸姣斾緥)锛�* 浣i噾姣斾緥 - var channlesRakePrice = grossProfit * (order.ChannlesRakeRate) / 100; - if (channlesRakePrice.HasValue) + if (order.ACOOLYStatus.HasValue && (int)order.ACOOLYStatus > (int)acoolyStatus) { - 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); + _logger.LogInformation($"璁㈠崟锛坽orderNo}锛夌敱{order.ACOOLYStatus}鑷硔acoolyStatus}澶辫触锛屼笉鍙洖婊氱姸鎬�"); + return; } + + if (order.LifePayOrderStatus == status && order.ACOOLYStatus == acoolyStatus) + { + _logger.LogInformation($"璁㈠崟锛坽orderNo}锛夊凡澶勭悊璇ョ姸鎬�"); + return; + } + + order.ActualReceivedAmount = actualParValue; + order.PlatformDeductionAmount = Math.Round((order.ActualReceivedAmount ?? 0) * (order.PlatformRate ?? 0) / 100, 2); + + if (acoolyOrderNo.IsNotNullOrEmpty()) + { + order.ACOOLYOrderNo = acoolyOrderNo; + } + + if (status == LifePayOrderStatusEnum.寰呴��娆�) + { + order.LifePayRefundStatus = LifePayRefundStatusEnum.寰呴��娆�; + } + + if (refundApplyRemark.IsNotNullOrEmpty()) + { + order.RefundApplyRemark = refundApplyRemark; + } + + order.LifePayOrderStatus = status; + order.ACOOLYStatus = acoolyStatus; + + if (order.LifePayOrderStatus == LifePayOrderStatusEnum.宸插畬鎴� + || order.LifePayOrderStatus == LifePayOrderStatusEnum.宸查��娆�) + { + order.FinishTime = DateTime.Now; + } + + if (order.ACOOLYStatus == ACOOLYStatusEnum.宸查��娆� || order.ACOOLYStatus == ACOOLYStatusEnum.閮ㄥ垎鍏呭�兼垚鍔�) + { + order.RefundPrice = Math.Round((1 - ((order.ActualReceivedAmount ?? 0) / (order.RechargeAmount ?? 0))) * (order.PayAmount ?? 0), 2); + } + + if (order.LifePayOrderStatus == LifePayOrderStatusEnum.宸插畬鎴�) + { + ///缁撶畻娓犻亾浣i噾 + /// 姣涘埄 + var grossProfit = order.RechargeAmount * (order.ChannleRate - order.PlatformRate) / 100; + /// 娓犻亾浣i噾 锛�(鍏呭�奸潰棰� * 娓犻亾鎶樻墸姣斾緥)-(鍏呭�奸潰棰� * 骞冲彴鎶樻墸姣斾緥)锛�* 浣i噾姣斾緥 + 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, order.ChannleRate, parValue, actualParValue); + + await CurrentUnitOfWork.SaveChangesAsync(); + + _logger.LogInformation("浜嬪姟瀹屾垚"); } - - /// 鍒涘缓鐢熸椿缂磋垂娑堣垂璁板綍 - await _lifePayOrderService.CreatLifePayConsumption(acoolyStatus, order.OrderNo, order.ACOOLYOrderNo, - order.PlatformDeductionAmount ?? 0, order.ChannelId, order.CreationTime, order.FinishTime, order.ChannleRate, parValue, actualParValue); - - await CurrentUnitOfWork.SaveChangesAsync(); + catch (Exception ex) + { + await CurrentUnitOfWork.RollbackAsync(); + _logger.LogError($"渚涘簲鍟嗗洖璋冨紓甯革細{ex.Message}", ex); + } } /// <summary> @@ -1908,6 +1929,7 @@ dto.PromoterId = promoter.Id; } + //TODO 鍚庣画闇�瑕佷慨鏀� 鐜板湪鐨勪緵搴斿晢鎶樻墸浠锋牴鎹繍钀ュ晢涓嶅悓 閰嶇疆涓嶅悓 涓嶆槸缁熶竴閰嶇疆浜� var rate = await _lifePayRateRepository.FirstOrDefaultAsync(it => it.RateType == LifePayRateTypeEnum.渚涘簲鍟嗘姌鎵d环); CheckExtensions.IfTrueThrowUserFriendlyException(rate != null && input.ChannlesRate < rate.Rate, "娓犻亾鎶樻墸鏃犳硶浣庝簬渚涘簲鍟嗘姌鎵�"); @@ -2440,18 +2462,24 @@ }; } - 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 + }; } } -- Gitblit v1.9.1