$v){ if (!empty($v['role_rules'])){ // $list[$k]['menus'] = $menus; $rules = explode(',',$v['role_rules']); $mation = SystemMenu::menusMation($rules); $name = []; for ($z=0;$zupdate($data); if ($result !== false){ Redis::del('roles_' . $role_id); SystemRole::affairCommit(); return true; } throw new \Exception('操作失败!'); }catch (\Exception $exception){ SystemRole::affairRollback(); throw new \Exception($exception->getMessage(), 500); } } /** * Notes:删除角色 * @param int $role_id * @return int * User: ZQ * Date: 2022/9/13 */ public static function delRole($role_id) { SystemRole::affairBegin(); try { $where = []; $where['role_id'] = $role_id; $data['role_status'] = 2; $result = SystemRole::where($where)->update($data); if (!empty($result)){ Redis::del('roles_' . $role_id); SystemRole::affairCommit(); return true; }else{ return false; } }catch (\Exception $exception){ SystemRole::affairRollback(); throw new \Exception($exception->getMessage(), 500); } } /** * Notes: 添加角色 * @param string $role_name * @param array $role_rules * @return int * User: ZQ * Date: 2022/9/13 */ public static function insertRole(string $role_name, $role_rules, $role_info, $role_is_show) { SystemRole::affairBegin(); try { $data = []; $data['role_name'] = $role_name; if (!empty($role_rules)){ $data['role_rules'] = implode(',',$role_rules); }else{ $data['role_rules'] = ''; } $data['role_is_show'] = $role_is_show; $data['role_info'] = $role_info; $result = SystemRole::insertGetId($data); if (!empty($result)){ SystemRole::affairCommit(); return $result; } throw new \Exception('操作失败!'); }catch (\Exception $exception){ SystemRole::affairRollback(); throw new \Exception($exception->getMessage(), 500); } } /** * Notes:查询角色 * @param int $role_id * @return int * User: ZQ * Date: 2022/9/13 */ public static function roleInfo($role_id) { $where = []; $where['role_id'] = $role_id; $result = SystemRole::where($where)->first(); if (!empty($result)){ $result['menu_is_menu'] = (string)$result['menu_is_menu']; if (!empty($result['role_rules'])){ $result['role_rules'] = explode(',',$result['role_rules']); }else{ $result['role_rules'] = []; } } return $result; } /** * Notes:修改角色 * @param string $role_name * @param int $role_is_show * @return int * User: ZQ * Date: 2022/9/15 */ public static function updateStatus($role_id, $role_is_show) { SystemRole::affairBegin(); try { $where = []; $where['role_id'] = $role_id; $data = []; $data['role_is_show'] = $role_is_show; $result = SystemRole::where($where)->update($data); if ($result !== false){ SystemRole::affairCommit(); return true; } throw new \Exception('操作失败!'); }catch (\Exception $exception){ SystemRole::affairRollback(); throw new \Exception($exception->getMessage(), 500); } } }