From fbd573b5d2d05cac61d2184064bb5dd18d0fe61f Mon Sep 17 00:00:00 2001
From: zhengyuxuan <zhengyuxuan1995>
Date: 星期四, 20 三月 2025 16:48:48 +0800
Subject: [PATCH] fix:退款订单号bug修复

---
 LifePayment/LifePayment.Application/LifePay/LifePayService.cs |  112 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 106 insertions(+), 6 deletions(-)

diff --git a/LifePayment/LifePayment.Application/LifePay/LifePayService.cs b/LifePayment/LifePayment.Application/LifePay/LifePayService.cs
index 0fed01f..4491695 100644
--- a/LifePayment/LifePayment.Application/LifePay/LifePayService.cs
+++ b/LifePayment/LifePayment.Application/LifePay/LifePayService.cs
@@ -21,6 +21,8 @@
 using ZeroD.Util;
 using Alipay.EasySDK.Payment.Common.Models;
 using static LifePayment.Domain.Shared.LifePaymentConstant;
+using ZeroD.Util.Fadd;
+using Nest;
 
 namespace LifePayment.Application;
 
@@ -167,7 +169,8 @@
     {
         return await _channelFilter.GetChannelLifePayUserFilter(_lifePayUserRepository).Where(x => x.IsDeleted == false)
             .WhereIf(!string.IsNullOrEmpty(input.QueryCondition), x => x.PhoneNumber.Contains(input.QueryCondition) || x.Name.Contains(input.QueryCondition))
-            .WhereIf(input.CreationTime.HasValue, x => x.CreationTime.ToString("yyyy-MM-dd") == input.CreationTime.Value.ToString("yyyy-MM-dd"))
+            .WhereIf(input.CreationTimeBegin.HasValue, x => x.CreationTime >= input.CreationTimeBegin)
+            .WhereIf(input.CreationTimeEnd.HasValue, x => x.CreationTime <= input.CreationTimeEnd)
                                             .Select(x =>
                                                    new UserListOutput()
                                                    {
@@ -264,6 +267,97 @@
         return result;
     }
 
+    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, "璁㈠崟涓嶅瓨鍦�");
+        var user = await _lifePayUserRepository.FirstOrDefaultAsync(x => x.Id == order.UserId);
+        
+        var channlesRakePrice = (order.PayAmount - (order.PlatformDeductionAmount == null ? 0 : order.PlatformDeductionAmount)) * channle.ChannlesRakeRate / 100;
+        var result = new LifePayOrderOutput()
+                {
+            UserName = user.Name,
+            UserPhoneNumber = user.PhoneNumber,
+            DiscountAmount = order.DiscountAmount,
+            FinishTime = order.FinishTime,
+            Id = order.Id,
+            OutOrderNo = order.OutOrderNo,
+            LifePayChannle = channle.ChannlesName,
+            LifePayOrderStatus = order.LifePayOrderStatus,
+            LifePayOrderType = order.LifePayOrderType,
+            LifePayType = order.LifePayType,
+            OrderNo = order.OrderNo,
+            PayAmount = order.PayAmount,
+            RechargeAmount = order.RechargeAmount,
+            PayStatus = order.PayStatus,
+            PayTime = order.PayTime,
+            OrderParamDetailJsonStr = order.OrderParamDetailJsonStr,
+            RefundCredentialsImgUrl = order.RefundCredentialsImgUrl.GetOssPath(),
+            CreationTime = order.CreationTime,
+            RefundCheckRemark = order.RefundCheckRemark,
+            RefundApplyRemark = order.RefundApplyRemark,
+            RefundTime = order.RefundTime,
+            ACOOLYOrderNo = order.ACOOLYOrderNo,
+            LifePayRefundStatus = order.LifePayRefundStatus,
+            ActualRechargeAmount = order.ActualRechargeAmount,
+            RefundPrice = order.RefundPrice,
+            PlatformRate = platformRate.Rate,
+            PlatformPrice = order.PlatformDeductionAmount,
+            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))
+        };
+
+        return result;
+    }
+
+    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 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, "璁㈠崟涓嶅瓨鍦�");
+        var user = await _lifePayUserRepository.FirstOrDefaultAsync(x => x.Id == order.UserId);
+
+        var channlesRakePrice = (order.PayAmount - (order.PlatformDeductionAmount == null ? 0 : order.PlatformDeductionAmount)) * channle.ChannlesRakeRate / 100;
+        var result = new LifePayRefundOrderOutput()
+        {
+            UserName = user.Name,
+            UserPhoneNumber = user.PhoneNumber,
+            DiscountAmount = order.DiscountAmount,
+            FinishTime = order.FinishTime,
+            Id = order.Id,
+            OutOrderNo = order.OutOrderNo,
+            LifePayChannle = channle.ChannlesName,
+            LifePayOrderStatus = order.LifePayOrderStatus,
+            LifePayOrderType = order.LifePayOrderType,
+            LifePayType = order.LifePayType,
+            OrderNo = order.OrderNo,
+            PayAmount = order.PayAmount,
+            RechargeAmount = order.RechargeAmount,
+            PayStatus = order.PayStatus,
+            PayTime = order.PayTime,
+            RefundCredentialsImgUrl = order.RefundCredentialsImgUrl.GetOssPath(),
+            CreationTime = order.CreationTime,
+            RefundCheckRemark = order.RefundCheckRemark,
+            RefundApplyRemark = order.RefundApplyRemark,
+            RefundTime = order.RefundTime,
+            ACOOLYOrderNo = order.ACOOLYOrderNo,
+            LifePayRefundStatus = order.LifePayRefundStatus,
+            ActualRechargeAmount = order.ActualRechargeAmount,
+            RefundPrice = order.RefundPrice,
+        };
+
+        return result;
+    }
+
     /// <summary>
     /// 鑾峰彇鎴戠殑璁㈠崟鍒嗛〉鏁版嵁
     /// </summary>
