From d5fe1b8b4de07a9ceeee5bba65677f5c0b5e9d5d Mon Sep 17 00:00:00 2001
From: zhengyiming <540361168@qq.com>
Date: 星期一, 31 三月 2025 10:14:56 +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.Application.Contracts/LifePay/LifePayOutput.cs |   10 +++
 LifePayment/LifePayment.Application/LifePay/LifePayOrderService.cs     |    4 
 LifePayment/LifePayment.Domain/Ali/AliPayApi.cs                        |  135 ++++++++++++++++++++++++++++++++++++++++++++
 LifePayment/LifePayment.Application/LifePay/LifePayService.cs          |    8 ++
 LifePayment/LifePayment.Application/LifePay/StatisticsService.cs       |   10 +++
 5 files changed, 163 insertions(+), 4 deletions(-)

diff --git a/LifePayment/LifePayment.Application.Contracts/LifePay/LifePayOutput.cs b/LifePayment/LifePayment.Application.Contracts/LifePay/LifePayOutput.cs
index a0614f0..333a00a 100644
--- a/LifePayment/LifePayment.Application.Contracts/LifePay/LifePayOutput.cs
+++ b/LifePayment/LifePayment.Application.Contracts/LifePay/LifePayOutput.cs
@@ -1235,4 +1235,14 @@
     /// 瀹為檯鏀跺叆
     /// </summary>
     public decimal RealIncome { get; set; }
+}
+
+public class ReceiptsListOutPut
+{
+    /// <summary>
+    /// 鍒涘缓鏃堕棿
+    /// </summary>
+    public DateTime CreationTime { get; set; }
+
+    public decimal Amount { get; set; }
 }
\ No newline at end of file
diff --git a/LifePayment/LifePayment.Application/LifePay/LifePayOrderService.cs b/LifePayment/LifePayment.Application/LifePay/LifePayOrderService.cs
index 16fe3b9..0ad8d61 100644
--- a/LifePayment/LifePayment.Application/LifePay/LifePayOrderService.cs
+++ b/LifePayment/LifePayment.Application/LifePay/LifePayOrderService.cs
@@ -168,7 +168,7 @@
                         if (input.ExpensesReceiptsType == ExpensesReceiptsTypeEnum.Expenses)
                         {
                             var query = await _aliPayApi.OrderInQuiry(new OrderInQuiryInput() { OutTradeNo = input.OrderNo });
-                            if (query.Code == AlipayResultCode.Success && (query.TradeStatus == AlipayStatus.TRADESUCCESS 
+                            if (query.Code == AlipayResultCode.Success && (query.TradeStatus == AlipayStatus.TRADESUCCESS
                                 || query.TradeStatus == AlipayStatus.TRADECLOSED))
                             {
                                 data.ExtraProperties = JsonConvert.SerializeObject(query);
@@ -182,7 +182,7 @@
                             if (query.Code == AlipayResultCode.Success && query.RefundStatus == AlipayRefundStatus.Success)
                             {
                                 data.ExtraProperties = JsonConvert.SerializeObject(query);
-                                //data.FinishTime = Convert.ToDateTime(query.SendPayDate);
+                                data.FinishTime = Convert.ToDateTime(query.GmtRefundPay);
                                 await _lifePayExpensesReceiptsRepository.InsertAsync(data);
                             }
                         }
diff --git a/LifePayment/LifePayment.Application/LifePay/LifePayService.cs b/LifePayment/LifePayment.Application/LifePay/LifePayService.cs
index 4d09890..11bdb9b 100644
--- a/LifePayment/LifePayment.Application/LifePay/LifePayService.cs
+++ b/LifePayment/LifePayment.Application/LifePay/LifePayService.cs
@@ -28,6 +28,7 @@
 using NPOI.SS.Formula.Functions;
 using StackExchange.Redis;
 using static Volo.Abp.Identity.Settings.IdentitySettingNames;
+using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
 
 namespace LifePayment.Application;
 
@@ -841,6 +842,13 @@
     public async Task<AlipayTradeFastpayRefundQueryResponse> QueryAlipayTradeRefund(OrderInQuiryInput input)
     {
         var result = await _aliPayApi.QueryAlipayTradeRefund(input);
+        var order = await _lifePayOrderRepository.Where(x => x.OrderNo == input.OutTradeNo).FirstOrDefaultAsync();
+        if (result.Code == AlipayResultCode.Success && result.RefundStatus == AlipayRefundStatus.Success)
+        {
+            order.LifePayOrderStatus = LifePayOrderStatusEnum.宸查��娆�;
+            order.LifePayRefundStatus = LifePayRefundStatusEnum.宸查��娆�;
+        }
+
         return result;
     }
 
diff --git a/LifePayment/LifePayment.Application/LifePay/StatisticsService.cs b/LifePayment/LifePayment.Application/LifePay/StatisticsService.cs
index 8d127f9..d319106 100644
--- a/LifePayment/LifePayment.Application/LifePay/StatisticsService.cs
+++ b/LifePayment/LifePayment.Application/LifePay/StatisticsService.cs
@@ -35,6 +35,11 @@
             _dallyStatisticsRepository = dallyStatisticsRepository;
         }
 
+        /// <summary>
+        /// 椤堕儴缁熻
+        /// </summary>
+        /// <param name="channleId"></param>
+        /// <returns></returns>
         public async Task<TopStatisticsOutput> GetTopStatistics(string channleId = "")
         {
             var today = DateTime.Now.Date;
@@ -119,5 +124,10 @@
                 return topStatisticsOutput;
             }
         }
+
+        //public async Task<ReceiptsListOutPut> GetReceiptsList()
+        //{
+
+        //}
     }
 }
