From cf7069e5b979e025d30f13a2fe3ee3b3d824cea6 Mon Sep 17 00:00:00 2001
From: zhengyuxuan <zhengyuxuan1995>
Date: 星期二, 25 三月 2025 11:03:47 +0800
Subject: [PATCH] Merge branch 'master' of http://120.26.58.240:8888/r/LifePaymentApi

---
 LifePayment/LifePayment.Application/LifePay/LifePayService.cs |   87 ++++++++++++++++++++++++++++++++++---------
 1 files changed, 68 insertions(+), 19 deletions(-)

diff --git a/LifePayment/LifePayment.Application/LifePay/LifePayService.cs b/LifePayment/LifePayment.Application/LifePay/LifePayService.cs
index a4e76a1..49672e7 100644
--- a/LifePayment/LifePayment.Application/LifePay/LifePayService.cs
+++ b/LifePayment/LifePayment.Application/LifePay/LifePayService.cs
@@ -358,7 +358,7 @@
     {
         var result = await (await GetLifePayRefundOrderListFilter(input)).Select(x => new LifePayRefundOrderListTemplate
         {
-            FinishTime = x.FinishTime,
+            FinishTime = x.RefundTime,
             RefundPrice = x.RefundPrice,
             LifePayOrderType = x.LifePayOrderType,
             LifePayType = x.LifePayType,
@@ -368,6 +368,7 @@
             ChannelName = x.ChannelName,
             CreationTime = x.CreationTime,
             ACOOLYStatus = x.ACOOLYStatus,
+            RefundApplyRemark = x.RefundApplyRemark,
             RechargeAmount = x.RechargeAmount,
             ActualReceivedAmount = x.ActualReceivedAmount.ToString("F2"),
             LifePayRefundStatus = x.LifePayRefundStatus,
@@ -397,8 +398,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 +433,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;
@@ -527,6 +530,7 @@
                                                         CreationTime = x.CreationTime,
                                                         RefundCheckRemark = x.RefundCheckRemark,
                                                         RefundApplyRemark = x.RefundApplyRemark,
+                                                        RefundApplyTime = x.RefundApplyTime,
                                                         RefundTime = x.RefundTime,
                                                         ACOOLYOrderNo = x.ACOOLYOrderNo,
                                                         LifePayRefundStatus = x.LifePayRefundStatus,
@@ -745,17 +749,17 @@
         {
             s.SerialNumber = ++i;
             s.LifePayOrderTypeStr = s.LifePayOrderType.GetDescription();
-            s.CreationTimeStr = s.CreationTime.ToString(LifePaymentConstant.DateTimeFormatStr.yyyyMMddHHmm);
+            s.CreationTimeStr = s.CreationTime.ToString(LifePaymentConstant.DateTimeFormatStr.yyyyMMddHHmmss);
             s.RechargeAmountStr = s.RechargeAmount.ToString("F2");
             s.PayAmountStr = s.PayAmount.ToString("F2");
-            s.PayTimeStr = !s.PayTime.HasValue ? string.Empty : s.PayTime.Value.ToString(LifePaymentConstant.DateTimeFormatStr.yyyyMMddHHmm);
+            s.PayTimeStr = !s.PayTime.HasValue ? string.Empty : s.PayTime.Value.ToString(LifePaymentConstant.DateTimeFormatStr.yyyyMMddHHmmss);
             s.LifePayTypeStr = s.LifePayType.GetDescription();
             s.PayStatusStr = s.PayStatus.GetDescription();
             s.ActualRechargeAmountStr = s.ActualRechargeAmount.ToString("F2");
             s.LifePayRefundStatusStr = s.LifePayRefundStatusStr.GetDescription();
             s.ACOOLYStatusStr = s.ACOOLYStatus.GetDescription();
             //s.LifePayOrderStatusStr = s.LifePayOrderStatus.GetDescription();
-            s.FinishTimeStr = !s.FinishTime.HasValue ? string.Empty : s.FinishTime.Value.ToString(LifePaymentConstant.DateTimeFormatStr.yyyyMMddHHmm);
+            s.FinishTimeStr = !s.FinishTime.HasValue ? string.Empty : s.FinishTime.Value.ToString(LifePaymentConstant.DateTimeFormatStr.yyyyMMddHHmmss);
         });
         return result;
     }
@@ -829,6 +833,8 @@
 
         var rate = await GetRate();
         CheckExtensions.IfTrueThrowUserFriendlyException(rate.IsNullOrEmpty(), "鏈厤缃姌鎵�");
+
+        //var rate = await GetLifePayRate();
 
         var amount = CalculateAmount(input.ProductData.ParValue, rate.FirstOrDefault(x => x.RateType == LifePayRateTypeEnum.榛樿璇濊垂鎶樻墸).Rate);
 
@@ -1305,6 +1311,7 @@
         {
             order.ACOOLYOrderNo = acoolyOrderNo;
         }
+
         if (refundApplyRemark.IsNotNullOrEmpty())
         {
             order.RefundApplyRemark = refundApplyRemark;
@@ -1312,7 +1319,7 @@
 
         order.LifePayOrderStatus = status;
         order.ACOOLYStatus = acoolyStatus;
-
+        order.FinishTime = DateTime.Now;
         await _lifePayOrderRepository.UpdateAsync(order);
     }
 
@@ -1561,24 +1568,21 @@
         var order = await _lifePayOrderRepository.FirstOrDefaultAsync(x => x.Id == input.Id);
         CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "璁㈠崟涓嶅瓨鍦�");
 
