redirect('/admin/sysconfig/lists'); } public function lists($group = 0) { $skeyword = $this->request->get('skeyword', '', 'urldecode'); $arg_where = array('stat' => 0); $arg_order = array('id' => 'desc', 'group' => 'asc', 'sort' => 'asc',); $arg_field = array('id', 'name', 'group', 'type', 'sort', 'title'); if (!empty($skeyword)) { $skeyword = trim($skeyword); $arg_where['name|title'] = ['like', '%' . $skeyword . '%']; $search['skeyword'] = $skeyword; Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数 } else { $search['skeyword'] = ''; } $dataObject = model('sysconfig')->getPageList($arg_where, $arg_order, $arg_field, 15); $value = [ 'group_id' => (int) $group, '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, ]; $value['groupList'] = (array) Config::get('config_group_list'); $value['typeList'] = (array) Config::get('config_type_list'); $this->assign($value); return $this->fetch(); } public function webconfig() { $sysconfigs = model('sysconfig')->getGroupLists(array('stat' => 0), array('group' => 'asc', 'sort' => 'asc', 'id' => 'asc'), null); foreach ($sysconfigs as $key => $val) { $configs[$val->group][] = $val->toArray(); } $value['configs'] = isset($configs) ? $configs : []; $value['groupList'] = (array) Config::get('config_group_list'); $value['typeList'] = (array) Config::get('config_type_list'); $this->assign($value); return $this->fetch(); } public function add() { $value['groupList'] = (array) Config::get('config_group_list'); $value['typeList'] = (array) Config::get('config_type_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')); } $validaterule = [ 'title' => 'require|max:30', 'agree' => 'require|accepted', 'name' => 'require|alphaDash|unique:sysconfig,name', ]; $validatemsg = [ 'title.require' => '标题不能为空', 'title.max' => '标题最多不能超过30个字符', 'agree.require' => '请勾选确认框', 'agree.accepted' => '请勾选确认框', 'name.require' => '配置名称不能为空', 'name.alphaDash' => '配置名称的值是否为字母数字下划线', 'name.unique' => '配置名称已经存在' ]; $valid_result = $this->validate($data, $validaterule, $validatemsg); if (true !== $valid_result) { // 验证失败 输出错误信息 return $this->error($valid_result); } if (isset($data['agree'])) { unset($data['agree']); } $model = model('sysconfig')->insertRow($data); if ($model && $model->getData('id')) { $this->cacheClear('sysconfig'); return $this->success(Lang::get('operation successed')); } else { return $this->error(Lang::get('operation failed')); } } return $this->error(Lang::get('incorrect operation')); } /** * 网站设置编辑 */ public function edit($id) { $id = intval($id); if ($id > 0) { $sysconfig = model('sysconfig')->getRow($id); if (empty($sysconfig)) { return $this->error(Lang::get('incorrect operation')); } $value['config'] = $sysconfig; } $value['groupList'] = (array) Config::get('config_group_list'); $value['typeList'] = (array) Config::get('config_type_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')); } $validaterule = [ 'title' => 'require|max:30', 'name' => 'require|alphaDash', 'agree' => 'require|accepted', 'id' => 'require', ]; $validatemsg = [ 'title.require' => '标题不能为空', 'title.max' => '标题最多不能超过30个字符', 'name.require' => '配置名称不能为空', 'name.alphaDash' => '配置名称的值是否为字母数字下划线', 'agree.require' => '请勾选确认框', 'agree.accepted' => '请勾选确认框', 'id.require' => '配置ID不能为空', ]; $valid_result = $this->validate($data, $validaterule, $validatemsg); if (true !== $valid_result) { // 验证失败 输出错误信息 return $this->error($valid_result); } if (isset($data['agree'])) { unset($data['agree']); } $model = model('sysconfig')->updateRow($data); if ($model && $model->getData('id')) { $this->cacheClear('sysconfig'); return $this->success(Lang::get('operation successed')); } else { return $this->error(Lang::get('operation failed')); } } return $this->error(Lang::get('incorrect operation')); } /** * 网站设置更新 */ public function updategrp() { if ($this->request->isPost()) { $data = $this->request->post(); if (empty($data) || !is_array($data)) { return $this->error(Lang::get('incorrect operation')); } $validaterule = [ 'config' => 'require|array', 'group' => 'require|number', 'agree' => 'require|accepted', ]; $validatemsg = [ 'config.require' => '配置不能为空', 'config.array' => '配置应是一个数组', 'group.require' => '配置组不能为空', 'group.number' => '配置组应为数字', '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']); } foreach ($data['config'] as $key => $value) { $object = model('sysconfig')->updateRow(['value' => $value], ['name' => $key, 'group' => $data['group']]); if (!$object) { break; } } $this->cacheClear('sysconfig'); if ($object !== false) { return $this->success(Lang::get('operation successed')); } 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 = model('sysconfig')->deleteRow($id); if ($result) { $this->cacheClear('sysconfig'); return $this->success(Lang::get('operation successed'), url('/admin/sysconfig/lists')); } else { return $this->error(Lang::get('operation failed')); } } return $this->error(Lang::get('incorrect operation')); } }