diff --git a/LifePayment/LifePayment.Domain/Ali/AliPayApi.cs b/LifePayment/LifePayment.Domain/Ali/AliPayApi.cs
index 15e591c..b3f7f32 100644
--- a/LifePayment/LifePayment.Domain/Ali/AliPayApi.cs
+++ b/LifePayment/LifePayment.Domain/Ali/AliPayApi.cs
@@ -56,13 +56,13 @@
         /// <returns></returns>
         public async Task<AlipayTradeFastpayRefundQueryResponse> QueryAlipayTradeRefund(OrderInQuiryInput input)
         {
-            AlipayTradeFastpayRefundQueryResponse response = await Factory.Payment.Common().QueryRefundAsync(input.OutTradeNo, input.OutTradeNo);
+            AlipayTradeFastpayRefundQueryResponse response = await QueryTradeRefund(input.OutTradeNo, input.OutTradeNo);
             return response;
         }
 
         public async Task<AlipayTradeRefundResponse> TradeRefund(AlipayTradeRefundRequest input)
         {
-            AlipayTradeRefundResponse response = await TradeRefund(input.OutTradeNo,input.OutRefundNo, input.RefundAmount);
+            AlipayTradeRefundResponse response = await TradeRefund(input.OutTradeNo, input.OutRefundNo, input.RefundAmount);
             return response;
         }
 
@@ -196,5 +196,136 @@
             throw new TeaUnretryableException(_lastRequest, innerException);
         }
 
