Quellcode durchsuchen

refactor(lakala): 注入自定义日志服务并替换原有日志调用

- 在 NotifyService 和 TransactionService 中注入自定义 Log 类
- 替换对 think\facade\Log 的依赖为内部封装的 Log 服务
- 新增 Log 类继承自 SixShop\System\Log 并指定扩展 ID
- 统一通过 $this->log 调用 debug 方法记录请求与响应数据
- 移除旧的日志门面引用,增强日志模块的可维护性与扩展性
runphp vor 3 Monaten
Ursprung
Commit
59acf1703a
3 geänderte Dateien mit 23 neuen und 8 gelöschten Zeilen
  1. 15 0
      src/Log.php
  2. 4 4
      src/Service/NotifyService.php
  3. 4 4
      src/Service/TransactionService.php

+ 15 - 0
src/Log.php

@@ -0,0 +1,15 @@
+<?php
+declare(strict_types=1);
+
+namespace SixShop\Lakala;
+
+use SixShop\System\ExtensionManager;
+use think\App;
+
+class Log extends \SixShop\System\Log
+{
+    public function __construct(App $app, private ExtensionManager $extensionManager)
+    {
+        parent::__construct($app, $extensionManager, Extension::EXTENSION_ID);
+    }
+}

+ 4 - 4
src/Service/NotifyService.php

@@ -3,19 +3,19 @@ declare(strict_types=1);
 namespace SixShop\Lakala\Service;
 
 use SixShop\Lakala\Config;
+use SixShop\Lakala\Log;
 use SixShop\Lakala\OpenAPISDK\V3\Api\LakalaNotifyApi;
 use SixShop\Lakala\OpenAPISDK\V3\Model\ModelTradeNotify;
 use SixShop\Lakala\PaymentProvider;
 use SixShop\Payment\Enum\PaymentStatusEnum;
 use SixShop\Payment\Model\ExtensionPaymentModel;
-use think\facade\Log;
 use function SixShop\Core\error_response;
 use function SixShop\Core\throw_logic_exception;
 
 class NotifyService
 {
     private LakalaNotifyApi $notifyApi;
-    public function __construct(private Config $config, private PaymentProvider $paymentProvider)
+    public function __construct(private Config $config, private PaymentProvider $paymentProvider, private Log $log)
     {
         $this->notifyApi = new LakalaNotifyApi($this->config->getV3Config());
     }
@@ -24,7 +24,7 @@ class NotifyService
     {
         $headers = getallheaders();
         $body = file_get_contents('php://input');
-        Log::debug('lakala notify headers:{headers}  body:{body}', [
+        $this->log->debug('lakala notify headers:{headers}  body:{body}', [
             'headers' => json_encode($headers),
             'body' => $body
         ]);
@@ -42,6 +42,6 @@ class NotifyService
             throw_logic_exception('lakala notify transaction_id status error');
         }
         $this->paymentProvider->query($payment->id);
-        Log::debug('lakala notified success {transaction_id}', ['transaction_id' => $payment->transaction_id]);
+        $this->log->debug('lakala notified success {transaction_id}', ['transaction_id' => $payment->transaction_id]);
     }
 }

+ 4 - 4
src/Service/TransactionService.php

@@ -2,6 +2,7 @@
 declare(strict_types=1);
 namespace SixShop\Lakala\Service;
 
+use SixShop\Lakala\Log;
 use SixShop\Lakala\OpenAPISDK\V3\Api\LakalaApi;
 use SixShop\Lakala\OpenAPISDK\V3\Api\QueryTradequeryApi;
 use SixShop\Lakala\OpenAPISDK\V3\Api\TransPreorderApi;
@@ -15,7 +16,6 @@ use SixShop\Lakala\OpenAPISDK\V3\Model\TradePreorderWechaGoodsDetail;
 use SixShop\Lakala\OpenAPISDK\V3\Model\TransPreorderRequest;
 use SixShop\Lakala\Config;
 use SixShop\Lakala\Dto\LocationInfo;
-use think\facade\Log;
 use function SixShop\Core\throw_logic_exception;
 
 /**
@@ -28,7 +28,7 @@ class TransactionService
     private QueryTradequeryApi $queryTradequeryApi;
 
     private LakalaApi $lakalaApi;
-    public function __construct(private Config $config)
+    public function __construct(private Config $config, private Log $log)
     {
         $this->transPreorderApi = new TransPreorderApi($config->getV3Config());
         $this->queryTradequeryApi = new QueryTradequeryApi($config->getV3Config());
@@ -85,9 +85,9 @@ class TransactionService
         $request->setRemark($remark);
         $request->setAccBusiFields($accBusiFields);
         $request->setCompleteNotifyUrl($this->config->complete_notify_url);
-        Log::debug('preOrder request:'.json_encode($request));
+        $this->log->debug('preOrder request:'.json_encode($request));
         $response = $this->transPreorderApi->transPreorder($request);
-        Log::debug('preOrder response:'.json_encode($response->getRespData()));
+        $this->log->debug('preOrder response:'.json_encode($response->getRespData()));
         if ($response->getCode() == 'BBS00000') {
             return $response->getRespData();
         } else {