Browse Source

fix(Trace): 增加对应用程序状态的检查以防止错误

- 在 Trace 类的析构函数中添加了对应用程序状态的检查,确保在特定条件下安全返回。

refactor(TestTixian): 优化测试用例请求构造

- 修改 TestTixian 测试用例中的请求构造方式,使用更简洁的方式设置请求数据。

refactor(FeeCalculatedEvent): 优化手续费率计算逻辑

- 在 FeeCalculatedEvent 中添加对手续费率计算的条件判断,确保在手续费为零时不发生除零错误。
notfff 6 months ago
parent
commit
62f305ff75

+ 3 - 0
UCore/Trace.php

@@ -20,6 +20,9 @@ class Trace
         if(app()->runningUnitTests() || defined('IS_UNITTEST')){
             return true;
         }
+        if (!function_exists('app') || !app() || !app()->bound('config')) {
+            return true;
+        }
 
         if(!defined('RUN_UNIQID')){
             define('RUN_UNIQID', uniqid());

+ 35 - 0
app/Module/ThirdParty/Tests/TestChongzhi.php

@@ -0,0 +1,35 @@
+<?php
+
+namespace App\Module\ThirdParty\Tests;
+
+use App\Module\ThirdParty\Services\WebhookDispatchService;
+use Illuminate\Support\Facades\Request;
+use Tests\TestCase;
+
+/**
+ *
+ * ./vendor/bin/phpunit app/Module/ThirdParty/Tests/TestChongzhi.php
+ */
+class TestChongzhi extends TestCase
+{
+
+    public function testA()
+    {
+        $user_id                = 39113;
+        $ac                     = 2;
+        $WebhookDispatchService = new WebhookDispatchService();
+        $request                = new \Illuminate\Http\Request();
+        $request->header('CONTENT_TYPE', 'json');
+        $request = new \Illuminate\Http\Request([], [
+            "order_id" => "145",
+            "user_id"  => "10002",
+            "amount"   => "1"
+        ]);
+        $request->setMethod('POST');
+        $res = $WebhookDispatchService->dispatch('urs', 'deposit', $request, true);
+
+        dump($res);
+
+    }
+
+}

+ 9 - 7
app/Module/ThirdParty/Tests/TestTixian.php

@@ -6,6 +6,10 @@ use App\Module\ThirdParty\Services\WebhookDispatchService;
 use Illuminate\Support\Facades\Request;
 use Tests\TestCase;
 
+/**
+ *
+ * ./vendor/bin/phpunit app/Module/ThirdParty/Tests/TestTixian.php
+ */
 class TestTixian extends TestCase
 {
 
@@ -16,13 +20,11 @@ class TestTixian extends TestCase
         $WebhookDispatchService = new WebhookDispatchService();
         $request                = new \Illuminate\Http\Request();
         $request->header('CONTENT_TYPE', 'json');
-        $in = new  \Symfony\Component\HttpFoundation\InputBag();
-        $in->add([
-                     "order_id" => "140",
-                     "user_id"  => "10002",
-                     "amount"   => "1"
-                 ]);
-        $request->setJson($in);
+        $request = new \Illuminate\Http\Request([], [
+            "order_id" => "144",
+            "user_id"  => "10002",
+            "amount"   => "1"
+        ]);
         $request->setMethod('POST');
         $res = $WebhookDispatchService->dispatch('urs', 'withdraw', $request, true);
 

+ 6 - 1
app/Module/Transfer/Events/FeeCalculatedEvent.php

@@ -130,12 +130,17 @@ class FeeCalculatedEvent
             $actualAmount = $calculatingEvent->amount;
             $totleAmout   = bcadd($calculatingEvent->amount, $calculatingEvent->feeAmount, 10);
         }
+        if($calculatingEvent->feeAmount > 0){
+            $feeRate = bcdiv($calculatingEvent->amount, $calculatingEvent->feeAmount, 10);
+        }else{
+            $feeRate = 0;
+        }
 
         return new static(
             app:                $calculatingEvent->app,
             amount:             $calculatingEvent->amount,
             type:               $calculatingEvent->type,
-            feeRate:            bcdiv($calculatingEvent->amount, $calculatingEvent->feeAmount, 10),
+            feeRate:            $feeRate,
             feeAmount:          $calculatingEvent->feeAmount,
             actualAmount:       $actualAmount,
             totleAmount:        $totleAmout,