-        if(order.LifePayRefundStatus == LifePayRefundStatusEnum.宸查��娆�)
+        if (order.LifePayRefundStatus == LifePayRefundStatusEnum.宸查��娆�)
         {
             return;
         }
 
-        if (order.LifePayOrderStatus == LifePayOrderStatusEnum.寰呴��娆�)
+        if (order.LifePayOrderStatus == LifePayOrderStatusEnum.寰呴��娆� || order.LifePayRefundStatus == LifePayRefundStatusEnum.寰呴��娆�)
         {
-            if (order.ACOOLYStatus == ACOOLYStatusEnum.宸插畬鎴� || order.ACOOLYStatus == ACOOLYStatusEnum.閮ㄥ垎鍏呭�兼垚鍔�)
+            if (order.ACOOLYStatus == ACOOLYStatusEnum.宸插畬鎴� || 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;
+            order.LifePayRefundStatus = LifePayRefundStatusEnum.閫�娆鹃┏鍥�;
 
             await _lifePayOrderRepository.UpdateAsync(order);
 
@@ -2007,7 +2011,7 @@
     {
         var result = (from a in _channelFilter.GetChannelLifePayOrderFilter(_lifePayOrderRepository)
      .Where(x => x.LifePayOrderStatus == LifePayOrderStatusEnum.寰呴��娆� || x.LifePayOrderStatus == LifePayOrderStatusEnum.宸查��娆� || x.LifePayOrderStatus == LifePayOrderStatusEnum.閫�娆句腑
-     || x.LifePayRefundStatus > LifePayRefundStatusEnum.鏃犻渶閫�娆�)
+     || (x.LifePayRefundStatus > LifePayRefundStatusEnum.鏃犻渶閫�娆� && x.LifePayRefundStatus != LifePayRefundStatusEnum.閫�娆鹃┏鍥�))
                                          .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)
@@ -2069,5 +2073,50 @@
                     });
     }
 
+    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
+        };
+    }
+
+    public async Task<decimal> GetLifePayRate(string channelId, LifePayRateTypeEnum lifePayRateType)
+    {
+        if (string.IsNullOrEmpty(channelId))
+        {
+            var rate = await GetRate();
+            CheckExtensions.IfTrueThrowUserFriendlyException(rate.IsNullOrEmpty(), "鏈厤缃姌鎵�");
+            var result = rate.FirstOrDefault(x => x.RateType == lifePayRateType).Rate;
+            return result;
+        }
+        else
+        {
+            var channel = await _lifePayChannlesRep.Where(x => x.ChannlesNum == channelId).FirstOrDefaultAsync();
+
+            CheckExtensions.IfTrueThrowUserFriendlyException(channel == null, "鏈壘鍒板搴旀笭閬�");
+            return channel.ChannlesRate;
+        }
+    }
+
     #endregion
 }

--
Gitblit v1.9.1