From 80566193cadd47fe77187465e4913d06a6dc978f Mon Sep 17 00:00:00 2001
From: zhengyuxuan <zhengyuxuan1995>
Date: 星期一, 24 三月 2025 20:33:23 +0800
Subject: [PATCH] fix:1分钱支付回退

---
 LifePayment/LifePayment.Application/LifePay/LifePayService.cs |   60 +++++++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 45 insertions(+), 15 deletions(-)

diff --git a/LifePayment/LifePayment.Application/LifePay/LifePayService.cs b/LifePayment/LifePayment.Application/LifePay/LifePayService.cs
index e4a7211..fcf0ccf 100644
--- a/LifePayment/LifePayment.Application/LifePay/LifePayService.cs
+++ b/LifePayment/LifePayment.Application/LifePay/LifePayService.cs
@@ -246,8 +246,8 @@
     {
         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)
-                      .WhereIf(input.BeginRefundTime.HasValue, x => x.FinishTime >= input.BeginRefundTime)
-                                            .WhereIf(input.EndRefundTime.HasValue, x => x.FinishTime <= input.EndRefundTime)
+                      .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)
                                             .WhereIf(input.LifePayType.HasValue, x => x.LifePayType == input.LifePayType)
                                             .WhereIf(input.EndPayTime.HasValue, x => x.PayTime <= input.EndPayTime)
@@ -303,8 +303,8 @@
         var result = await (from a in _channelFilter.GetChannelLifePayOrderFilter(_lifePayOrderRepository)
         .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)
+                                            .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)
                                             .WhereIf(input.LifePayType.HasValue, x => x.LifePayType == input.LifePayType)
                                             .WhereIf(input.EndRefundApplyTime.HasValue, x => x.RefundApplyTime <= input.EndRefundApplyTime)
@@ -397,8 +397,10 @@
         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 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 result = new LifePayOrderOutput()
                 {
             UserName = user.Name,
@@ -430,12 +432,12 @@
             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),
+            ChannleRate = order.ChannleRate,
+            ChannlesRakeRate = order.ChannlesRakeRate,
+            ChannlesRakePrice = orderpirce.ChannlesRakePrice,
             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)
+            PremiumPrice = orderpirce.PremiumPrice,
+            Profit = orderpirce.Profit
         };
 
         return result;
@@ -1305,6 +1307,7 @@
         {
             order.ACOOLYOrderNo = acoolyOrderNo;
         }
+
         if (refundApplyRemark.IsNotNullOrEmpty())
         {
             order.RefundApplyRemark = refundApplyRemark;
@@ -1312,7 +1315,7 @@
 
         order.LifePayOrderStatus = status;
         order.ACOOLYStatus = acoolyStatus;
-
+        order.FinishTime = DateTime.Now;
         await _lifePayOrderRepository.UpdateAsync(order);
     }
 
@@ -1756,10 +1759,10 @@
     private (decimal PayAmont, decimal DiscountAmount, decimal RechargeAmount) CalculateAmount(decimal amount, decimal rate)
     {
         /// 姝e父鏀粯
-        //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, "鏀粯閲戦閿欒");
 
@@ -2008,8 +2011,8 @@
         var result = (from a in _channelFilter.GetChannelLifePayOrderFilter(_lifePayOrderRepository)
      .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)
+                                         .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)
                                          .WhereIf(input.LifePayType.HasValue, x => x.LifePayType == input.LifePayType)
                                          .WhereIf(input.EndRefundApplyTime.HasValue, x => x.RefundApplyTime <= input.EndRefundApplyTime)
@@ -2069,5 +2072,32 @@
                     });
     }
 
+    public async Task<OrderPriceReturn> GetOrderPrice(decimal price, decimal priceAmount, decimal? platformRate,decimal? channleRate,
+        decimal? channlesRakeRate,decimal? premiumRate)
+    {
+        /// 姣涘埄
+        var grossProfit = price * (channleRate - platformRate) / 100;
+
+        /// 骞冲彴鎵f閲戦  鍏呭�奸潰棰� * 骞冲彴鎶樻墸姣斾緥
+        var platformPrice = price * platformRate / 100;
+
+        /// 鎵嬬画璐�
+        var premiumPrice = priceAmount * premiumRate / 100;
+
+        /// 娓犻亾浣i噾  锛�(鍏呭�奸潰棰� * 娓犻亾鎶樻墸姣斾緥)-(鍏呭�奸潰棰� * 骞冲彴鎶樻墸姣斾緥)锛�* 浣i噾姣斾緥
+        var channlesRakePrice = grossProfit * channlesRakeRate / 100;
+
+        /// 鍒╂鼎
+        var profit = grossProfit - channlesRakePrice - premiumPrice;
+
+        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
+        };
+    }
+
     #endregion
 }

--
Gitblit v1.9.1