init
This commit is contained in:
287
app/admin/controller/Pinglun.php
Executable file
287
app/admin/controller/Pinglun.php
Executable file
@@ -0,0 +1,287 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Lang;
|
||||
use think\Loader;
|
||||
use think\Config;
|
||||
|
||||
class Pinglun extends BaseController {
|
||||
|
||||
public function index() {
|
||||
$this->redirect('/admin/pinglun/lists');
|
||||
}
|
||||
|
||||
public function lists() {
|
||||
$skeyword = $this->request->get('skeyword', '', 'urldecode');
|
||||
$arg_where = ['stat' => ['eq', 0]];
|
||||
$arg_order = ['id' => 'desc'];
|
||||
$arg_field = ['*'];
|
||||
if (!empty($skeyword)) {
|
||||
$skeyword = trim($skeyword);
|
||||
$arg_where['cname|content'] = ['like', '%' . $skeyword . '%'];
|
||||
$search['skeyword'] = $skeyword;
|
||||
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
|
||||
} else {
|
||||
$search['skeyword'] = '';
|
||||
}
|
||||
//$dataObject = Loader::model('Pinglun')->getPageList($arg_where, $arg_order, $arg_field, 12);
|
||||
$dataObject = model('pinglun')->getPageList($arg_where, $arg_order, $arg_field, 12);
|
||||
$value = [
|
||||
'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 add($pid = 0) {
|
||||
// if ($pid > 0) {
|
||||
// $pinglun = Loader::model('Pinglun')->getRow(['id' => $pid, 'stat' => ['gt', -1]]);
|
||||
// if (empty($pinglun)) {
|
||||
// return $this->error(Lang::get('incorrect operation'));
|
||||
// }
|
||||
// $value['pinglun'] = $pinglun;
|
||||
// }
|
||||
$value['pid'] = $pid;
|
||||
$this->assign($value);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function reply($id = 0) {
|
||||
if ($id > 0) {
|
||||
$pinglun = model('pinglun')->getRow(['id' => $id, 'stat' => ['gt', -1]]);
|
||||
if (empty($pinglun)) {
|
||||
return $this->error(Lang::get('incorrect operation'));
|
||||
}
|
||||
$value['pinglun'] = $pinglun;
|
||||
}
|
||||
$this->assign($value);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function addreply() {
|
||||
if ($this->request->isPost()) {
|
||||
$data = $this->request->post();
|
||||
if (empty($data) || !is_array($data)) {
|
||||
return $this->error(Lang::get('incorrect operation'));
|
||||
}
|
||||
$validaterule = [
|
||||
'content_id' => 'require',
|
||||
'typeid' => 'require',
|
||||
'content' => 'require',
|
||||
];
|
||||
$validatemsg = [
|
||||
'content_id.require' => '不能为空',
|
||||
'typeid.require' => '不能为空',
|
||||
'content.require' => '不能为空',
|
||||
];
|
||||
$valid_result = $this->validate($data, $validaterule, $validatemsg);
|
||||
if (true !== $valid_result) {
|
||||
// 验证失败 输出错误信息
|
||||
return $this->error($valid_result);
|
||||
}
|
||||
$addtime = date('Y-m-d H:i:s');
|
||||
$txarr = [1, 2, 3, 4, 5];
|
||||
shuffle($txarr);
|
||||
$set = [
|
||||
'customer_id' => 1,
|
||||
'cname' => isset($data['cname']) ? $data['cname'] : session('user_auth.username'),
|
||||
'typeid' => isset($data['typeid']) ? $data['typeid'] : 'Article',
|
||||
'pid' => isset($data['pid']) ? $data['pid'] : 0,
|
||||
'content_id' => isset($data['content_id']) ? $data['content_id'] : 0,
|
||||
'content' => $data['content'],
|
||||
'tx' => $txarr[0],
|
||||
'display' => $data['display'],
|
||||
'createtime' => $addtime,
|
||||
'lasttime' => $addtime,
|
||||
];
|
||||
$model = model('pinglun')->insertRow($set);
|
||||
if ($model && $model->getData('id')) {
|
||||
//(isset($set['content_id']) && isset($set['typeid'])) ? Loader::model($set['typeid'])->where(['id' => $set['content_id']])->setInc('commentcount') : '';
|
||||
return $this->success(Lang::get('operation successed'), url('/admin/pinglun/lists'));
|
||||
} else {
|
||||
return $this->error(Lang::get('operation failed'));
|
||||
}
|
||||
}
|
||||
return $this->error(Lang::get('incorrect operation'));
|
||||
}
|
||||
|
||||
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 = [
|
||||
'content_id' => 'require',
|
||||
'typeid' => 'require',
|
||||
'content' => 'require',
|
||||
];
|
||||
$validatemsg = [
|
||||
'content_id.require' => '不能为空',
|
||||
'typeid.require' => '不能为空',
|
||||
'content.require' => '不能为空',
|
||||
];
|
||||
$valid_result = $this->validate($data, $validaterule, $validatemsg);
|
||||
if (true !== $valid_result) {
|
||||
// 验证失败 输出错误信息
|
||||
return $this->error($valid_result);
|
||||
}
|
||||
$addtime = date('Y-m-d H:i:s');
|
||||
$txarr = [1, 2, 3, 4, 5];
|
||||
shuffle($txarr);
|
||||
$set = [
|
||||
'customer_id' => 1,
|
||||
'cname' => isset($data['cname']) ? $data['cname'] : session('user_auth.username'),
|
||||
'typeid' => isset($data['typeid']) ? $data['typeid'] : 'Article',
|
||||
'pid' => isset($data['pid']) ? $data['pid'] : 0,
|
||||
'content_id' => isset($data['content_id']) ? $data['content_id'] : 0,
|
||||
'content' => $data['content'],
|
||||
'tx' => $txarr[0],
|
||||
'display' => $data['display'],
|
||||
'createtime' => $addtime,
|
||||
'lasttime' => $addtime,
|
||||
];
|
||||
$model = model('pinglun')->insertRow($set);
|
||||
if ($model && $model->getData('id')) {
|
||||
(isset($set['content_id']) && isset($set['typeid'])) ? Loader::model($set['typeid'])->where(['id' => $set['content_id']])->setInc('commentcount') : '';
|
||||
return $this->success(Lang::get('operation successed'), url('/admin/pinglun/lists'));
|
||||
} 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) {
|
||||
$pinglun = model('pinglun')->getRow(['id' => $id, 'stat' => ['gt', -1]]);
|
||||
if (empty($pinglun)) {
|
||||
return $this->error(Lang::get('incorrect operation'));
|
||||
}
|
||||
$value['pinglun'] = $pinglun;
|
||||
}
|
||||
$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',
|
||||
'content' => 'require',
|
||||
];
|
||||
$validatemsg = [
|
||||
'id.require' => 'id不能为空',
|
||||
'content.require' => '不能为空',
|
||||
];
|
||||
$valid_result = $this->validate($data, $validaterule, $validatemsg);
|
||||
if (true !== $valid_result) {
|
||||
// 验证失败 输出错误信息
|
||||
return $this->error($valid_result);
|
||||
}
|
||||
$model = model('pinglun')->updateRow($data);
|
||||
if ($model && $model->getData('id')) {
|
||||
return $this->success(Lang::get('operation successed'), url('/admin/pinglun/lists'));
|
||||
} else {
|
||||
return $this->error(Lang::get('operation failed'));
|
||||
}
|
||||
}
|
||||
return $this->error(Lang::get('incorrect operation'));
|
||||
}
|
||||
|
||||
public function togglestat() {
|
||||
$id = $this->request->get('id', 0);
|
||||
$flag = $this->request->get('flag', 0);
|
||||
if ($this->request->isGet() && $id) {
|
||||
$model = model('pinglun')->updateRow(['id' => $id, 'stat' => $flag]);
|
||||
if ($model && $model->getData('id')) {
|
||||
return $this->success(Lang::get('operation successed'), url('/admin/pinglun/lists'));
|
||||
} else {
|
||||
return $this->error(Lang::get('operation failed'));
|
||||
}
|
||||
}
|
||||
return $this->error(Lang::get('incorrect operation'));
|
||||
}
|
||||
|
||||
public function toggleishot() {
|
||||
$id = $this->request->param('id', 0);
|
||||
$flag = $this->request->param('flag', 0);
|
||||
$id = intval($id);
|
||||
if ($id > 0) {
|
||||
$model = model('pinglun')->updateRow(['id' => $id, 'ishot' => $flag]);
|
||||
if ($model && $model->getData('id')) {
|
||||
return $this->success(Lang::get('operation successed'), url('/admin/pinglun/lists'));
|
||||
} else {
|
||||
return $this->error(Lang::get('operation failed'));
|
||||
}
|
||||
}
|
||||
return $this->error(Lang::get('incorrect operation'));
|
||||
}
|
||||
|
||||
public function checked() {
|
||||
$ids = $this->request->post('ids');
|
||||
if ($this->request->isPost() && $ids) {
|
||||
$result = model('pinglun')->updateRow(['display' => 1], ['id' => ['in', $ids]]);
|
||||
if ($result) {
|
||||
return $this->success(Lang::get('operation successed'), url('/admin/pinglun/lists'));
|
||||
} else {
|
||||
return $this->error(Lang::get('operation failed'));
|
||||
}
|
||||
}
|
||||
return $this->error(Lang::get('incorrect operation'));
|
||||
}
|
||||
|
||||
public function unchecked() {
|
||||
$ids = $this->request->post('ids');
|
||||
if ($this->request->isPost() && $ids) {
|
||||
$result = city(session('cit'),'Pinglun')->updateRow(['display' => 0], ['id' => ['in', $ids]]);
|
||||
if ($result) {
|
||||
return $this->success(Lang::get('operation successed'), url('/admin/pinglun/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('pinglun')->deleteRow($id);
|
||||
if ($result) {
|
||||
return $this->success(Lang::get('operation successed'), url('/admin/pinglun/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) {
|
||||
$ids = explode(",", $ids);
|
||||
// $result = city(session('cit'),'Pinglun')->deleteRows($ids);
|
||||
$result = model('tbpl')->where('id', 'in', $ids)->update(['stat' => -1]);
|
||||
// echo \think\Db::table('tbpl')->getLastSql();die;
|
||||
// tiaoshi($result);die;
|
||||
if ($result) {
|
||||
return $this->success(Lang::get('operation successed'), url('/admin/pinglun/lists'));
|
||||
} else {
|
||||
return $this->error(Lang::get('operation failed'));
|
||||
}
|
||||
}
|
||||
return $this->error(Lang::get('incorrect operation'));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user