+        private async Task<AlipayTradeFastpayRefundQueryResponse> QueryTradeRefund(string outTradeNo, string outRequestNo)
+        {
+            Dictionary<string, object> runtime_ = new Dictionary<string, object>
+        {
+            {
+                "ignoreSSL",
+                _kernel.GetConfig("ignoreSSL")
+            },
+            {
+                "httpProxy",
+                _kernel.GetConfig("httpProxy")
+            },
+            { "connectTimeout", 15000 },
+            { "readTimeout", 15000 },
+            {
+                "retry",
+                new Dictionary<string, int?> { { "maxAttempts", 0 } }
+            }
+        };
+            TeaRequest _lastRequest = null;
+            Exception innerException = null;
+            long _now = DateTime.Now.Millisecond;
+            int _retryTimes = 0;
+            while (TeaCore.AllowRetry((IDictionary)runtime_["retry"], _retryTimes, _now))
+            {
+                if (_retryTimes > 0)
+                {
+                    int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes);
+                    if (backoffTime > 0)
+                    {
+                        TeaCore.Sleep(backoffTime);
+                    }
+                }
+
+                _retryTimes++;
+                try
+                {
+                    TeaRequest teaRequest = new TeaRequest();
+                    Dictionary<string, string> dictionary = new Dictionary<string, string>
+                {
+                    { "method", "alipay.trade.fastpay.refund.query" },
+                    {
+                        "app_id",
+                        _kernel.GetConfig("appId")
+                    },
+                    {
+                        "timestamp",
+                        _kernel.GetTimestamp()
+                    },
+                    { "format", "json" },
+                    { "version", "1.0" },
+                    {
+                        "alipay_sdk",
+                        _kernel.GetSdkVersion()
+                    },
+                    { "charset", "UTF-8" },
+                    {
+                        "sign_type",
+                        _kernel.GetConfig("signType")
+                    },
+                    {
+                        "app_cert_sn",
+                        _kernel.GetMerchantCertSN()
+                    },
+                    {
+                        "alipay_root_cert_sn",
+                        _kernel.GetAlipayRootCertSN()
+                    }
+                };
+                    var queryOptions = new string[] { "gmt_refund_pay" };
+                    Dictionary<string, object> bizParams = new Dictionary<string, object>
+                {
+                    { "out_trade_no", outTradeNo },
+                    { "out_request_no", outRequestNo },
+                    { "query_options", queryOptions }
+                };
+                    Dictionary<string, string> dictionary2 = new Dictionary<string, string>();
+                    teaRequest.Protocol = _kernel.GetConfig("protocol");
+                    teaRequest.Method = "POST";
+                    teaRequest.Pathname = "/gateway.do";
+                    teaRequest.Headers = new Dictionary<string, string>
+                {
+                    {
+                        "host",
+                        _kernel.GetConfig("gatewayHost")
+                    },
+                    { "content-type", "application/x-www-form-urlencoded;charset=utf-8" }
+                };
+                    teaRequest.Query = _kernel.SortMap(TeaConverter.merge<string>(new object[3]
+                    {
+                    new Dictionary<string, string> {
+                    {
+                        "sign",
+                        _kernel.Sign(dictionary, bizParams, dictionary2, _kernel.GetConfig("merchantPrivateKey"))
+                    } },
+                    dictionary,
+                    dictionary2
+                    }));
+                    teaRequest.Body = TeaCore.BytesReadable(_kernel.ToUrlEncodedRequestBody(bizParams));
+                    _lastRequest = teaRequest;
+                    TeaResponse response = await TeaCore.DoActionAsync(teaRequest, runtime_);
+                    Dictionary<string, object> respMap = await _kernel.ReadAsJsonAsync(response, "alipay.trade.fastpay.refund.query");
+                    if (_kernel.IsCertMode())
+                    {
+                        if (_kernel.Verify(respMap, _kernel.ExtractAlipayPublicKey(_kernel.GetAlipayCertSN(respMap))))
+                        {
+                            return TeaModel.ToObject<AlipayTradeFastpayRefundQueryResponse>(_kernel.ToRespModel(respMap));
+                        }
+                    }
+                    else if (_kernel.Verify(respMap, _kernel.GetConfig("alipayPublicKey")))
+                    {
+                        return TeaModel.ToObject<AlipayTradeFastpayRefundQueryResponse>(_kernel.ToRespModel(respMap));
+                    }
+
+                    throw new TeaException(new Dictionary<string, string> { { "message", "楠岀澶辫触锛岃妫�鏌ユ敮浠樺疂鍏挜璁剧疆鏄惁姝g‘銆�" } });
+                }
+                catch (Exception ex)
+                {
+                    if (TeaCore.IsRetryable(ex))
+                    {
+                        innerException = ex;
+                        continue;
+                    }
+
+                    throw ex;
+                }
+            }
+
+            throw new TeaUnretryableException(_lastRequest, innerException);
+        }
+
     }
 }
\ No newline at end of file

--
Gitblit v1.9.1