refactor: 重构用户信息状态代码写法。

This commit is contained in:
augushong
2025-04-14 19:58:41 +08:00
parent 651efc5814
commit 18ba49e1c5
5 changed files with 39 additions and 24 deletions

View File

@@ -12,6 +12,8 @@ use think\facade\Cache;
use think\facade\Env;
use think\facade\Event;
use think\facade\Filesystem;
use think\facade\Request;
use think\helper\Arr;
use think\response\View;
use think\route\Url;
@@ -175,13 +177,37 @@ if (!function_exists('auth')) {
*/
function auth($node = null)
{
$authService = new AuthService(session('admin.id'));
$authService = new AuthService(get_session_admin('id'));
$check = $authService->checkNode($node);
return $check;
}
}
function get_session_admin($key = null)
{
$token = read_header_token();
if (!empty($token)) {
$admin = Cache::get($token);
} else {
$admin = session('admin');
}
return Arr::get($admin, $key);
}
function read_header_token()
{
$header_authorization = Request::header('Authorization');
if (!empty($header_authorization)) {
$token = explode(' ', $header_authorization)[1];
return $token;
}
return null;
}
function json_message($data = [], $code = 0, $msg = '')
{
if (is_string($data)) {