48 lines
911 B
PHP
48 lines
911 B
PHP
|
<?php
|
||
|
declare (strict_types=1);
|
||
|
|
||
|
namespace app\util;
|
||
|
|
||
|
use think\facade\Request;
|
||
|
|
||
|
/**
|
||
|
* @author canny
|
||
|
* @date 2023/12/5 11:18
|
||
|
**/
|
||
|
class SessionUtil
|
||
|
{
|
||
|
const ADMIN_TOKEN_KEY = "token";
|
||
|
private static int $siteId = 1;
|
||
|
private static object $user;
|
||
|
|
||
|
public static function setUser($user)
|
||
|
{
|
||
|
self::$user = $user;
|
||
|
}
|
||
|
|
||
|
public static function getSiteId(): int
|
||
|
{
|
||
|
return self::$siteId;
|
||
|
}
|
||
|
|
||
|
public static function getUser(): object
|
||
|
{
|
||
|
return !empty(self::$user) ? self::$user : json_decode("");
|
||
|
}
|
||
|
|
||
|
public static function getUserId(): int
|
||
|
{
|
||
|
return (int)self::$user->id;
|
||
|
}
|
||
|
|
||
|
|
||
|
public static function getToken()
|
||
|
{
|
||
|
return Request::cookie(self::ADMIN_TOKEN_KEY, Request::header(self::ADMIN_TOKEN_KEY));
|
||
|
}
|
||
|
|
||
|
public static function isSuperAdmin(): bool
|
||
|
{
|
||
|
return !empty(self::getUser()->super_admin);
|
||
|
}
|
||
|
}
|