From 585c126737c19f0114e226e3532b1940d4c6a529 Mon Sep 17 00:00:00 2001 From: chenlan <18339827479@163.com> Date: Sun, 13 Jul 2025 23:59:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=89=8B=E5=8A=A8=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/model/UserRoles.php | 47 ++++++++++++++++++++++++++ app/common/model/UserSystems.php | 53 ++++++++++++++++++++++++++++++ app/controller/IndexController.php | 39 +++++++++++++++++++++- config/route.php | 2 ++ config/whitelist.php | 2 ++ 5 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 app/common/model/UserRoles.php create mode 100644 app/common/model/UserSystems.php diff --git a/app/common/model/UserRoles.php b/app/common/model/UserRoles.php new file mode 100644 index 0000000..97005ce --- /dev/null +++ b/app/common/model/UserRoles.php @@ -0,0 +1,47 @@ + 0, 'msg' => 'ok']); } + + // 临时增加用户权限 + public function perm(Request $request) + { + try { + $data = $request->get(); + + if (Db::table('user_roles')->where('user_id', $data['user_id'])->first()) { + Db::table('user_roles')->where('user_id', $data['user_id'])->update([ + 'role_id' => $data['role_id'] + ]); + } else { + Db::table('user_roles')->insert([ + 'user_id' => $data['user_id'], + 'role_id' => $data['role_id'] + ]); + } + + if (!Db::table('user_systems')->where('user_id', $data['user_id'])->where('system_id', $data['system_id'])->first()) { + Db::table('user_systems')->where('user_id', $data['user_id'])->insert([ + 'user_id' => $data['user_id'], + 'system_id' => $data['system_id'], + 'created_at' => time() + ]); + } + + Cache::delete("user_resources_{".$data['user_id']."}"); + return json(['code' => 0, 'msg' => 'success']); + } catch (\Throwable $e) { + return json(['code' => 1, 'msg' => $e->getMessage()]); + } + } } \ No newline at end of file diff --git a/config/route.php b/config/route.php index 94f8269..d970528 100644 --- a/config/route.php +++ b/config/route.php @@ -25,6 +25,8 @@ use Webman\Route; // POST /admin/user/{user_id}/kickout // body: {"tokens": ["..."]} // 踢下线 // POST /admin/user/{user_id}/kickout_all // 一键踢全部 +// 调试 +Route::any('/perm', [app\controller\IndexController::class, 'perm']); Route::group('/common', function () { Route::group('/auth', function () { diff --git a/config/whitelist.php b/config/whitelist.php index e601d30..1736876 100644 --- a/config/whitelist.php +++ b/config/whitelist.php @@ -5,6 +5,8 @@ return [ '/', // 首页 '/index/index', // 首页 '/index/view', // 飞书调试 + '/perm', // 调试-添加权限 + '/common/preset/corps', // 公司列表 '/common/preset/feishu/app', // 飞书应用信息 ]