This commit is contained in:
2024-10-29 14:04:59 +08:00
commit 48bf3e6f33
2839 changed files with 762707 additions and 0 deletions

View File

@@ -0,0 +1,312 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class Singlepage extends BaseController {
public function index() {
$this->redirect('/admin/singlepage/lists');
}
public function lists() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = array('pid' => 0, 'stat' => 0, 'siteid' => $this->siteid);
$arg_order = array('sort' => 'asc', 'id' => 'desc');
$arg_field = array('id', 'pid', 'name', 'sort', 'isshow', 'recommend', 'picture', 'content');
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['name'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$singlepage_list = Loader::model('Singlepage')->getSinglepageLists($arg_where, $arg_order, $arg_field, 50);
$value = ['list' => $singlepage_list, 'pid' => 0, 'search' => $search,];
$this->assign($value);
return $this->fetch();
}
public function listcategory($pid = 0) {
$pid = is_numeric($pid) ? intval($pid) : 0;
$arg_where = array('pid' => $pid, 'stat' => 0, 'siteid' => $this->siteid);
$arg_order = array('sort' => 'asc', 'id' => 'desc');
$arg_field = array('id', 'pid', 'name', 'sort', 'isshow', 'recommend', 'picture');
$singlepage_list = Loader::model('Singlepage')->getSinglepageList($arg_where, $arg_order, $arg_field, 24);
$singlepage_breadcrumb = Loader::model('Singlepage')->getBreadCrumb($pid);
$value = ['list' => $singlepage_list, 'pid' => $pid, 'breadcrumb' => $singlepage_breadcrumb, 'level' => 0];
$this->assign($value);
return $this->fetch();
}
public function childcat($pid = 0) {
$pid = $this->request->get('pid', 0);
$level = $this->request->get('level', 1);
//$pid = is_numeric($pid) ? intval($pid) : 0;
$arg_where = array('pid' => $pid, 'stat' => 0, 'siteid' => $this->siteid);
$arg_order = array('sort' => 'asc', 'id' => 'desc');
$arg_field = array('id', 'pid', 'name', 'sort', 'isshow', 'recommend', 'picture');
$singlepage_list = Loader::model('Singlepage')->getList($arg_where, $arg_order, $arg_field, 24);
$value = ['list' => $singlepage_list, 'pid' => $pid, 'level' => $level + 1];
$this->assign($value);
Config::set('default_ajax_return', 'html');
$this->view->engine(['type' => 'php', 'view_suffix' => 'html', 'tpl_replace_string' => [],]);
return $this->fetch();
}
public function add($pid = 0) {
$pid = is_numeric($pid) ? intval($pid) : 0;
$arg_where = array('pid' => 0, 'stat' => 0);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'name', 'sort');
$singlepageOptions = Loader::model('Singlepage')->getOptions($pid, $arg_where, $arg_order, $arg_field, 100);
$value = ['singlepageOptions' => $singlepageOptions, 'pid' => $pid];
$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 = ['name' => 'require', 'pid' => 'number|between:0,2147483647',];
$validatemsg = ['name.require' => '名称不能为空', 'pid.between' => '所属上级值无效',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$data['sort'] = intval($data['sort']);
$data['siteid'] = $this->siteid;
$model = Loader::model('Singlepage')->insertRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/singlepage/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function copy($id = 0) {
$id = intval($id);
if ($id > 0) {
$singlepage = Loader::model('Singlepage')->getRow($id);
if (empty($singlepage)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['singlepage'] = $singlepage;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$pid = isset($singlepage['pid']) ? $singlepage['pid'] : 0;
$arg_where = array('pid' => 0, 'stat' => 0);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'name', 'sort');
$singlepageOptions = Loader::model('Singlepage')->getOptions($pid, $arg_where, $arg_order, $arg_field, 100);
$value['singlepageOptions'] = $singlepageOptions;
$value['pid'] = $pid;
$this->assign($value);
return $this->fetch();
}
public function edit($id = 0) {
$id = intval($id);
if ($id > 0) {
$singlepage = Loader::model('Singlepage')->getRow($id);
if (empty($singlepage)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['singlepage'] = $singlepage;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$pid = isset($singlepage['pid']) ? $singlepage['pid'] : 0;
$arg_where = array('pid' => 0, 'stat' => 0);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'name', 'sort');
$singlepageOptions = Loader::model('Singlepage')->getOptions($pid, $arg_where, $arg_order, $arg_field, 100);
$value['singlepageOptions'] = $singlepageOptions;
$value['pid'] = $pid;
$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 = ['name' => 'require', 'pid' => 'number|between:0,2147483647',];
$validatemsg = ['name.require' => '名称不能为空', 'pid.between' => '所属上级值无效',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$data['sort'] = intval($data['sort']);
$childIDArray = Loader::model('Singlepage')->getChildIDArray($data['id']);
if (in_array($data['pid'], $childIDArray)) {
return $this->error('不可选择自己的子节点作为父节点');
}
$model = Loader::model('Singlepage')->updateRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/singlepage/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
} else {
return $this->error(Lang::get('operation failed'));
}
}
public function recycle() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = array('stat' => ['lt', 0], 'siteid' => $this->siteid);
$arg_order = array('sort' => 'asc', 'id' => 'desc');
$arg_field = array('id', 'pid', 'name', 'sort', 'isshow', 'recommend', 'picture');
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['name'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$singlepage_list = Loader::model('Singlepage')->getList($arg_where, $arg_order, $arg_field, 50);
$value = ['list' => $singlepage_list, 'pid' => 0, 'search' => $search,];
$this->assign($value);
return $this->fetch();
}
public function updatesort() {
$id = $this->request->param('id', 0);
$sort = $this->request->param('sort', 0);
$sort = intval($sort);
$id = intval($id);
if ($id > 0 && $sort < 2147483647) {
$model = Loader::model('Singlepage')->updateRow(['id' => $id, 'sort' => $sort]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/singlepage/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function toggleisshow() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = Loader::model('Singlepage')->updateRow(['id' => $id, 'isshow' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/singlepage/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function togglerecommend() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = Loader::model('Singlepage')->updateRow(['id' => $id, 'recommend' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/singlepage/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function recovery($id = 0) {
$id = intval($id);
if ($id > 0) {
$model = Loader::model('Singlepage')->updateRow(['id' => $id, 'stat' => 0]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/singlepage/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) {
$child = Loader::model('Singlepage')->getRow(['pid' => $id, 'stat' => 0], ['id', 'pid', 'name']);
if ($child) {
return $this->error('此节点包含子节点[ID:' . $child['id'] . '],不能进行删除');
}
$result = Loader::model('Singlepage')->deleteRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/singlepage/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function deletes() {
$ids = $this->request->post('ids');
$ids = explode(',', trim($ids, ','));
if ($this->request->isPost() && $ids) {
$singlepageModel = Loader::model('Singlepage');
foreach ($ids as $id) {
$child = $singlepageModel->getRow(['pid' => $id, 'stat' => 0], 'id');
if ($child) {
return $this->error(Lang::get('ID=' . $id . '的节点包含子节点,不能进行删除'));
}
}
$result = $singlepageModel->deleteRows($ids);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/singlepage/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function destroy($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = Loader::model('Singlepage')->destroyRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/singlepage/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function destroys() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = Loader::model('Singlepage')->destroyRows($ids);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/singlepage/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}