diff --git a/CHANGELOG.md b/CHANGELOG.md index 28b00ca..e981d41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## v6.0.81 / 2020-07-12 +- 优化代码质量 + ## v6.0.80 / 2020-07-12 - 优化描述 diff --git a/src/cache/Mysql.php b/src/cache/Mysql.php index 02014b9..0668cb2 100644 --- a/src/cache/Mysql.php +++ b/src/cache/Mysql.php @@ -73,7 +73,8 @@ class Mysql 'cache_value' => $cache_value, 'cache_expire' => Times::dateRear("Y-m-d H:i:s", $this->cache_expire) ]); - return $result ? true : false; + if (empty($result)) return false; + return true; } /** @@ -107,7 +108,8 @@ class Mysql $result = Db::table($this->table) ->where('cache_name', $this->cache_name) ->delete(); - return $result ? true : false; + if (empty($result)) return false; + return true; } /** @@ -126,7 +128,8 @@ class Mysql 'cache_value' => $cache_value, 'cache_expire' => Times::dateRear("Y-m-d H:i:s", $this->cache_expire) ]); - return $result ? true : false; + if (empty($result)) return false; + return true; } /** @@ -146,7 +149,8 @@ class Mysql ->update([ 'cache_value' => $cache_value + $int ]); - return $result ? true : false; + if (empty($result)) return false; + return true; } /** @@ -166,6 +170,7 @@ class Mysql ->update([ 'cache_value' => $cache_value - $int ]); - return $result ? true : false; + if (empty($result)) return false; + return true; } } diff --git a/src/common.php b/src/common.php index b6e6e04..efaeecd 100644 --- a/src/common.php +++ b/src/common.php @@ -28,7 +28,7 @@ use think\db\exception\ModelNotFoundException; /** * 定义当前版本 */ -const VERSION = '6.0.80'; +const VERSION = '6.0.81'; if (!function_exists('get_ip_info')) { /** diff --git a/src/facade/Files.php b/src/facade/Files.php index 21b78d1..a676590 100644 --- a/src/facade/Files.php +++ b/src/facade/Files.php @@ -36,6 +36,8 @@ use think\Facade; * @method static bool folderZip(string $name, string $suffix_name = '.png', string $file_name = '*') 把文件夹里面的文件打包成zip文件 * @method static string getFiles(string $path) 获取目录下的所有文件和目录 * @method static bool rmFiles(string $path) 删除目录下的文件 + * @method static bool judgeFile(string $path) 判断文件是否存在 + * @method static bool judgeContents(string $path) 判断目录是否存在 */ class Files extends Facade { diff --git a/src/helper/Files.php b/src/helper/Files.php index 1ac70b9..bc1c935 100644 --- a/src/helper/Files.php +++ b/src/helper/Files.php @@ -147,4 +147,26 @@ class Files } return true; } + + /** + * 判断文件是否存在 + * @param string $path + * @return bool + */ + public function judgeFile(string $path): bool + { + if (file_exists($path)) return true; + return false; + } + + /** + * 判断目录是否存在 + * @param string $path + * @return bool + */ + public function judgeContents(string $path): bool + { + if (is_dir($path)) return true; + return false; + } } diff --git a/src/service/bt/ApiService.php b/src/service/bt/ApiService.php index 3e0abb1..9c62fa1 100644 --- a/src/service/bt/ApiService.php +++ b/src/service/bt/ApiService.php @@ -20,6 +20,7 @@ namespace DtApp\ThinkLibrary\service\bt; use DtApp\ThinkLibrary\exception\DtaException; +use DtApp\ThinkLibrary\facade\Files; use DtApp\ThinkLibrary\Service; use DtApp\ThinkLibrary\service\curl\BtService; @@ -346,14 +347,8 @@ class ApiService extends Service public function toArray() { $this->getHttp(); - switch ($this->where['type']) { - case 'sites': - $this->getDataWithOrderOpt(); - break; - default: - $this->getDataWithCount(); - break; - } + if ($this->where['type'] == 'sites') $this->getDataWithOrderOpt(); + else $this->getDataWithCount(); if (empty($this->backtrack)) return []; if (is_array($this->backtrack)) return $this->backtrack; return json_decode($this->backtrack, true); @@ -386,7 +381,7 @@ class ApiService extends Service //定义cookie保存位置 $file = app()->getRootPath() . 'runtime/dtapp/bt/cookie/'; $cookie_file = $file . md5($this->panel) . '.cookie'; - is_dir($file) or mkdir($file, 0777, true); + if (empty(Files::judgeContents($file))) mkdir($file, 0777, true); if (!file_exists($cookie_file)) { $fp = fopen($cookie_file, 'w+'); fclose($fp);