From ac3ba908b2482068a577d1aa3662773dc7b34306 Mon Sep 17 00:00:00 2001 From: hnh0000 Date: Mon, 20 Dec 2021 20:25:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BF=AB=E6=8D=B7=E8=8E=B7=E5=8F=96=E5=89=8D?= =?UTF-8?q?=E5=8F=B0=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/library/Auth.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/application/common/library/Auth.php b/application/common/library/Auth.php index 91a7e5072..e6108d7ec 100644 --- a/application/common/library/Auth.php +++ b/application/common/library/Auth.php @@ -50,6 +50,28 @@ class Auth return self::$instance; } + /** + * 获取当前登录用户id,未登录返回null + * + * @return null + */ + public static function id() + { + $user = self::instance()->getUser(); + + return $user ? $user->id : null; + } + + /** + * 获取当前登录用户模型 + * + * @return User + */ + public static function user() + { + return self::instance()->getUser(); + } + /** * 获取User模型 * @return User -- Gitee