From e896cbc0f5d5483d4661918556f45b7b9a6c31c2 Mon Sep 17 00:00:00 2001
From: zhengyuxuan <zhengyuxuan1995>
Date: 星期一, 24 三月 2025 20:31:36 +0800
Subject: [PATCH] fix:手续费、利润等计算

---
 LifePayment/LifePayment.Host/LifePaymentServices.Application.Contracts.xml |   20 ++++++++++
 LifePayment/LifePayment.Application.Contracts/LifePay/LifePayInput.cs      |   25 ++++++++++++
 LifePayment/LifePayment.Application/LifePay/LifePayService.cs              |   40 +++++++++++++++++--
 3 files changed, 80 insertions(+), 5 deletions(-)

diff --git a/LifePayment/LifePayment.Application.Contracts/LifePay/LifePayInput.cs b/LifePayment/LifePayment.Application.Contracts/LifePay/LifePayInput.cs
index e6c7ebc..2202231 100644
--- a/LifePayment/LifePayment.Application.Contracts/LifePay/LifePayInput.cs
+++ b/LifePayment/LifePayment.Application.Contracts/LifePay/LifePayInput.cs
@@ -537,4 +537,29 @@
     public string Phone { get; set; }
 
     public string Remark { get; set; }
+}
+
+public class OrderPriceReturn
+{
+    /// <summary>
+    /// 骞冲彴鎵f閲戦
+    /// </summary>
+    public decimal PlatformPrice { get; set; }
+
+    /// <summary>
+    /// 鎵嬬画璐�
+    /// </summary>
+    public decimal PremiumPrice { get; set; }
+
+    /// <summary>
+    /// 娓犻亾浣i噾
+    /// </summary>
+    public decimal ChannlesRakePrice { get; set; }
+
+    /// <summary>
+    /// 鍒╂鼎
+    /// </summary>
+
+    public decimal Profit { get; set; }
+
 }
\ No newline at end of file
diff --git a/LifePayment/LifePayment.Application/LifePay/LifePayService.cs b/LifePayment/LifePayment.Application/LifePay/LifePayService.cs
index 67ce229..060bbdb 100644
--- a/LifePayment/LifePayment.Application/LifePay/LifePayService.cs
+++ b/LifePayment/LifePayment.Application/LifePay/LifePayService.cs
@@ -398,6 +398,9 @@
          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,
@@ -429,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;
@@ -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
 }
diff --git a/LifePayment/LifePayment.Host/LifePaymentServices.Application.Contracts.xml b/LifePayment/LifePayment.Host/LifePaymentServices.Application.Contracts.xml
index 6f0b37b..e45398d 100644
--- a/LifePayment/LifePayment.Host/LifePaymentServices.Application.Contracts.xml
+++ b/LifePayment/LifePayment.Host/LifePaymentServices.Application.Contracts.xml
@@ -636,6 +636,26 @@
             娉ㄥ唽鏃堕棿
             </summary>
         </member>
+        <member name="P:LifePayment.Application.Contracts.OrderPriceReturn.PlatformPrice">
+            <summary>
+            骞冲彴鎵f閲戦
+            </summary>
+        </member>
+        <member name="P:LifePayment.Application.Contracts.OrderPriceReturn.PremiumPrice">
+            <summary>
+            鎵嬬画璐�
+            </summary>
+        </member>
+        <member name="P:LifePayment.Application.Contracts.OrderPriceReturn.ChannlesRakePrice">
+            <summary>
+            娓犻亾浣i噾
+            </summary>
+        </member>
+        <member name="P:LifePayment.Application.Contracts.OrderPriceReturn.Profit">
+            <summary>
+            鍒╂鼎
+            </summary>
+        </member>
         <member name="P:LifePayment.Application.Contracts.LifePayIntroInfoInput.LifePayType">
             <summary>
             鐢熸椿缂磋垂绫诲瀷

--
Gitblit v1.9.1