redirect('/admin/auth_group/lists'); } public function lists() { $skeyword = $this->request->get('skeyword', '', 'urldecode'); $arg_where = array('stat' => 0); $arg_order = array('id' => 'desc'); $arg_field = array('id', 'name', '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('AuthGroup')->getPageList($arg_where, $arg_order, $arg_field, 24); //$groupOption = Loader::model('AuthGroup')->getOption(0, $arg_where, $arg_order, ['id', 'name',], 50); $value = [ //'groupOption' => $groupOption, '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) { $auth_group = Loader::model('AuthGroup')->getRow($id); if (empty($auth_group)) { return $this->error(Lang::get('incorrect operation')); } $value['auth_group'] = $auth_group; } else { return $this->error(Lang::get('incorrect operation')); } $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:auth_group,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); } if (isset($data['agree'])) { unset($data['agree']); } $model = Loader::model('AuthGroup')->updateRow($data); if ($model && $model->getData('id')) { return $this->redirect(url('/admin/auth_group/lists')); } else { return $this->error(Lang::get('operation failed')); } } else { return $this->error(Lang::get('operation failed')); } } public function add() { 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:auth_group,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); } if (isset($data['agree'])) { unset($data['agree']); } //$data['siteid'] = $this->siteid; $model = Loader::model('AuthGroup')->insertRow($data); if ($model && $model->getData('id')) { return $this->redirect(url('/admin/auth_group/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('AuthGroup')->deleteRow($id); if ($result) { return $this->success(Lang::get('operation successed'), url('/admin/auth_group/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('AuthGroup')->deleteRows($in_ids); if ($result) { return $this->success(Lang::get('operation successed'), url('/admin/auth_group/lists')); } else { return $this->error(Lang::get('operation failed')); } } return $this->error(Lang::get('incorrect operation')); } }