@@ -340,6 +434,8 @@
 
         return result;
     }
+
+
 
     /// <summary>
     /// 鏍规嵁璁㈠崟鍙疯幏鍙栨敮浠樼姸鎬�
@@ -997,6 +1093,7 @@
             order.PayStatus = LifePayStatusEnum.寰呴��娆�;
         }
 
+
         await _lifePayOrderRepository.UpdateAsync(order);
     }
 
@@ -1021,10 +1118,12 @@
             throw new UserFriendlyException("褰撳墠璁㈠崟鐘舵�佹棤娉曢��娆�");
         }
 
+        var outRefundNo = order.ChannelId + CreateRefundOrderNo();
+        order.RefundOrderNo = outRefundNo;
         switch (order.LifePayType)
         {
             case LifePayTypeEnum.WxPay:
-                var wxRefundResult = await WxPayDomesticRefunds(order.OrderNo, order.RefundApplyRemark, Convert.ToInt32(order.PayAmount * 100), Convert.ToInt32(order.PayAmount * 100));
+                var wxRefundResult = await WxPayDomesticRefunds(order.OrderNo, outRefundNo,order.RefundApplyRemark, Convert.ToInt32(order.PayAmount * 100), Convert.ToInt32(order.PayAmount * 100));
                 if (wxRefundResult.Status == "SUCCESS")
                 {
                     order.PayStatus = LifePayStatusEnum.宸查��娆�;
@@ -1058,6 +1157,7 @@
         order.RefundCheckRemark = input.RefundCheckRemark;
         order.RefundTime = DateTime.Now;
         order.RefundCheckUserId = CurrentUser.Id;
+        order.RefundPrice = order.PayAmount;
 
         await _lifePayOrderRepository.UpdateAsync(order);
 
@@ -1111,12 +1211,12 @@
     /// <param name="total"></param>
     /// <param name="currency"></param>
     /// <returns></returns>
-    public async Task<WxPayDomesticRefundsReponse> WxPayDomesticRefunds(string outTradeNo, string reason, int refund, int total, string currency = "CNY")
+    public async Task<WxPayDomesticRefundsReponse> WxPayDomesticRefunds(string outTradeNo,string outRefundNo, string reason, int refund, int total, string currency = "CNY")
     {
         WxPayDomesticRefundsRequest req = new WxPayDomesticRefundsRequest
         {
             OutTradeNo = outTradeNo,
-            OutRefundNo = CreateRefundOrderNo(),
+            OutRefundNo = outRefundNo,
             Reason = reason,
             Amount = new Model_WxPayDomesticRefunds_Amount
             {
@@ -1406,10 +1506,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, "鏀粯閲戦閿欒");
 

--
Gitblit v1.9.1