From 7f36c8b49b888cbf440ea400336a11abf4cab018 Mon Sep 17 00:00:00 2001
From: zhengyiming <540361168@qq.com>
Date: 星期二, 01 四月 2025 11:19:40 +0800
Subject: [PATCH] Merge branch 'dev-lifepay-v1.3' of http://120.26.58.240:8888/r/LifePaymentApi into dev-lifepay-v1.3

---
 LifePayment/LifePayment.HttpApi/LifePay/WxPayNotifyController.cs   |    5 --
 LifePayment/LifePayment.HttpApi/LifePay/LifePayController.cs       |   21 ++++++----
 LifePayment/LifePayment.Domain/WeChat/WxpayApiConstant.cs          |   27 +++++++++++++
 LifePayment/LifePayment.Application/LifePay/LifePayService.cs      |   44 +++++++++++++++++-----
 LifePayment/LifePayment.Domain.Shared/LifePaymentConstant.cs       |    2 
 LifePayment/LifePayment.Domain.Shared/WeChat/WxPayPostBaseModel.cs |    3 +
 6 files changed, 79 insertions(+), 23 deletions(-)

diff --git a/LifePayment/LifePayment.Application/LifePay/LifePayService.cs b/LifePayment/LifePayment.Application/LifePay/LifePayService.cs
index 8d5907a..a3135a3 100644
--- a/LifePayment/LifePayment.Application/LifePay/LifePayService.cs
+++ b/LifePayment/LifePayment.Application/LifePay/LifePayService.cs
@@ -30,6 +30,7 @@
 using static Volo.Abp.Identity.Settings.IdentitySettingNames;
 using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
 using LifePayment.Application.LifePay;
+using Alipay.AopSdk.Core.Domain;
 
 namespace LifePayment.Application;
 
@@ -876,7 +877,24 @@
     /// <returns></returns>
     public async Task<WxPayDomesticRefundsQueryReponse> WxPayDomesticRefundsQuery(string outTradeNo)
     {
-        return await _wxPayApi.WxPayDomesticRefundsQuery(outTradeNo);
+        var order = await _lifePayOrderRepository.Where(x => x.RefundOrderNo == outTradeNo).FirstOrDefaultAsync();
+        CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "鏈壘鍒拌鍗曚俊鎭�");
+        var result = await _wxPayApi.WxPayDomesticRefundsQuery(outTradeNo);
+        if (order.LifePayRefundStatus != LifePayRefundStatusEnum.宸查��娆� && result.Code == WxpayResultCode.Success && result.Status == WxPayRefundStatus.閫�娆炬垚鍔�)
+        {
+            order.LifePayOrderStatus = LifePayOrderStatusEnum.宸查��娆�;
+            order.LifePayRefundStatus = LifePayRefundStatusEnum.宸查��娆�;
+            await _lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput()
+            {
+                OrderNo = order.OrderNo,
+                OutRefundNo = order.RefundOrderNo,
+                OutOrderNo = order.OutOrderNo,
+                LifePayType = LifePayTypeEnum.AliPay,
+                ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Receipts
+            });
+        }
+        return result;
+
     }
 
     /// <summary>
@@ -1449,20 +1467,26 @@
         {
             case LifePayTypeEnum.WxPay:
                 var wxRefundResult = await WxPayDomesticRefunds(order.OrderNo, outRefundNo, order.RefundApplyRemark, Convert.ToInt32(input.RefundPrice * 100), Convert.ToInt32(order.PayAmount * 100));
-                if (wxRefundResult.Status == "SUCCESS")
+                if (wxRefundResult.Status == WxpayRefundResultStatus.SUCCESS)
+                {
+                    order.RefundOrderNo = outRefundNo;
+                    order.LifePayOrderStatus = LifePayOrderStatusEnum.閫�娆句腑;
+                    order.LifePayRefundStatus = LifePayRefundStatusEnum.閫�娆句腑;
+                }
+                else if (wxRefundResult.Status == WxpayRefundResultStatus.PROCESSING)
+                {
+                    order.RefundOrderNo = outRefundNo;
+                    order.LifePayOrderStatus = LifePayOrderStatusEnum.閫�娆句腑;
+                    order.LifePayRefundStatus = LifePayRefundStatusEnum.閫�娆句腑;
+                }
+                else if (wxRefundResult.Status.IsNullOrEmpty() && wxRefundResult.Message == WxpayRefundResultMessage.FullRefund)
                 {
                     order.LifePayOrderStatus = LifePayOrderStatusEnum.宸查��娆�;
                     order.LifePayRefundStatus = LifePayRefundStatusEnum.宸查��娆�;
                 }
-                else if (wxRefundResult.Status == "PROCESSING")
-                {
-                    order.LifePayOrderStatus = LifePayOrderStatusEnum.閫�娆句腑;
-                    order.LifePayRefundStatus = LifePayRefundStatusEnum.閫�娆句腑;
-                }
                 else
                 {
-                    order.LifePayOrderStatus = LifePayOrderStatusEnum.寰呴��娆�;
-                    order.LifePayRefundStatus = LifePayRefundStatusEnum.寰呴��娆�;
+                    throw new UserFriendlyException("閫�娆惧け璐�:" + wxRefundResult.Message);
                 }
 
                 break;
@@ -1473,13 +1497,13 @@
                     throw new UserFriendlyException("閫�娆惧け璐�:" + aliRefundResult.SubMsg);
                 }
 
