From 6d3f89d32a23a14dd76cfab07ed575457ade1cf4 Mon Sep 17 00:00:00 2001 From: Chaim Date: Tue, 19 May 2020 15:08:38 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E5=A2=9E=E5=8A=A0=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86=E6=8E=A5=E7=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- composer.json | 1 + src/cache/Mysql.php | 6 ++-- src/exception/ThinkException.php | 49 ++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 src/exception/ThinkException.php diff --git a/README.md b/README.md index be40d1f..2fcb61c 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ - 阿里云仓库地址:https://github.com/GC0202/ThinkLibrary - CODING:https://liguangchun-01.coding.net/p/ThinkLibrary/d/ThinkLibrary/git - CODING:https://aizhineng.coding.net/p/ThinkLibrary/d/ThinkLibrary/git -- https://liguangchundt.coding.net/p/ThinkLibrary/d/ThinkLibrary/git +- 腾讯云:https://liguangchundt.coding.net/p/ThinkLibrary/d/ThinkLibrary/git - 微信:https://git.weixin.qq.com/liguangchun/ThinkLibrary - 华为云:https://codehub-cn-south-1.devcloud.huaweicloud.com/composer00001/ThinkLibrary.git diff --git a/composer.json b/composer.json index 597505e..ae1570d 100644 --- a/composer.json +++ b/composer.json @@ -31,6 +31,7 @@ "ext-iconv": "*", "ext-curl": "*", "ext-dom": "*", + "ext-http": "*", "topthink/framework": "^6.0.0", "topthink/think-orm": "^2.0", "topthink/think-view": "^1.0", diff --git a/src/cache/Mysql.php b/src/cache/Mysql.php index 1a44f3d..287f381 100644 --- a/src/cache/Mysql.php +++ b/src/cache/Mysql.php @@ -131,11 +131,12 @@ class Mysql public function inc(int $int = 1) { $cache_value = (int)$this->get(); - return Db::table($this->table) + $result = Db::table($this->table) ->where('cache_name', $this->cache_name) ->update([ 'cache_value' => $cache_value + $int ]); + return $result ? true : false; } /** @@ -148,10 +149,11 @@ class Mysql public function dec(int $int = 1) { $cache_value = (int)$this->get(); - return Db::table($this->table) + $result = Db::table($this->table) ->where('cache_name', $this->cache_name) ->update([ 'cache_value' => $cache_value - $int ]); + return $result ? true : false; } } diff --git a/src/exception/ThinkException.php b/src/exception/ThinkException.php new file mode 100644 index 0000000..4dfc036 --- /dev/null +++ b/src/exception/ThinkException.php @@ -0,0 +1,49 @@ +getError(), 422); + } + + // 请求异常 + if ($e instanceof HttpException && $request->isAjax()) { + return response($e->getMessage(), $e->getStatusCode()); + } + + // 其他错误交给系统处理 + return parent::render($request, $e); + } +}