From d02041d6869647e065d2d496d2a9ce0725a2749d Mon Sep 17 00:00:00 2001 From: mzeros Date: Sat, 7 Dec 2024 12:24:34 +0800 Subject: [PATCH] =?UTF-8?q?fix(gateway):=20=E4=BC=98=E5=8C=96=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 query 和 submit 方法中添加 try-catch 块,捕获异常并记录日志 - 新增 writelog 方法用于统一日志记录 - 异常发生时返回错误码 -100 和异常信息 --- app/gateway/controller/v4/Handle.php | 64 +++++++++++++++++++--------- 1 file changed, 44 insertions(+), 20 deletions(-) diff --git a/app/gateway/controller/v4/Handle.php b/app/gateway/controller/v4/Handle.php index 39e2d61..56c0b9d 100644 --- a/app/gateway/controller/v4/Handle.php +++ b/app/gateway/controller/v4/Handle.php @@ -3,6 +3,7 @@ namespace app\gateway\controller\v4; use app\channel\service\CardService; +use dever\Log; /** * 接口处理 @@ -17,34 +18,47 @@ class Handle extends Core # 查询接口 一般用于查询数据,同步执行 public function query(): void { - $settingStatus = sysconf('settingStatus'); - if ($settingStatus == 1) { - $this->no(-1000); + try{ + $settingStatus = sysconf('settingStatus'); + if ($settingStatus == 1) { + $this->no(-1000); + } + $this->checkOpenTime(sysconf('settingOpenTime')); + + if (isset($this->merchant['opentime']) && $this->merchant['opentime']) { + $this->checkOpenTime($this->merchant['opentime']); + } + $data = $this->channel($this->mid, $this->product, false); + $this->yes($data); + } catch (\Exception $e){ + $this->writelog($e->getMessage(), 'error'); + $this->no(-100,$e->getMessage()); } - $this->checkOpenTime(sysconf('settingOpenTime')); - - if (isset($this->merchant['opentime']) && $this->merchant['opentime']) { - $this->checkOpenTime($this->merchant['opentime']); - } - $data = $this->channel($this->mid, $this->product, false); - $this->yes($data); + } # 提交接口 一般用于提交数据,异步执行 public function submit(): void { - $settingStatus = sysconf('settingStatus'); - if ($settingStatus == 1) { - $this->no(-1000); - } - $this->checkOpenTime(sysconf('settingOpenTime')); - - if (isset($this->merchant['opentime']) && $this->merchant['opentime']) { - $this->checkOpenTime($this->merchant['opentime']); + try{ + $settingStatus = sysconf('settingStatus'); + if ($settingStatus == 1) { + $this->no(-1000); + } + $this->checkOpenTime(sysconf('settingOpenTime')); + + if (isset($this->merchant['opentime']) && $this->merchant['opentime']) { + $this->checkOpenTime($this->merchant['opentime']); + } + + $data = $this->channel($this->mid, $this->product, true); + $this->yes($data); + } catch (\Exception $e){ + + $this->writelog($e->getMessage(), 'error'); + $this->no(-100,$e->getMessage()); } - $data = $this->channel($this->mid, $this->product, true); - $this->yes($data); } # 提交接口 一般用于提交数据,异步执行 @@ -305,4 +319,14 @@ class Handle extends Core return $v; } + protected function writelog($data,$t = '') + { + if($t){ + Log::write('gateway', 'Handle_'.$t, $data); + }else{ + Log::write('gateway', 'Handle', $data); + } + + } + } \ No newline at end of file