From 72878f49eabec6e53e6ce15b41bd2dfa1eb92a31 Mon Sep 17 00:00:00 2001 From: mzl Date: Mon, 14 Jul 2025 10:08:29 +0800 Subject: [PATCH] Merge commit 'acd428f57bceb73ddc770cc6b59f8be7a237af90' --- app/common/model/Role.php | 2 +- app/common/model/User.php | 2 +- app/common/model/UserRoles.php | 47 ++++++++++++++++++++++++ app/common/model/UserSystems.php | 53 ++++++++++++++++++++++++++++ app/controller/IndexController.php | 39 +++++++++++++++++++- app/ticket/logic/TicketLogic.php | 4 +-- app/ticket/service/TicketService.php | 14 +++++++- config/route.php | 2 ++ config/whitelist.php | 2 ++ 9 files changed, 159 insertions(+), 6 deletions(-) create mode 100644 app/common/model/UserRoles.php create mode 100644 app/common/model/UserSystems.php diff --git a/app/common/model/Role.php b/app/common/model/Role.php index ea84200..c9eaabd 100644 --- a/app/common/model/Role.php +++ b/app/common/model/Role.php @@ -53,6 +53,6 @@ class Role extends Model // 角色拥有的资源(权限点、菜单) public function resources() { - return $this->belongsToMany(Resource::class, 'role_resources', 'role_id', 'resource_id'); + return $this->belongsToMany(Resource::class, 'role_resources', 'role_id', 'resource_id')->orderBy('sort', 'asc'); } } diff --git a/app/common/model/User.php b/app/common/model/User.php index 4709b44..e9b4627 100644 --- a/app/common/model/User.php +++ b/app/common/model/User.php @@ -75,7 +75,7 @@ class User extends Model // 用户直接拥有的资源(用于特殊补权) public function resources() { - return $this->belongsToMany(Resource::class, 'user_resources', 'user_id', 'resource_id'); + return $this->belongsToMany(Resource::class, 'user_resources', 'user_id', 'resource_id')->orderBy('sort', 'asc'); } // 用户可访问的系统 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/app/ticket/logic/TicketLogic.php b/app/ticket/logic/TicketLogic.php index e7d098d..540e7c5 100644 --- a/app/ticket/logic/TicketLogic.php +++ b/app/ticket/logic/TicketLogic.php @@ -26,8 +26,8 @@ class TicketLogic if(!empty($params['status'])){ $where[] = ['status', '=', $params['status']]; } - $size = $params['size']; - $current = $params['current']; + $size = $params['size']??10; + $current = $params['current']??1; return Ticket::with('attachments')->with('categorie')->with('categorie.translation')->where($where)->orderBy('id','desc')->paginate($size, ['*'], 'page', $current); } diff --git a/app/ticket/service/TicketService.php b/app/ticket/service/TicketService.php index f5a0d72..6250b5f 100644 --- a/app/ticket/service/TicketService.php +++ b/app/ticket/service/TicketService.php @@ -55,8 +55,20 @@ class TicketService { try { Db::beginTransaction(); - $attachment = $data['attachment']??[]; $logic = new TicketLogic(); + $result = $logic->find($data['id']); + + if(empty($result)){ + throw new BusinessException('工单不存在'); + } + if($result['user_id'] != $data['user_id']){ + throw new BusinessException('只能编辑自己的工单'); + } + if($result['status'] != 1){ + throw new BusinessException('只能修改待受理工单'); + } + + $attachment = $data['attachment']??[]; $result = $logic->edit($data); if(!empty($attachment)){ 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', // 飞书应用信息 ]