init
This commit is contained in:
211
app/admin/controller/Fq.php
Executable file
211
app/admin/controller/Fq.php
Executable file
@@ -0,0 +1,211 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Lang;
|
||||
use think\Loader;
|
||||
use think\Config;
|
||||
|
||||
class Fq extends BaseController {
|
||||
|
||||
public function index() {
|
||||
$this->redirect('/admin/fq/lists');
|
||||
}
|
||||
|
||||
public function lists() {
|
||||
$skeyword = $this->request->get('skeyword', '', 'urldecode');
|
||||
if (!empty($skeyword)) {
|
||||
$skeyword = trim($skeyword);
|
||||
$arg_where['name'] = ['like', '%' . $skeyword . '%'];
|
||||
$search['skeyword'] = $skeyword;
|
||||
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
|
||||
} else {
|
||||
$search['skeyword'] = '';
|
||||
}
|
||||
$arg_where['stat'] = 0;
|
||||
$arg_where['country_code'] = $this->country_code;
|
||||
|
||||
$arg_order = ['sort' => 'asc', 'id' => 'desc'];
|
||||
$dataObject = model('fq')->getPageList($arg_where, $arg_order);
|
||||
$value = [
|
||||
'list' => $dataObject->isEmpty() ? null : $dataObject->items(),
|
||||
'page' => $dataObject->render(),
|
||||
'search' => $search,
|
||||
];
|
||||
$this->assign($value);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function add() {
|
||||
$value = [];
|
||||
$this->assign($value);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function create() {
|
||||
if ($this->request->isPost()) {
|
||||
$data = $this->request->post();
|
||||
// dump($data);die;
|
||||
if (empty($data) || !is_array($data)) {
|
||||
return $this->error(Lang::get('incorrect operation'));
|
||||
}
|
||||
//验证规则
|
||||
$validaterule = [
|
||||
'name' => 'require',
|
||||
'content' => 'require',
|
||||
'picture' => 'require',
|
||||
];
|
||||
//验证提示信息
|
||||
$validatemsg = [
|
||||
'name.require' => '名称需要填写',
|
||||
'content.require' => '内容需要填写',
|
||||
'picture.require' => '图片需要填写',
|
||||
];
|
||||
$valid_result = $this->validate($data, $validaterule, $validatemsg);
|
||||
if (true !== $valid_result) {
|
||||
// 验证失败 输出错误信息
|
||||
return $this->error($valid_result);
|
||||
}
|
||||
$data['country_code'] = $this->country_code;
|
||||
|
||||
$insert_data = [
|
||||
'name' => $data['name'],
|
||||
'content' => $data['content'],
|
||||
'picture' => $data['picture'],
|
||||
'sort' => $data['sort'],
|
||||
'is_home' => $data['is_home'],
|
||||
'create_time' => time(),
|
||||
'country_code' => $data['country_code'],
|
||||
];
|
||||
|
||||
$model = model('fq')->insertRow($insert_data);
|
||||
if ($model && $model->getData('id')) {
|
||||
return $this->redirect(url('/admin/fq/lists'));
|
||||
} else {
|
||||
return $this->error(Lang::get('operation failed'));
|
||||
}
|
||||
}
|
||||
return $this->error(Lang::get('incorrect operation'));
|
||||
}
|
||||
|
||||
public function edit($id = 0) {
|
||||
$id = intval($id);
|
||||
if ($id > 0) {
|
||||
$fq = model('fq')->getRow($id);
|
||||
if (empty($fq)) {
|
||||
return $this->error(Lang::get('incorrect operation'));
|
||||
}
|
||||
$value['fq'] = $fq;
|
||||
} else {
|
||||
return $this->error(Lang::get('incorrect operation'));
|
||||
}
|
||||
// tiaoshi($fq);die;
|
||||
$value['id'] = $id;
|
||||
$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 = [
|
||||
'id' => 'require',
|
||||
'name' => 'require',
|
||||
'content' => 'require',
|
||||
'picture' => 'require',
|
||||
];
|
||||
//验证提示信息
|
||||
$validatemsg = [
|
||||
'id.require' => 'id需要填写',
|
||||
'name.require' => '名称需要填写',
|
||||
'content.require' => '内容需要填写',
|
||||
'picture.require' => '图片需要填写',
|
||||
];
|
||||
$valid_result = $this->validate($data, $validaterule, $validatemsg);
|
||||
if (true !== $valid_result) {
|
||||
// 验证失败 输出错误信息
|
||||
return $this->error($valid_result);
|
||||
}
|
||||
|
||||
$update_data = [
|
||||
'id' => $data['id'],
|
||||
'name' => $data['name'],
|
||||
'content' => $data['content'],
|
||||
'picture' => $data['picture'],
|
||||
'sort' => $data['sort'],
|
||||
'is_home' => $data['is_home'],
|
||||
];
|
||||
|
||||
$model = model('fq')->updateRow($update_data);
|
||||
if ($model && $model->getData('id')) {
|
||||
return $this->redirect(url('/admin/fq/lists'));
|
||||
} else {
|
||||
return $this->error(Lang::get('operation failed'));
|
||||
}
|
||||
} else {
|
||||
return $this->error(Lang::get('incorrect operation'));
|
||||
}
|
||||
}
|
||||
|
||||
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 < 20000) {
|
||||
$model = model('fq')->updateRow(['id' => $id, 'sort' => $sort]);
|
||||
if ($model && $model->getData('id')) {
|
||||
return $this->success(Lang::get('operation successed'), url('/admin/fq/lists'));
|
||||
} else {
|
||||
return $this->error(Lang::get('operation failed'));
|
||||
}
|
||||
}
|
||||
return $this->error(Lang::get('incorrect operation'));
|
||||
}
|
||||
public function updatestate() {
|
||||
$id = $this->request->param('id', 0);
|
||||
$isHome = $this->request->param('flag', 0);
|
||||
$id = intval($id);
|
||||
if ($id > 0) {
|
||||
$model = model('fq')->updateRow(['id' => $id, 'is_home' => $isHome]);
|
||||
|
||||
if ($model && $model->getData('id')) {
|
||||
return $this->success(Lang::get('operation successed'), url('/admin/fq/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 = model('fq')->deleteRow($id);
|
||||
if ($result) {
|
||||
return $this->success(Lang::get('operation successed'), url('/admin/question/lists'));
|
||||
} else {
|
||||
return $this->error(Lang::get('operation failed'));
|
||||
}
|
||||
}
|
||||
return $this->error(Lang::get('incorrect operation'));
|
||||
}
|
||||
|
||||
public function deletes() {
|
||||
$ids = $this->request->post('ids');
|
||||
if ($this->request->isPost() && $ids) {
|
||||
$result = model('fq')->deleteRows($ids);
|
||||
if ($result) {
|
||||
return $this->success(Lang::get('operation successed'), url('/admin/question/lists'));
|
||||
} else {
|
||||
return $this->error(Lang::get('operation failed'));
|
||||
}
|
||||
}
|
||||
return $this->error(Lang::get('incorrect operation'));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user