From 37a0d618c0b33cd817f6ed12c0b54743a2af0ff3 Mon Sep 17 00:00:00 2001
From: zhengyuxuan <zhengyuxuan1995>
Date: 星期四, 27 三月 2025 13:40:03 +0800
Subject: [PATCH] Merge branch 'master' into dev-lifepay-v1.3

---
 LifePayment/LifePayment.Application/LifePay/LifePayService.cs |  132 +++++++++++++++++++++++++------------------
 1 files changed, 76 insertions(+), 56 deletions(-)

diff --git a/LifePayment/LifePayment.Application/LifePay/LifePayService.cs b/LifePayment/LifePayment.Application/LifePay/LifePayService.cs
index d422ac7..544d13e 100644
--- a/LifePayment/LifePayment.Application/LifePay/LifePayService.cs
+++ b/LifePayment/LifePayment.Application/LifePay/LifePayService.cs
@@ -51,6 +51,7 @@
     private readonly IAlipayInterfaceManager _alipayInterfaceManager;
     private readonly IWxPayApi _wxPayApi;
     private readonly WxPayOption _wxPayOptions;
+    private readonly InitSetting _initSettingOptions;
 
     private readonly IACOOLYManager _aCOOLYManager;
 
@@ -67,6 +68,7 @@
                           IAlipayInterfaceManager aliPayInterfaceManager,
                           IWxPayApi wxPayApi,
                           IOptions<WxPayOption> wxPayOptions,
+                          IOptions<InitSetting> initSettingOptions,
                           IRepository<LifePayChannles, Guid> lifePayChannlesRep,
                           IRepository<LifePayAccount, Guid> lifePayAccount,
                           IDataFilter dataFilter,
@@ -83,6 +85,7 @@
         _alipayInterfaceManager = aliPayInterfaceManager;
         _wxPayApi = wxPayApi;
         _wxPayOptions = wxPayOptions.Value;
+        _initSettingOptions = initSettingOptions.Value;
         _distributedEventBus = distributedEventBus;
         _lifePayChannlesRep = lifePayChannlesRep;
         _lifePayAccount = lifePayAccount;
