From 3274bc9ca97ce02bd7eb86107898a40531057477 Mon Sep 17 00:00:00 2001
From: sunpengfei <i@angelzzz.com>
Date: 星期一, 09 六月 2025 16:37:48 +0800
Subject: [PATCH] pref:多次接收到支付回调的bug

---
 LifePayment/LifePayment.HttpApi/LifePay/WxPayNotifyController.cs |   36 +++++++++++++++++++++++++-----------
 LifePayment/LifePayment.Application/LifePay/LifePayService.cs    |    2 +-
 2 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/LifePayment/LifePayment.Application/LifePay/LifePayService.cs b/LifePayment/LifePayment.Application/LifePay/LifePayService.cs
index 25fc798..7d0e1f1 100644
--- a/LifePayment/LifePayment.Application/LifePay/LifePayService.cs
+++ b/LifePayment/LifePayment.Application/LifePay/LifePayService.cs
@@ -1306,7 +1306,7 @@
         var order = await _lifePayOrderRepository.Where(x => x.OrderNo == orderNo).FirstOrDefaultAsync();
         CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "璁㈠崟涓嶅瓨鍦�");
 
-        if (order.PayStatus == LifePayStatusEnum.宸叉敮浠�)
+        if (order.PayStatus != LifePayStatusEnum.鏈敮浠�)
         {
             return;
         }
diff --git a/LifePayment/LifePayment.HttpApi/LifePay/WxPayNotifyController.cs b/LifePayment/LifePayment.HttpApi/LifePay/WxPayNotifyController.cs
index 41be1d0..d5bead3 100644
--- a/LifePayment/LifePayment.HttpApi/LifePay/WxPayNotifyController.cs
+++ b/LifePayment/LifePayment.HttpApi/LifePay/WxPayNotifyController.cs
@@ -2,12 +2,14 @@
 using LifePayment.Domain;
 using LifePayment.Domain.Shared;
 using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Caching.Distributed;
 using Microsoft.Extensions.Logging;
 using Newtonsoft.Json;
 using System;
 using System.Text.RegularExpressions;
 using System.Threading.Tasks;
 using Volo.Abp.AspNetCore.Mvc;
+using Volo.Abp.Caching;
 using Volo.Abp.Uow;
 
 namespace LifePayment.HttpApi
@@ -22,18 +24,21 @@
         private readonly IWxPayApi _wxPayApi;
         private readonly ILifePayService _lifePayService;
         private readonly ILifePayOrderService _lifePayOrderService;
+        private readonly IDistributedCache<string> distributedCache;
         private readonly ILogger<WxPayNotifyController> _logger;
 
         public WxPayNotifyController(
                IWxPayApi wxPayApi,
                ILogger<WxPayNotifyController> logger,
                ILifePayService lifePayService,
-               ILifePayOrderService lifePayOrderService)
+               ILifePayOrderService lifePayOrderService,
+               IDistributedCache<string> distributedCache)
         {
             _wxPayApi = wxPayApi;
             _logger = logger;
             _lifePayService = lifePayService;
             _lifePayOrderService = lifePayOrderService;
+            this.distributedCache = distributedCache;
         }
 
         /// <summary>
@@ -56,17 +61,26 @@
                 {
                     if (wxPayNotice.TradeState == LifePaymentConstant.WxPayStatus.鏀粯鎴愬姛)
                     {
-                        await _lifePayService.LifePaySuccessHandler(wxPayNotice.OutTradeNo, wxPayNotice.TransactionId);
-
-                        // 鎻掑叆鏀舵敮娴佹按
-                        await _lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput()
+                        var key = $"WxRechargeNotify_{wxPayNotice.OutTradeNo}";
+                        if (string.IsNullOrWhiteSpace(distributedCache.Get(key)))
                         {
-                            OrderNo = wxPayNotice.OutTradeNo,
-                            OutOrderNo = wxPayNotice.TransactionId,
-                            LifePayType = LifePayTypeEnum.WxPay,
-                            ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Expenses,
-                            Amount = wxPayNotice.Amount.Total
-                        });
+                            await _lifePayService.LifePaySuccessHandler(wxPayNotice.OutTradeNo, wxPayNotice.TransactionId);
+
+                            // 鎻掑叆鏀舵敮娴佹按
+                            await _lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput()
+                            {
+                                OrderNo = wxPayNotice.OutTradeNo,
+                                OutOrderNo = wxPayNotice.TransactionId,
+                                LifePayType = LifePayTypeEnum.WxPay,
+                                ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Expenses,
+                                Amount = wxPayNotice.Amount.Total
+                            });
+
+                            distributedCache.Set(key, data, new DistributedCacheEntryOptions
+                            {
+                                AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10)
+                            });
+                        }
                     }
                 }
             }

--
Gitblit v1.9.1