From d7b01cca243ea2a767adbb1418a52258b4f2d765 Mon Sep 17 00:00:00 2001 From: zhengyuxuan <zhengyuxuan1995> Date: 星期五, 21 三月 2025 17:27:07 +0800 Subject: [PATCH] fix:状态更新 --- LifePayment/LifePayment.Application/LifePay/LifePayService.cs | 154 +++++++++++++++++++++------------------------------ 1 files changed, 64 insertions(+), 90 deletions(-) diff --git a/LifePayment/LifePayment.Application/LifePay/LifePayService.cs b/LifePayment/LifePayment.Application/LifePay/LifePayService.cs index e24db15..c0a5a6f 100644 --- a/LifePayment/LifePayment.Application/LifePay/LifePayService.cs +++ b/LifePayment/LifePayment.Application/LifePay/LifePayService.cs @@ -26,6 +26,7 @@ using Volo.Abp.Domain.Entities; using Volo.Abp.ObjectMapping; using NPOI.SS.Formula.Functions; +using StackExchange.Redis; namespace LifePayment.Application; @@ -60,7 +61,6 @@ IRepository<LifePayUser, Guid> lifePayUserRepository, IRepository<LifePayPremium, Guid> lifePayPremiumRepository, IRepository<LifePayIntroInfo, Guid> lifePayIntroInfoRepository, - IRepository<DallyStatistics, Guid> dallyStatisticsRepository, IRepository<OperateHistory, Guid> operateHistory, IAliPayApi aliPayApi, IAlipayInterfaceManager aliPayInterfaceManager, @@ -78,7 +78,6 @@ _lifePayUserRepository = lifePayUserRepository; _lifePayPremiumRepository = lifePayPremiumRepository; _lifePayIntroInfoRepository = lifePayIntroInfoRepository; - _dallyStatisticsRepository = dallyStatisticsRepository; _aliPayApi = aliPayApi; _alipayInterfaceManager = aliPayInterfaceManager; _wxPayApi = wxPayApi; @@ -93,44 +92,6 @@ #region 鏌ヨ - public async Task<TopStatisticsOutput> GetTopStatistics() - { - var today = DateTime.Now.Date; - var statistics = await _dallyStatisticsRepository.Where(x => x.CreationTime.Date == today).FirstOrDefaultAsync(); - if (statistics == null) - { - var accumulatedReceipts = await _lifePayOrderRepository.Where(x => x.CreationTime < today).SumAsync(x => x.PayAmount); - var receiptsYesterday = await _lifePayOrderRepository.Where(x => x.CreationTime >= today.AddDays(-1) && x.CreationTime < today).SumAsync(x => x.PayAmount); - var accumulatedOrders = await _lifePayOrderRepository.Where(x => x.CreationTime < today).CountAsync(); - var accumulatedIncome = await _lifePayOrderRepository.Where(x => x.CreationTime < today).SumAsync(x => x.ActualRechargeAmount); - var ordersNumYesterday = await _lifePayOrderRepository.Where(x => x.CreationTime >= today.AddDays(-1) && x.CreationTime < today).CountAsync(); - var yesterdaySuccess = await _lifePayOrderRepository.Where(x => x.CreationTime >= today.AddDays(-1) && x.CreationTime < today && x.LifePayOrderStatus == LifePayOrderStatusEnum.宸插畬鎴�).CountAsync(); - var yesterdayFail = await _lifePayOrderRepository.Where(x => x.CreationTime >= today.AddDays(-1) && x.CreationTime < today && x.LifePayOrderStatus == LifePayOrderStatusEnum.宸插け璐�).CountAsync(); - var accumulatedUsers = await _lifePayUserRepository.CountAsync(); - - var entity = new DallyStatistics() - { - Id = GuidGenerator.Create(), - CreationTime = DateTime.Now, - Amount = 0, - AccumulatedReceipts = accumulatedReceipts, - ReceiptsYesterday = receiptsYesterday, - AccumulatedOrders = accumulatedOrders, - OrdersNumYesterday = ordersNumYesterday, - YesterdaySuccess = yesterdaySuccess, - YesterdayFail = yesterdayFail, - AccumulatedUsers = accumulatedUsers, - }; - await _dallyStatisticsRepository.InsertAsync(entity); - //var result = ObjectMapper.Map<DallyStatistics, TopStatisticsOutput>(entity); - return new TopStatisticsOutput(); - } - else - { - var result = ObjectMapper.Map<DallyStatistics, TopStatisticsOutput>(statistics); - return result; - } - } /// <summary> /// 鑾峰彇鐢佃垂闈㈠�� @@ -329,8 +290,7 @@ { var result = await (from a in _channelFilter.GetChannelLifePayOrderFilter(_lifePayOrderRepository) - .Where(x => x.PayStatus == LifePayStatusEnum.寰呴��娆� || x.PayStatus == LifePayStatusEnum.宸查��娆� || x.PayStatus == LifePayStatusEnum.閫�娆句腑 - || x.LifePayOrderStatus == LifePayOrderStatusEnum.閫�娆惧緟瀹℃牳 || x.LifePayOrderStatus == LifePayOrderStatusEnum.宸查��娆� || x.LifePayOrderStatus == LifePayOrderStatusEnum.閫�娆惧け璐� + .Where(x => x.LifePayOrderStatus == LifePayOrderStatusEnum.寰呴��娆� || x.LifePayOrderStatus == LifePayOrderStatusEnum.宸查��娆� || x.LifePayOrderStatus == LifePayOrderStatusEnum.閫�娆句腑 || x.LifePayRefundStatus > LifePayRefundStatusEnum.鏃犻渶閫�娆�) .WhereIf(input.BeginFinishTime.HasValue, x => x.FinishTime >= input.BeginFinishTime) .WhereIf(input.EndFinishTime.HasValue, x => x.FinishTime <= input.EndFinishTime) @@ -381,10 +341,8 @@ public async Task<LifePayOrderOutput> GetLifePayOrderDetail(string orderNo) { var order = await _lifePayOrderRepository.Where(x => x.OrderNo == orderNo).FirstOrDefaultAsync(); - 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.IsDeleted == false && x.PremiumType == order.LifePayType).FirstOrDefaultAsync(); - 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; @@ -415,16 +373,16 @@ LifePayRefundStatus = order.LifePayRefundStatus, ActualRechargeAmount = order.ActualRechargeAmount, RefundPrice = order.RefundPrice, - PlatformRate = platformRate.Rate, + PlatformRate = order.PlatformRate, PlatformPrice = order.PlatformDeductionAmount, ElecBillUrl = order.ElecBillUrl.GetOssPath(), RefundElecBillUrl = order.RefundElecBillUrl.GetOssPath(), ChannleRate = channle.ChannlesRate, ChannlesRakeRate = channle.ChannlesRakeRate, ChannlesRakePrice = channlesRakePrice.HasValue ? 0 : Math.Round(channlesRakePrice.Value, 2), - PremiumRate = premium == null ? 0 : premium.Rate, - PremiumPrice = premium == null ? 0 : Math.Round(order.PayAmount * premium.Rate, 2), - Profit = (order.PayAmount - order.PlatformDeductionAmount) * (1.00m - channle.ChannlesRakeRate / 100) - (premium == null ? 0 : Math.Round(order.PayAmount * premium.Rate, 2)) + PremiumRate = order.PremiumRate, + PremiumPrice = Math.Round(order.PayAmount * (order.PremiumRate.HasValue ? order.PremiumRate.Value:0), 2), + Profit = (order.PayAmount - order.PlatformDeductionAmount) * (1.00m - channle.ChannlesRakeRate / 100) - Math.Round(order.PayAmount * (order.PremiumRate.HasValue ? order.PremiumRate.Value : 0), 2) }; return result; @@ -812,10 +770,13 @@ var amount = CalculateAmount(input.ProductData.ParValue, rate.FirstOrDefault(x => x.RateType == LifePayRateTypeEnum.榛樿璇濊垂鎶樻墸).Rate); + var platformRate = await _lifePayRateRepository.FirstOrDefaultAsync(r => r.RateType == LifePayRateTypeEnum.渚涘簲鍟嗘姌鎵d环); + + var orderInput = new CreateLifePayOrderInput { OrderNo = channle.ChannlesNum + CreateOrderNo(), - LifePayOrderStatus = LifePayOrderStatusEnum.寰呯‘璁�, + LifePayOrderStatus = LifePayOrderStatusEnum.鍏呭�间腑, LifePayOrderType = LifePayOrderTypeEnum.璇濊垂璁㈠崟, //LifePayType = input.LifePayType, OrderParamDetailJsonStr = JsonConvert.SerializeObject(input.ProductData), @@ -825,7 +786,10 @@ PayAmount = amount.PayAmont, DiscountAmount = amount.DiscountAmount, RechargeAmount = amount.RechargeAmount, - ChannelId = channle.ChannlesNum + ChannelId = channle.ChannlesNum, + PlatformRate = platformRate.Rate, + ChannleRate = channle.ChannlesRate, + ChannlesRakeRate = channle.ChannlesRakeRate, }; await CreateLifePayOrder(orderInput); @@ -856,10 +820,12 @@ var amount = CalculateAmount(input.ProductData.ParValue, rate.FirstOrDefault(x => x.RateType == LifePayRateTypeEnum.榛樿鐢佃垂鎶樻墸).Rate); + var platformRate = await _lifePayRateRepository.FirstOrDefaultAsync(r => r.RateType == LifePayRateTypeEnum.渚涘簲鍟嗘姌鎵d环); + var orderInput = new CreateLifePayOrderInput { OrderNo = channle.ChannlesNum + CreateOrderNo(), - LifePayOrderStatus = LifePayOrderStatusEnum.寰呯‘璁�, + LifePayOrderStatus = LifePayOrderStatusEnum.鍏呭�间腑, LifePayOrderType = LifePayOrderTypeEnum.鐢佃垂璁㈠崟, // LifePayType = input.LifePayType, OrderParamDetailJsonStr = JsonConvert.SerializeObject(input.ProductData), @@ -869,7 +835,10 @@ PayAmount = amount.PayAmont, DiscountAmount = amount.DiscountAmount, RechargeAmount = amount.RechargeAmount, - ChannelId = channle.ChannlesNum + ChannelId = channle.ChannlesNum, + PlatformRate = platformRate.Rate, + ChannleRate = channle.ChannlesRate, + ChannlesRakeRate = channle.ChannlesRakeRate, }; await CreateLifePayOrder(orderInput); @@ -900,10 +869,12 @@ var amount = CalculateAmount(input.ProductData.ParValue, rate.FirstOrDefault(x => x.RateType == LifePayRateTypeEnum.榛樿鐕冩皵鎶樻墸).Rate); + var platformRate = await _lifePayRateRepository.FirstOrDefaultAsync(r => r.RateType == LifePayRateTypeEnum.渚涘簲鍟嗘姌鎵d环); + var orderInput = new CreateLifePayOrderInput { OrderNo = channle.ChannlesNum + CreateOrderNo(), - LifePayOrderStatus = LifePayOrderStatusEnum.寰呯‘璁�, + LifePayOrderStatus = LifePayOrderStatusEnum.鍏呭�间腑, LifePayOrderType = LifePayOrderTypeEnum.鐕冩皵璁㈠崟, // LifePayType = input.LifePayType, OrderParamDetailJsonStr = JsonConvert.SerializeObject(input.ProductData), @@ -938,7 +909,8 @@ 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 = "鐢熸椿缂磋垂-"; @@ -1215,7 +1187,7 @@ } order.LifePayRefundStatus = LifePayRefundStatusEnum.鏃犻渶閫�娆�; - order.LifePayOrderStatus = LifePayOrderStatusEnum.寰呯‘璁�; + order.LifePayOrderStatus = LifePayOrderStatusEnum.鍏呭�间腑; //SetOrderStatus(order, result.Code); order.OutRequestNo = result.RequestNo.IsNullOrEmpty() ? null : result.RequestNo; order.ACOOLYOrderNo = result.ACOOLYOrderNo.IsNullOrEmpty() ? null : result.ACOOLYOrderNo; @@ -1223,7 +1195,7 @@ catch (Exception ex) { _logger.LogError(ex, "澶勭悊鐢熸椿缂磋垂鏀粯鎴愬姛鍥炶皟鏃跺紓甯�"); - order.LifePayOrderStatus = LifePayOrderStatusEnum.宸插け璐�; + order.LifePayOrderStatus = LifePayOrderStatusEnum.寰呴��娆�; order.LifePayRefundStatus = LifePayRefundStatusEnum.寰呴��娆�; } _logger.LogError("鐢熸椿缂磋垂璁㈠崟鐘舵�侊細" + order.LifePayOrderStatus.ToString()); @@ -1241,10 +1213,10 @@ var order = await _lifePayOrderRepository.Where(x => x.OrderNo == orderNo).FirstOrDefaultAsync(); CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "璁㈠崟涓嶅瓨鍦�"); - if (order.LifePayOrderStatus == LifePayOrderStatusEnum.宸插畬鎴�) - { - return; - } + //if (order.LifePayOrderStatus == LifePayOrderStatusEnum.宸插畬鎴�) + //{ + // return; + //} order.PlatformDeductionAmount = payAmount; if (acoolyOrderNo.IsNotNullOrEmpty()) @@ -1252,15 +1224,6 @@ order.ACOOLYOrderNo = acoolyOrderNo; } - if (order.LifePayOrderStatus == LifePayOrderStatusEnum.宸插畬鎴�) - { - order.FinishTime = DateTime.Now; - } - - if (order.LifePayOrderStatus == LifePayOrderStatusEnum.宸插け璐� && order.PayStatus != LifePayStatusEnum.宸查��娆�) - { - order.PayStatus = LifePayStatusEnum.寰呴��娆�; - } order.LifePayOrderStatus = status; order.ACOOLYStatus = acoolyStatus; @@ -1279,12 +1242,22 @@ var order = await _lifePayOrderRepository.FirstOrDefaultAsync(x => x.Id == input.Id); CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "璁㈠崟涓嶅瓨鍦�"); - if (order.PayStatus == LifePayStatusEnum.宸查��娆�) + if (order.LifePayRefundStatus == LifePayRefundStatusEnum.宸查��娆�) { return; } - if (order.LifePayOrderStatus != LifePayOrderStatusEnum.宸插け璐� && order.PayStatus != LifePayStatusEnum.寰呴��娆� && order.LifePayOrderStatus != LifePayOrderStatusEnum.閫�娆惧緟瀹℃牳) + if (input.RefundPrice > order.PayAmount) + { + throw new UserFriendlyException("閫�娆剧殑閲戦涓嶈兘澶т簬瀹炰粯閲戦"); + } + + if (input.LifePayRefundType == LifePayRefundTypeEnum.鍏ㄩ閫�娆�) + { + input.RefundPrice = order.PayAmount; + } + + if (order.LifePayOrderStatus != LifePayOrderStatusEnum.寰呴��娆� || order.PayStatus != LifePayStatusEnum.宸叉敮浠� || order.LifePayRefundStatus != LifePayRefundStatusEnum.寰呴��娆�) { throw new UserFriendlyException("褰撳墠璁㈠崟鐘舵�佹棤娉曢��娆�"); } @@ -1294,35 +1267,30 @@ switch (order.LifePayType) { case LifePayTypeEnum.WxPay: - var wxRefundResult = await WxPayDomesticRefunds(order.OrderNo, outRefundNo,order.RefundApplyRemark, Convert.ToInt32(order.PayAmount * 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.PayStatus = LifePayStatusEnum.宸查��娆�; order.LifePayOrderStatus = LifePayOrderStatusEnum.宸查��娆�; order.LifePayRefundStatus = LifePayRefundStatusEnum.宸查��娆�; } else if (wxRefundResult.Status == "PROCESSING") { - order.PayStatus = LifePayStatusEnum.閫�娆句腑; order.LifePayOrderStatus = LifePayOrderStatusEnum.閫�娆句腑; order.LifePayRefundStatus = LifePayRefundStatusEnum.閫�娆句腑; } else { - order.PayStatus = LifePayStatusEnum.寰呴��娆�; - order.LifePayOrderStatus = LifePayOrderStatusEnum.閫�娆惧け璐�; + order.LifePayOrderStatus = LifePayOrderStatusEnum.寰呴��娆�; order.LifePayRefundStatus = LifePayRefundStatusEnum.寰呴��娆�; } break; case LifePayTypeEnum.AliPay: - var aliRefundResult = await AliTradeRefund(new AlipayTradeRefundRequest() { OutTradeNo = order.OrderNo, RefundAmount = order.PayAmount.ToString() }); + var aliRefundResult = await AliTradeRefund(new AlipayTradeRefundRequest() { OutTradeNo = order.OrderNo, RefundAmount = Convert.ToInt32(input.RefundPrice * 100).ToString() }); if (aliRefundResult.Code != AlipayResultCode.Success) { throw new UserFriendlyException("閫�娆惧け璐�"); } - - order.PayStatus = LifePayStatusEnum.宸查��娆�; order.LifePayOrderStatus = LifePayOrderStatusEnum.宸查��娆�; break; default: throw new UserFriendlyException("閫�娆惧け璐�"); @@ -1332,7 +1300,7 @@ order.RefundCheckRemark = input.RefundCheckRemark; order.RefundTime = DateTime.Now; order.RefundCheckUserId = CurrentUser.Id; - order.RefundPrice = order.PayAmount; + order.RefundPrice = input.RefundPrice; await _lifePayOrderRepository.UpdateAsync(order); @@ -1359,18 +1327,17 @@ throw new UserFriendlyException("闈炵敤鎴锋湰浜洪��娆�"); } - if (order.PayStatus == LifePayStatusEnum.宸查��娆�) + if (order.LifePayRefundStatus == LifePayRefundStatusEnum.宸查��娆�) { return; } - if (order.LifePayOrderStatus != LifePayOrderStatusEnum.寰呯‘璁� && order.LifePayOrderStatus != LifePayOrderStatusEnum.宸插け璐� - && order.PayStatus != LifePayStatusEnum.宸叉敮浠�) + if (order.PayStatus != LifePayStatusEnum.宸叉敮浠� || order.LifePayOrderStatus != LifePayOrderStatusEnum.宸插畬鎴�) { throw new UserFriendlyException("褰撳墠璁㈠崟鐘舵�佹棤娉曠敵璇烽��娆�"); } - order.LifePayOrderStatus = LifePayOrderStatusEnum.閫�娆惧緟瀹℃牳; + order.LifePayOrderStatus = LifePayOrderStatusEnum.寰呴��娆�; order.RefundApplyRemark = input.RefundApplyRemark; order.RefundApplyTime = DateTime.Now; @@ -1493,15 +1460,22 @@ var order = await _lifePayOrderRepository.FirstOrDefaultAsync(x => x.Id == input.Id); CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "璁㈠崟涓嶅瓨鍦�"); - if (order.PayStatus == LifePayStatusEnum.宸查��娆�) + if(order.LifePayRefundStatus == LifePayRefundStatusEnum.宸查��娆�) { return; } - if ((order.LifePayOrderStatus == LifePayOrderStatusEnum.宸插け璐� && order.PayStatus == LifePayStatusEnum.寰呴��娆�) || - order.LifePayOrderStatus == LifePayOrderStatusEnum.閫�娆惧緟瀹℃牳 || order.LifePayOrderStatus == LifePayOrderStatusEnum.寰呯‘璁�) + if (order.LifePayOrderStatus == LifePayOrderStatusEnum.寰呴��娆�) { - order.LifePayOrderStatus = LifePayOrderStatusEnum.閫�娆惧け璐�; + if (order.ACOOLYStatus == ACOOLYStatusEnum.宸插畬鎴� || order.ACOOLYStatus == ACOOLYStatusEnum.閮ㄥ垎鍏呭�兼垚鍔�) + { + order.LifePayOrderStatus = LifePayOrderStatusEnum.宸插畬鎴�; + } + else if (order.ACOOLYStatus == ACOOLYStatusEnum.鍏呭�煎け璐�) + { + order.LifePayOrderStatus = LifePayOrderStatusEnum.閫�娆惧け璐�; + } + order.RefundCheckRemark = input.RefundCheckRemark; order.RefundCheckUserId = CurrentUser.Id; @@ -1700,7 +1674,7 @@ order.FinishTime = DateTime.Now; break; case ACOOLYConstant.Code.PROCESSING: - order.LifePayOrderStatus = LifePayOrderStatusEnum.寰呯‘璁�; + order.LifePayOrderStatus = LifePayOrderStatusEnum.鍏呭�间腑; break; default: break; -- Gitblit v1.9.1