From 0fb9196d49d36c94607d91bb412dce1b1a325819 Mon Sep 17 00:00:00 2001 From: augushong Date: Tue, 19 Apr 2022 18:11:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96sysconfig=E5=8A=A9=E6=89=8B?= =?UTF-8?q?=E5=87=BD=E6=95=B0=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common.php | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/app/common.php b/app/common.php index e9cb38f..c1fd0d2 100644 --- a/app/common.php +++ b/app/common.php @@ -34,7 +34,6 @@ if (!function_exists('password')) { $value = sha1('blog_') . md5($value) . md5('_encrypt') . sha1($value); return sha1($value); } - } if (!function_exists('xdebug')) { @@ -58,12 +57,12 @@ if (!function_exists('xdebug')) { $str = ''; - if(is_string($data)){ + if (is_string($data)) { $str = $data; - }else{ - if(is_array($data) || is_object($data)){ + } else { + if (is_array($data) || is_object($data)) { $str = print_r($data, true); - }else{ + } else { $str = var_export($data, true); } } @@ -79,20 +78,22 @@ if (!function_exists('sysconfig')) { /** * 获取系统配置信息 * @param $group - * @param null $name + * @param null|bool|string $name * @return array|mixed */ - function sysconfig($group, $name = null) + function sysconfig($group, $name = null, $default = null) { if ($name === true) { $value = Cache::get('sysconfig_' . $group); if (empty($value)) { - $value = \app\admin\model\SystemConfig::where('name', $group)->value('value'); + $value = \app\admin\model\SystemConfig::where('name', $group)->column('value', 'name'); Cache::tag('sysconfig')->set('sysconfig_' . $group, $value); } - + if (is_null($value)) { + return $default; + } return $value; } @@ -108,6 +109,9 @@ if (!function_exists('sysconfig')) { Cache::tag('sysconfig')->set("sysconfig_{$group}", $value, 3600); } } + if (is_null($value)) { + return $default; + } return $value; } } @@ -128,7 +132,6 @@ if (!function_exists('array_format_key')) { } return $newArray; } - } if (!function_exists('auth')) { @@ -147,7 +150,6 @@ if (!function_exists('auth')) { $check = $authService->checkNode($node); return $check; } - } @@ -176,4 +178,4 @@ function json_message($data = [], $code = 0, $msg = '') 'msg' => $msg, 'data' => $data ]); -} \ No newline at end of file +}