+                order.RefundOrderNo = outRefundNo;
                 order.LifePayOrderStatus = LifePayOrderStatusEnum.閫�娆句腑;
                 order.LifePayRefundStatus = LifePayRefundStatusEnum.閫�娆句腑;
                 break;
             default: throw new UserFriendlyException("閫�娆惧け璐�");
         }
 
-        order.RefundOrderNo = outRefundNo;
         order.RefundCredentialsImgUrl = input.RefundCredentialsImgUrl;
         order.RefundCheckRemark = input.RefundCheckRemark;
         order.RefundTime = DateTime.Now;
diff --git a/LifePayment/LifePayment.Domain.Shared/LifePaymentConstant.cs b/LifePayment/LifePayment.Domain.Shared/LifePaymentConstant.cs
index aa7070d..1100406 100644
--- a/LifePayment/LifePayment.Domain.Shared/LifePaymentConstant.cs
+++ b/LifePayment/LifePayment.Domain.Shared/LifePaymentConstant.cs
@@ -1396,6 +1396,6 @@
 
         }
 
-
+       
     }
 }
\ No newline at end of file
diff --git a/LifePayment/LifePayment.Domain.Shared/WeChat/WxPayPostBaseModel.cs b/LifePayment/LifePayment.Domain.Shared/WeChat/WxPayPostBaseModel.cs
index 82d0a98..435b9d2 100644
--- a/LifePayment/LifePayment.Domain.Shared/WeChat/WxPayPostBaseModel.cs
+++ b/LifePayment/LifePayment.Domain.Shared/WeChat/WxPayPostBaseModel.cs
@@ -728,6 +728,9 @@
         [JsonProperty("message")]
         public string Message { get; set; }
 
+        [JsonProperty("code")]
+        public string Code { get; set; }
+
     }
 
     public class Model_WxPayRetuenDomesticRefunds_Amount: Model_WxPayDomesticRefunds_Amount
diff --git a/LifePayment/LifePayment.Domain/WeChat/WxpayApiConstant.cs b/LifePayment/LifePayment.Domain/WeChat/WxpayApiConstant.cs
new file mode 100644
index 0000000..c1de762
--- /dev/null
+++ b/LifePayment/LifePayment.Domain/WeChat/WxpayApiConstant.cs
@@ -0,0 +1,27 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace LifePayment.Domain
+{
+    public class WxpayApiConstant
+    {
+
+    }
+    public class WxpayRefundResultMessage
+    {
+        public const string FullRefund = "璁㈠崟宸插叏棰濋��娆�";
+    }
+    public class WxpayRefundResultStatus
+    {
+        public const string SUCCESS = "SUCCESS";
+        public const string PROCESSING = "PROCESSING";
+    }
+    public class WxpayResultCode
+    {
+        public const string Success = "10000";
+        public const string Fail = "40004";
+    }
+}
diff --git a/LifePayment/LifePayment.HttpApi/LifePay/LifePayController.cs b/LifePayment/LifePayment.HttpApi/LifePay/LifePayController.cs
index dca8f91..5dd5a70 100644
--- a/LifePayment/LifePayment.HttpApi/LifePay/LifePayController.cs
+++ b/LifePayment/LifePayment.HttpApi/LifePay/LifePayController.cs
@@ -1,6 +1,7 @@
 锘縰sing Alipay.AopSdk.F2FPay.Model;
 using LifePayment.Application.Contracts;
 using LifePayment.Application.LifePay;
+using LifePayment.Domain;
 using LifePayment.Domain.Common;
 using LifePayment.Domain.Shared;
 using Microsoft.AspNetCore.Authorization;
@@ -524,16 +525,20 @@
         public async Task<WxPayDomesticRefundsQueryReponse> WxPayDomesticRefundsQuery(string outTradeNo)
         {
             var res = await _lifePayService.WxPayDomesticRefundsQuery(outTradeNo);
-            await _lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput()
+            if (res.Code == WxpayResultCode.Success)
             {
-                OrderNo = res.OutTradeNo,
-                OutRefundNo = res.RefundId,
-                OutOrderNo = res.TransactionId,
-                LifePayType = LifePayTypeEnum.WxPay,
-                ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Expenses,
-                Amount = Convert.ToDecimal(res.Amount.Total)
-            });
+                await _lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput()
+                {
+                    OrderNo = res.OutTradeNo,
+                    OutRefundNo = res.RefundId,
+                    OutOrderNo = res.TransactionId,
+                    LifePayType = LifePayTypeEnum.WxPay,
+                    ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Expenses,
+                    Amount = Convert.ToDecimal(res.Amount.Total)
+                });
+            }
             return res;
+
         }
 
         /// <summary>
diff --git a/LifePayment/LifePayment.HttpApi/LifePay/WxPayNotifyController.cs b/LifePayment/LifePayment.HttpApi/LifePay/WxPayNotifyController.cs
index afb1d87..5dc1ddd 100644
--- a/LifePayment/LifePayment.HttpApi/LifePay/WxPayNotifyController.cs
+++ b/LifePayment/LifePayment.HttpApi/LifePay/WxPayNotifyController.cs
@@ -102,10 +102,7 @@
 
                 if (wxPayNotice.OutTradeNo.Contains("JF"))
                 {
-                    if (wxPayNotice.RefundStatus == LifePaymentConstant.WxPayRefundStatus.閫�娆炬垚鍔�)
-                    {
-                        
-                    }
+                   
                     switch (wxPayNotice.RefundStatus)
                     {
                         case LifePaymentConstant.WxPayRefundStatus.閫�娆炬垚鍔�:

--
Gitblit v1.9.1