AdminIndexController.php
2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
// +----------------------------------------------------------------------
// | TcComment [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017 Tangchao All rights reserved.
// +----------------------------------------------------------------------
// | Author: Tangchao <79300975@qq.com>
// +----------------------------------------------------------------------
namespace plugins\tc_comment\controller;
use think\Db;
use cmf\controller\PluginBaseController;
class AdminIndexController extends PluginBaseController
{
function _initialize()
{
$adminId = cmf_get_current_admin_id();
if (!empty($adminId)) {
$this->assign("admin_id", $adminId);
} else {
$this->error('未登录');
}
}
function index()
{
$where = [];
$where['delete_time'] = 0;
$comments = Db::name('comment')
->where($where)
->order("id DESC")
->paginate(10);
$page = $comments->render();
$this->assign("page", $page);
$this->assign("comments", $comments);
return $this->fetch('/admin_index');
}
public function delete()
{
$id = $this->request->param("id", 0, "intval");
$userQuery = Db::name("Comment");
$where['id'] = $id;
$data['delete_time'] = time();
$userQuery->where($where)->update($data);
if ($data) {
Db::name('portal_post')->where('id', $id)->setDec('comment_count');
$this->success("删除成功!");
} else {
$this->error("删除失败!");
}
}
public function cancelBan()
{
$id = input('param.id', 0, 'intval');
if ($id) {
$result = Db::name("Comment")->where(["id" => $id, "status" => 0])->setField('status', 1);
if ($result) {
Db::name('portal_post')->where('id', $id)->setInc('comment_count');
$this->success("评论审核成功!", '');
}else {
$this->error('评论切换失败,评论不存在!');
}
} else {
$this->error('数据传入失败!');
}
}
public function ban()
{
$id = input('param.id', 0, 'intval');
if ($id) {
$result = Db::name("Comment")->where(["id" => $id, "status" => 1])->setField('status', 0);
if ($result) {
Db::name('portal_post')->where('id', $id)->setDec('comment_count');
$this->success("评论已切换成未审核!", '');
} else {
$this->error('评论切换失败,评论不存在!');
}
} else {
$this->error('数据传入失败!');
}
}
}