From c451d5b0eb82f66d461712b76cbbe7f181b6a88b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=B3=E6=B8=85=E7=88=BD?= Date: Wed, 9 Apr 2025 18:13:46 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B6=85=E7=AE=A1=E5=90=8E=E5=8F=B0=20-=20?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=91=98=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/superadmin/config/route.php | 11 +- .../superadmin/controller/Administrator.php | 147 ++++++++++++++++++ 2 files changed, 155 insertions(+), 3 deletions(-) create mode 100644 Server/application/superadmin/controller/Administrator.php diff --git a/Server/application/superadmin/config/route.php b/Server/application/superadmin/config/route.php index dfec2b8d..4a086ac1 100644 --- a/Server/application/superadmin/config/route.php +++ b/Server/application/superadmin/config/route.php @@ -8,7 +8,12 @@ Route::post('auth/login', 'app\\superadmin\\controller\\Auth@login'); Route::group('menu', function () { Route::get('tree', 'app\\superadmin\\controller\\Menu@getMenuTree'); Route::get('list', 'app\\superadmin\\controller\\Menu@getMenuList'); - Route::post('save', 'app\\superadmin\\controller\\Menu@saveMenu'); - Route::delete('delete/:id', 'app\\superadmin\\controller\\Menu@deleteMenu'); - Route::post('status', 'app\\superadmin\\controller\\Menu@updateStatus'); +}); + +// 管理员相关路由 +Route::group('administrator', function () { + // 获取管理员列表 + Route::get('list', 'app\\superadmin\\controller\\Administrator@getList'); + // 获取管理员详情 + Route::get('detail/:id', 'app\\superadmin\\controller\\Administrator@getDetail'); }); \ No newline at end of file diff --git a/Server/application/superadmin/controller/Administrator.php b/Server/application/superadmin/controller/Administrator.php new file mode 100644 index 00000000..1509e487 --- /dev/null +++ b/Server/application/superadmin/controller/Administrator.php @@ -0,0 +1,147 @@ +request->param('page/d', 1); + $limit = $this->request->param('limit/d', 10); + $keyword = $this->request->param('keyword/s', ''); + + // 构建查询条件 + $where = [ + ['deleteTime', '=', 0] + ]; + + // 如果有搜索关键词 + if (!empty($keyword)) { + $where[] = ['account|name', 'like', "%{$keyword}%"]; + } + + // 查询管理员数据 + $total = AdminModel::where($where)->count(); + $list = AdminModel::where($where) + ->field('id, account, name, status, authId, createTime, lastLoginTime, lastLoginIp') + ->order('id', 'desc') + ->page($page, $limit) + ->select(); + + // 格式化数据 + $data = []; + foreach ($list as $item) { + $data[] = [ + 'id' => $item->id, + 'username' => $item->account, + 'name' => $item->name, + 'role' => $this->getRoleName($item->authId), + 'status' => $item->status, + 'createdAt' => $item->createTime, + 'lastLogin' => !empty($item->lastLoginTime) ? date('Y-m-d H:i', $item->lastLoginTime) : '从未登录', + 'permissions' => $this->getPermissions($item->authId) + ]; + } + + return json([ + 'code' => 200, + 'msg' => '获取成功', + 'data' => [ + 'list' => $data, + 'total' => $total, + 'page' => $page, + 'limit' => $limit + ] + ]); + } + + /** + * 获取详细信息 + * @param int $id 管理员ID + * @return \think\response\Json + */ + public function getDetail($id) + { + // 查询管理员信息 + $admin = AdminModel::where('id', $id) + ->where('deleteTime', 0) + ->field('id, account, name, status, authId, createTime, lastLoginTime') + ->find(); + + // 如果查不到记录 + if (!$admin) { + return json([ + 'code' => 404, + 'msg' => '管理员不存在', + 'data' => null + ]); + } + + // 格式化数据 + $data = [ + 'id' => $admin->id, + 'username' => $admin->account, + 'name' => $admin->name, + 'status' => $admin->status, + 'authId' => $admin->authId, + 'roleName' => $this->getRoleName($admin->authId), + 'createdAt' => date('Y-m-d', $admin->createTime), + 'lastLogin' => !empty($admin->lastLoginTime) ? date('Y-m-d H:i', $admin->lastLoginTime) : '从未登录', + 'permissions' => $this->getPermissions($admin->authId) + ]; + + return json([ + 'code' => 200, + 'msg' => '获取成功', + 'data' => $data + ]); + } + + /** + * 根据权限ID获取角色名称 + * @param int $authId 权限ID + * @return string + */ + private function getRoleName($authId) + { + // 可以从权限表中查询,这里为演示简化处理 + switch($authId) { + case 1: + return '超级管理员'; + case 2: + return '项目管理员'; + case 3: + return '客户管理员'; + default: + return '普通管理员'; + } + } + + /** + * 根据权限ID获取权限列表 + * @param int $authId 权限ID + * @return array + */ + private function getPermissions($authId) + { + // 可以从权限表中查询,这里为演示简化处理 + $permissions = [ + 1 => ['项目管理', '客户池', '管理员权限', '系统设置'], // 超级管理员 + 2 => ['项目管理', '客户池'], // 项目管理员 + 3 => ['客户池'], // 客户管理员 + 4 => [] // 普通管理员 + ]; + + return isset($permissions[$authId]) ? $permissions[$authId] : []; + } +} \ No newline at end of file