@@ -265,19 +268,19 @@
                             from b in temp.DefaultIfEmpty()
                             select new LifePayOrderListOutput
                             {
-                                DiscountAmount = a.DiscountAmount,
+                                DiscountAmount = a.DiscountAmount ?? 0,
                                 FinishTime = a.FinishTime,
                                 Id = a.Id,
-                                LifePayOrderStatus = a.LifePayOrderStatus,
+                                LifePayOrderStatus = a.LifePayOrderStatus?? 0,
                                 LifePayOrderType = a.LifePayOrderType,
                                 LifePayType = a.LifePayType,
                                 OrderNo = a.OrderNo,
-                                PayAmount = a.PayAmount,
+                                PayAmount = a.PayAmount ?? 0,
                                 PhoneNumber = a.PhoneNumber,
-                                RechargeAmount = a.RechargeAmount,
+                                RechargeAmount = a.RechargeAmount??0,
                                 UserId = a.UserId,
                                 OutOrderNo = a.OutOrderNo,
-                                PayStatus = a.PayStatus,
+                                PayStatus = a.PayStatus?? 0,
                                 PayTime = a.PayTime,
                                 ACOOLYOrderNo = a.ACOOLYOrderNo,
                                 RefundCredentialsImgUrl = a.RefundCredentialsImgUrl.GetOssPath(),
@@ -321,19 +324,19 @@
                             from b in temp.DefaultIfEmpty()
                             select new LifePayOrderListOutput
                             {
-                                DiscountAmount = a.DiscountAmount,
+                                DiscountAmount = a.DiscountAmount ?? 0,
                                 FinishTime = a.FinishTime,
                                 Id = a.Id,
-                                LifePayOrderStatus = a.LifePayOrderStatus,
+                                LifePayOrderStatus = a.LifePayOrderStatus ?? 0,
                                 LifePayOrderType = a.LifePayOrderType,
                                 LifePayType = a.LifePayType,
                                 OrderNo = a.OrderNo,
-                                PayAmount = a.PayAmount,
+                                PayAmount = a.PayAmount ?? 0,
                                 PhoneNumber = a.PhoneNumber,
-                                RechargeAmount = a.RechargeAmount,
+                                RechargeAmount = a.RechargeAmount ?? 0,
                                 UserId = a.UserId,
                                 OutOrderNo = a.OutOrderNo,
-                                PayStatus = a.PayStatus,
+                                PayStatus = a.PayStatus ?? 0,
                                 PayTime = a.PayTime,
                                 ACOOLYOrderNo = a.ACOOLYOrderNo,
                                 RefundCredentialsImgUrl = a.RefundCredentialsImgUrl.GetOssPath(),
@@ -405,25 +408,24 @@
         CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "璁㈠崟涓嶅瓨鍦�");
         var user = await _lifePayUserRepository.FirstOrDefaultAsync(x => x.Id == order.UserId);
         CheckExtensions.IfTrueThrowUserFriendlyException(user == null, "鐢ㄦ埛涓嶅瓨鍦�");
-        var orderpirce = await GetOrderPrice(order.RechargeAmount, order.PayAmount, order.PlatformRate ?? 0, order.ChannleRate ?? 0, order.ChannlesRakeRate ?? 0, order.PremiumRate ?? 0);
-
+        var orderpirce = await GetOrderPrice(order.RechargeAmount ?? 0, order.PayAmount ?? 0, order.PlatformRate ?? 0, order.ChannleRate ?? 0, order.ChannlesRakeRate ?? 0, order.PremiumRate ?? 0);
 
         var result = new LifePayOrderOutput()
         {
             UserName = user.Name,
             UserPhoneNumber = user.PhoneNumber,
-            DiscountAmount = order.DiscountAmount,
+            DiscountAmount = order.DiscountAmount ?? 0,
             FinishTime = order.FinishTime,
             Id = order.Id,
             OutOrderNo = order.OutOrderNo,
             LifePayChannle = channle.ChannlesName,
-            Status = order.LifePayOrderStatus,
+            Status = order.LifePayOrderStatus ?? 0,
             LifePayOrderType = order.LifePayOrderType,
             LifePayType = order.LifePayType,
             OrderNo = order.OrderNo,
-            PayAmount = order.PayAmount,
-            RechargeAmount = order.RechargeAmount,
-            PayStatus = order.PayStatus,
+            PayAmount = order.PayAmount ?? 0,
+            RechargeAmount = order.RechargeAmount ?? 0,
+            PayStatus = order.PayStatus ?? 0,
             PayTime = order.PayTime,
             OrderParamDetailJsonStr = order.OrderParamDetailJsonStr,
             RefundCredentialsImgUrl = order.RefundCredentialsImgUrl.GetOssPath(),
@@ -465,18 +467,18 @@
         {
             UserName = user.Name,
             UserPhoneNumber = user.PhoneNumber,
-            DiscountAmount = order.DiscountAmount,
+            DiscountAmount = order.DiscountAmount ?? 0,
             FinishTime = order.FinishTime,
             Id = order.Id,
             OutOrderNo = order.OutOrderNo,
             LifePayChannle = channle.ChannlesName,
-            Status = order.LifePayOrderStatus,
+            Status = order.LifePayOrderStatus ?? 0,
             LifePayOrderType = order.LifePayOrderType,
             LifePayType = order.LifePayType,
             OrderNo = order.OrderNo,
-            PayAmount = order.PayAmount,
-            RechargeAmount = order.RechargeAmount,
-            PayStatus = order.PayStatus,
+            PayAmount = order.PayAmount ?? 0,
+            RechargeAmount = order.RechargeAmount ?? 0,
+            PayStatus = order.PayStatus ?? 0,
             PayTime = order.PayTime,
             RefundCredentialsImgUrl = order.RefundCredentialsImgUrl.GetOssPath(),
             CreationTime = order.CreationTime,
@@ -521,16 +523,16 @@
                                             .Select(x =>
                                                     new UserLifePayOrderOutput
                                                     {
-                                                        DiscountAmount = x.DiscountAmount,
+                                                        DiscountAmount = x.DiscountAmount ?? 0,
                                                         FinishTime = x.FinishTime,
                                                         Id = x.Id,
-                                                        LifePayOrderStatus = x.LifePayOrderStatus,
+                                                        LifePayOrderStatus = x.LifePayOrderStatus ?? 0,
                                                         LifePayOrderType = x.LifePayOrderType,
                                                         LifePayType = x.LifePayType,
                                                         OrderNo = x.OrderNo,
-                                                        PayAmount = x.PayAmount,
-                                                        RechargeAmount = x.RechargeAmount,
-                                                        PayStatus = x.PayStatus,
+                                                        PayAmount = x.PayAmount ?? 0,
+                                                        RechargeAmount = x.RechargeAmount ?? 0,
+                                                        PayStatus = x.PayStatus ?? 0,
                                                         PayTime = x.PayTime,
                                                         OrderParamDetailJsonStr = x.OrderParamDetailJsonStr,
                                                         RefundCredentialsImgUrl = x.RefundCredentialsImgUrl.GetOssPath(),
@@ -552,16 +554,16 @@
                                             .Select(x =>
                                                     new UserLifePayOrderOutput
                                                     {
-                                                        DiscountAmount = x.DiscountAmount,
+                                                        DiscountAmount = x.DiscountAmount ?? 0,
                                                         FinishTime = x.FinishTime,
                                                         Id = x.Id,
-                                                        LifePayOrderStatus = x.LifePayOrderStatus,
+                                                        LifePayOrderStatus = x.LifePayOrderStatus?? 0 ,
                                                         LifePayOrderType = x.LifePayOrderType,
                                                         LifePayType = x.LifePayType,
                                                         OrderNo = x.OrderNo,
-                                                        PayAmount = x.PayAmount,
-                                                        RechargeAmount = x.RechargeAmount,
-                                                        PayStatus = x.PayStatus,
+                                                        PayAmount = x.PayAmount ?? 0,
+                                                        RechargeAmount = x.RechargeAmount ?? 0,
+                                                        PayStatus = x.PayStatus ?? 0,
                                                         PayTime = x.PayTime,
                                                         OrderParamDetailJsonStr = x.OrderParamDetailJsonStr,
                                                         RefundCredentialsImgUrl = x.RefundCredentialsImgUrl.GetOssPath(),
@@ -587,7 +589,7 @@
     public async Task<LifePayStatusEnum> GetPayStatusByOrderNo(string orderNo)
     {
         return await _lifePayOrderRepository.Where(x => x.OrderNo == orderNo)
-                                            .Select(x => x.PayStatus)
+                                            .Select(x => x.PayStatus ?? 0)
                                             .FirstOrDefaultAsync();
     }
 
@@ -643,7 +645,7 @@
                                                         OrderNo = x.OrderNo,
                                                         RefundCheckRemark = x.RefundCheckRemark,
                                                         RefundApplyRemark = x.RefundApplyRemark,
-                                                        LifePayOrderStatus = x.LifePayOrderStatus,
+                                                        LifePayOrderStatus = x.LifePayOrderStatus ?? 0,
                                                     }).FirstOrDefaultAsync();
 
         CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "鏈壘鍒拌鍗曚俊鎭�");
@@ -838,6 +840,11 @@
         var channle = await GetLifePayChannlesDtoByNum(input.ChannelId);
         CheckExtensions.IfTrueThrowUserFriendlyException(channle == null, "娓犻亾涓嶅瓨鍦�");
 
+        var repeatOrder = await _lifePayOrderRepository.Where(x => x.LifePayOrderType == LifePayOrderTypeEnum.璇濊垂璁㈠崟 && x.PayStatus == LifePayStatusEnum.宸叉敮浠�
+        && x.LifePayOrderStatus == LifePayOrderStatusEnum.鍏呭�间腑 && x.OrderParamDetailJsonStr.Contains(input.ProductData.IspCode)
+        && x.OrderParamDetailJsonStr.Contains(input.ProductData.Phone)).ToListAsync();
+         CheckExtensions.IfTrueThrowUserFriendlyException(repeatOrder.Count() > 0, "鎮ㄦ湁鍚屾埛鍙疯鍗曟鍦ㄥ厖鍊间腑锛岃鍕块噸澶嶅厖鍊�");
+
         //var rate = await GetRate();
         //CheckExtensions.IfTrueThrowUserFriendlyException(rate.IsNullOrEmpty(), "鏈厤缃姌鎵�");
 
@@ -894,7 +901,10 @@
 
         //var rate = await GetRate();
         //CheckExtensions.IfTrueThrowUserFriendlyException(rate.IsNullOrEmpty(), "鏈厤缃姌鎵�");
-
+        var repeatOrder = await _lifePayOrderRepository.Where(x => x.LifePayOrderType == LifePayOrderTypeEnum.鐢佃垂璁㈠崟 && x.PayStatus == LifePayStatusEnum.宸叉敮浠�
+         && x.LifePayOrderStatus == LifePayOrderStatusEnum.鍏呭�间腑 && x.OrderParamDetailJsonStr.Contains(input.ProductData.ElectricType)
+         && x.OrderParamDetailJsonStr.Contains(input.ProductData.ElectricAccount)).ToListAsync();
+                CheckExtensions.IfTrueThrowUserFriendlyException(repeatOrder.Count() > 0, "鎮ㄦ湁鍚屾埛鍙疯鍗曟鍦ㄥ厖鍊间腑锛岃鍕块噸澶嶅厖鍊�");
 
         var rate = await GetLifePayRate(channle, LifePayRateTypeEnum.榛樿鐢佃垂鎶樻墸);
 
@@ -946,6 +956,10 @@
 
         //var rate = await GetRate();
         //CheckExtensions.IfTrueThrowUserFriendlyException(rate.IsNullOrEmpty(), "鏈厤缃姌鎵�");
+        var repeatOrder = await _lifePayOrderRepository.Where(x => x.LifePayOrderType == LifePayOrderTypeEnum.鐕冩皵璁㈠崟 && x.PayStatus == LifePayStatusEnum.宸叉敮浠�
+        && x.LifePayOrderStatus == LifePayOrderStatusEnum.鍏呭�间腑 && x.OrderParamDetailJsonStr.Contains(input.ProductData.GasOrgType)
+        && x.OrderParamDetailJsonStr.Contains(input.ProductData.GasAccount)).ToListAsync();
+        CheckExtensions.IfTrueThrowUserFriendlyException(repeatOrder.Count() > 0, "鎮ㄦ湁鍚屾埛鍙疯鍗曟鍦ㄥ厖鍊间腑锛岃鍕块噸澶嶅厖鍊�");
 
 
         var rate = await GetLifePayRate(channle, LifePayRateTypeEnum.榛樿鐕冩皵鎶樻墸);
@@ -1017,10 +1031,10 @@
 
 #if DEBUG
         //var payUrl = await GetPayQRCode(order.LifePayType.Value, order.OrderNo, desc, 0.01m, ip, input.H5Type);
-        var payUrl = await GetPayQRCode(order.LifePayType.Value, order.OrderNo, desc, order.PayAmount, ip, input.H5Type);
+        var payUrl = await GetPayQRCode(order.LifePayType.Value, order.OrderNo, desc, order.PayAmount ?? 0, ip, input.H5Type);
 #else
       //var payUrl = await GetPayQRCode(order.LifePayType.Value, order.OrderNo, desc, 0.01m, ip, input.H5Type);
-        var payUrl = await GetPayQRCode(order.LifePayType.Value, order.OrderNo, desc, order.PayAmount, ip, input.H5Type);
+        var payUrl = await GetPayQRCode(order.LifePayType.Value, order.OrderNo, desc, order.PayAmount??0, ip, input.H5Type);
 #endif
 
         return payUrl;
@@ -1065,7 +1079,7 @@
 
         //  var result = await PayTransactionsJsAPI(input.OpenId, input.Attach,  order.PayAmount, input.OrderNo, desc);
 
-        var result = await PayTransactionsJsAPI(input.OpenId, input.PayAppId, input.Attach, order.PayAmount, input.OrderNo, desc);
+        var result = await PayTransactionsJsAPI(input.OpenId, input.PayAppId, input.Attach, order.PayAmount ?? 0, input.OrderNo, desc);
         return result;
         //var payUrl = await GetPayQRCode(order.LifePayType.Value, order.OrderNo, desc, 0.01m, ip, input.H5Type);
         //var payUrl = await GetPayQRCode(order.LifePayType.Value, order.OrderNo, desc, order.PayAmount, ip, input.H5Type);
@@ -1389,7 +1403,7 @@
 
         if (input.LifePayRefundType == LifePayRefundTypeEnum.鍏ㄩ閫�娆�)
         {
-            input.RefundPrice = order.PayAmount;
+            input.RefundPrice = order.PayAmount ?? 0;
         }
 
         if (order.LifePayOrderStatus != LifePayOrderStatusEnum.寰呴��娆� || order.PayStatus != LifePayStatusEnum.宸叉敮浠� || order.LifePayRefundStatus != LifePayRefundStatusEnum.寰呴��娆�)
@@ -1815,15 +1829,21 @@
 
     private (decimal PayAmont, decimal DiscountAmount, decimal RechargeAmount) CalculateAmount(decimal amount, decimal rate)
     {
-        /// 姝e父鏀粯
-        var payAmount = decimal.Round(amount * rate / 100, 2, MidpointRounding.AwayFromZero);
+        if (_initSettingOptions.OpenTheOnePennyTest)
+        {
+            /// 1鍒嗛挶鏀粯
+            decimal payAmount = 0.01m;
 
-        /// 1鍒嗛挶鏀粯
-        //decimal payAmount = 0.01m;
+            CheckExtensions.IfTrueThrowUserFriendlyException(payAmount < 0.01m, "鏀粯閲戦閿欒");
 
-        CheckExtensions.IfTrueThrowUserFriendlyException(payAmount < 0.01m, "鏀粯閲戦閿欒");
-
-        return (payAmount, amount - payAmount, amount);
+            return (payAmount, amount - payAmount, amount);
+        }
+        else
+        {
+            /// 姝e父鏀粯
+            var payAmount = decimal.Round(amount * rate / 100, 2, MidpointRounding.AwayFromZero);
+            return (payAmount, amount - payAmount, amount);
+        }
     }
 
     private void SetOrderStatus(LifePayOrder order, string code)
@@ -2042,19 +2062,19 @@
                       from b in temp.DefaultIfEmpty()
                       select new LifePayOrderListOutput
                       {
-                          DiscountAmount = a.DiscountAmount,
+                          DiscountAmount = a.DiscountAmount ?? 0,
                           FinishTime = a.FinishTime,
                           Id = a.Id,
-                          LifePayOrderStatus = a.LifePayOrderStatus,
+                          LifePayOrderStatus = a.LifePayOrderStatus ?? 0,
                           LifePayOrderType = a.LifePayOrderType,
                           LifePayType = a.LifePayType,
                           OrderNo = a.OrderNo,
-                          PayAmount = a.PayAmount,
+                          PayAmount = a.PayAmount ?? 0,
                           PhoneNumber = a.PhoneNumber,
-                          RechargeAmount = a.RechargeAmount,
+                          RechargeAmount = a.RechargeAmount ?? 0,
                           UserId = a.UserId,
                           OutOrderNo = a.OutOrderNo,
-                          PayStatus = a.PayStatus,
+                          PayStatus = a.PayStatus ?? 0,
                           PayTime = a.PayTime,
                           ACOOLYOrderNo = a.ACOOLYOrderNo,
                           RefundCredentialsImgUrl = a.RefundCredentialsImgUrl.GetOssPath(),
@@ -2093,19 +2113,19 @@
                       from b in temp.DefaultIfEmpty()
                       select new LifePayOrderListOutput
                       {
-                          DiscountAmount = a.DiscountAmount,
+                          DiscountAmount = a.DiscountAmount ?? 0,
                           FinishTime = a.FinishTime,
                           Id = a.Id,
-                          LifePayOrderStatus = a.LifePayOrderStatus,
+                          LifePayOrderStatus = a.LifePayOrderStatus ?? 0,
                           LifePayOrderType = a.LifePayOrderType,
                           LifePayType = a.LifePayType,
                           OrderNo = a.OrderNo,
-                          PayAmount = a.PayAmount,
+                          PayAmount = a.PayAmount ?? 0,
                           PhoneNumber = a.PhoneNumber,
-                          RechargeAmount = a.RechargeAmount,
+                          RechargeAmount = a.RechargeAmount ?? 0,
                           UserId = a.UserId,
                           OutOrderNo = a.OutOrderNo,
-                          PayStatus = a.PayStatus,
+                          PayStatus = a.PayStatus ?? 0,
                           PayTime = a.PayTime,
                           ACOOLYOrderNo = a.ACOOLYOrderNo,
                           RefundCredentialsImgUrl = a.RefundCredentialsImgUrl.GetOssPath(),

--
Gitblit v1.9.1