redirect('/admin/user_role/lists'); } public function lists() { $skeyword = $this->request->get('skeyword', '', 'urldecode'); $arg_where = array('stat' => 0, 'id' => ['neq', 1]); $arg_order = array('id' => 'desc'); $arg_field = array('id', 'name', 'rbac_acl', 'description', 'stat'); if (!empty($skeyword)) { $skeyword = trim($skeyword); $arg_where['name'] = ['like', '%' . $skeyword . '%']; $search['skeyword'] = $skeyword; Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数 } else { $search['skeyword'] = ''; } $dataObject = Loader::model('UserRole')->getPageList($arg_where, $arg_order, $arg_field, 24); //$roleOption = Loader::model('UserRole')->getOption(0, $arg_where, $arg_order, ['id', 'name',], 50); $value = [ //'roleOption' => $roleOption, 'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray() 'page' => $dataObject->render(), //'page_previous' => $dataObject->getUrl($dataObject->currentPage() - 1), //'page_next' => $dataObject->getUrl($dataObject->currentPage() + 1), 'search' => $search, ]; $this->assign($value); return $this->fetch(); } public function edit($id = 0) { $id = intval($id); if ($id > 0) { $user_role = Loader::model('UserRole')->getRow($id); if (empty($user_role)) { return $this->error(Lang::get('incorrect operation')); } $user_role['rbac_acl'] = explode(',', $user_role['rbac_acl']); $value['user_role'] = $user_role; } else { return $this->error(Lang::get('incorrect operation')); } $auth_group_list = Loader::model('AuthGroup')->getList(['stat' => 0], ['id' => 'asc'], ['id', 'name',]); $auth_access_list = Loader::model('AuthAccess')->getList(['stat' => 0], ['id' => 'asc'], ['id', 'name', 'gid',]); $access_list = []; foreach ($auth_access_list as $k => $val) { $access_list[$val['gid']][] = $val; } $value['access_list'] = $access_list; $value['group_list'] = $auth_group_list; $this->assign($value); return $this->fetch(); } public function update() { if ($this->request->isPost()) { $data = $this->request->post(); if (empty($data) || !is_array($data)) { return $this->error(Lang::get('incorrect operation')); } else { foreach ($data as $k => $v) { if (is_string($v)) { $data[$k] = trim($v); } } } $validaterule = ['name' => 'require|unique:user_role,name', 'description' => 'require', 'agree' => 'require|accepted',]; $validatemsg = ['name.require' => '名称不能为空', 'name.unique' => '名称已存在', 'description.require' => '描述不能为空', 'agree.require' => '请勾选确认框', 'agree.accepted' => '请勾选确认框',]; $valid_result = $this->validate($data, $validaterule, $validatemsg); if (true !== $valid_result) { // 验证失败 输出错误信息 return $this->error($valid_result); } $role_row['rbac_acl'] = is_array($data['acl']) ? implode(',', $data['acl']) : ''; if (empty($role_row['rbac_acl'])) { return $this->error("请选择权限!"); } $role_row['id'] = $data['id']; $role_row['name'] = $data['name']; $role_row['description'] = $data['description']; $role_row['yesorno'] = $data['yesorno']; $model = Loader::model('UserRole')->updateRow($role_row); if ($model && $model->getData('id')) { return $this->redirect(url('/admin/user_role/lists')); } else { return $this->error(Lang::get('operation failed')); } } return $this->error(Lang::get('incorrect operation')); } public function add() { $auth_group_list = Loader::model('AuthGroup')->getList(['stat' => 0], ['id' => 'asc'], ['id', 'name',], 24); $auth_access_list = Loader::model('AuthAccess')->getList(['stat' => 0], ['id' => 'asc'], ['id', 'name', 'gid',], 24); $access_list = []; foreach ($auth_access_list as $k => $val) { $access_list[$val['gid']][] = $val; } $value['access_list'] = $access_list; $value['group_list'] = $auth_group_list; $this->assign($value); return $this->fetch(); } public function create() { if ($this->request->isPost()) { $data = $this->request->post(); if (empty($data) || !is_array($data)) { return $this->error(Lang::get('incorrect operation')); } else { foreach ($data as $k => $v) { if (is_string($v)) { $data[$k] = trim($v); } } } $validaterule = ['name' => 'require|unique:user_role,name', 'description' => 'require', 'agree' => 'require|accepted',]; $validatemsg = ['name.require' => '名称不能为空', 'name.unique' => '名称已存在', 'description.require' => '描述不能为空', 'agree.require' => '请勾选确认框', 'agree.accepted' => '请勾选确认框',]; $valid_result = $this->validate($data, $validaterule, $validatemsg); if (true !== $valid_result) { // 验证失败 输出错误信息 return $this->error($valid_result); } $role_row['rbac_acl'] = is_array($data['acl']) ? implode(',', $data['acl']) : ''; if (empty($role_row['rbac_acl'])) { return $this->error("请选择权限!"); } $role_row['name'] = $data['name']; $role_row['description'] = $data['description']; $role_row['yesorno'] = $data['yesorno']; $model = Loader::model('UserRole')->insertRow($role_row); if ($model && $model->getData('id')) { return $this->redirect(url('/admin/user_role/lists')); } else { return $this->error(Lang::get('operation failed')); } } return $this->error(Lang::get('incorrect operation')); } public function delete($id = 0) { $id = intval($id); if ($id > 0) { $result = Loader::model('UserRole')->deleteRow($id); if ($result) { return $this->success(Lang::get('operation successed'), url('/admin/user_role/lists')); } else { return $this->error(Lang::get('operation failed')); } } return $this->error(Lang::get('incorrect operation')); } public function deletes() { $ids = $this->request->post('ids'); $in_ids = explode(',', trim($ids, ',')); if ($this->request->isPost() && $in_ids) { $result = Loader::model('UserRole')->deleteRows($in_ids); if ($result) { return $this->success(Lang::get('operation successed'), url('/admin/user_role/lists')); } else { return $this->error(Lang::get('operation failed')); } } return $this->error(Lang::get('incorrect operation')); } }