From 61b9a07d99a9aee0e00067866bcc671e852df5ea Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Tue, 8 Sep 2020 16:25:36 +0800 Subject: [PATCH] =?UTF-8?q?update:=E6=96=B0=E5=A2=9E=E8=A7=92=E8=89=B2?= =?UTF-8?q?=E6=A0=87=E8=AF=86=E5=94=AF=E4=B8=80=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- catch/permissions/controller/Role.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/catch/permissions/controller/Role.php b/catch/permissions/controller/Role.php index 5c3e3e0..1e52c28 100644 --- a/catch/permissions/controller/Role.php +++ b/catch/permissions/controller/Role.php @@ -2,6 +2,7 @@ namespace catchAdmin\permissions\controller; use catchAdmin\permissions\model\Permissions; +use catchAdmin\permissions\model\Roles; use catcher\base\CatchRequest as Request; use catcher\base\CatchController; use catcher\CatchResponse; @@ -38,14 +39,19 @@ class Role extends CatchController */ public function save(Request $request) { - $this->role->storeBy($request->param()); + $params = $request->param(); - $permissions = $request->param('permissions'); + if (Roles::where('identify', $params['identify'])->find()) { + throw new FailedException('角色标识 [' . $params['identify'] . ']已存在'); + } + + $this->role->storeBy($params); + $permissions = $params['permissions']; if (!empty($permissions)) { $this->role->attachPermissions(array_unique($permissions)); } - if (!empty($request->param('departments'))) { - $this->role->attachDepartments($request->param('departments')); + if (!empty($params['permissions'])) { + $this->role->attachDepartments($params['permissions']); } // 添加角色 return CatchResponse::success(); @@ -69,6 +75,10 @@ class Role extends CatchController */ public function update($id, Request $request): Json { + if (Roles::where('identify', $request->param('identify'))->where('id', '<>', $id)->find()) { + throw new FailedException('角色标识 [' . $request->param('identify') . ']已存在'); + } + $this->role->updateBy($id, $request->param()); $role = $this->role->findBy($id);