CommentController.php
5.9 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;
use cmf\controller\AdminBaseController;
use think\Db;
use think\Validate;
class CommentController extends AdminBaseController
{
public $table_name = 'commente';
public $table_name1 = 'commente1';
public $table_name_tag = 'commente_tag';
/***标签管理***/
//评论标签管理
public function tag(){
$param = $this->request->param();
$keyword = empty($param['keyword']) ? '' : $param['keyword'];
if (!empty($keyword)) {
$where['name'] = ['like', "%$keyword%"];
}
$type = empty($param['type']) ? '' : $param['type'];
if (!empty($type)) {
$where['type'] = ['eq', $type];
}
$where['delete_time']=0;
$list = DB::name($this->table_name_tag)->where($where)->select()->toArray();
$this->assign('list', $list);
return $this->fetch();
}
//添加评论标签管理
public function tag_add(){
return $this->fetch();
}
public function tag_add_do(){
$data = $this->request->param();
$validate = new Validate([
'name' => 'require',
]);
if (!$validate->check($data)) {
$this->error('名字不能为空!');
}else{
$datain['name'] = $data['name'];
$datain['type'] = $data['type'];
$datain['create_time'] = time();
$result = DB::name($this->table_name_tag)->insert($datain);
if ($result) {
$this->success('添加成功!', url('tag'));
}else{
$this->error('添加失败!');
}
}
}
//修改评论标签管理
public function tag_edit(){
$id = $this->request->param('id', 0, 'intval');
if ($id > 0) {
$info = DB::name($this->table_name_tag)->where(['id'=>$id])->find();
$this->assign('info', $info);
return $this->fetch();
} else {
$this->error('操作错误!');
}
return $this->fetch();
}
public function tag_edit_do(){
$data = $this->request->param();
$validate = new Validate([
'name' => 'require',
]);
if (!$validate->check($data)) {
$this->error('名字不能为空!');
}else{
$datain['id'] = $data['id'];
$datain['type'] = $data['type'];
$datain['name'] = $data['name'];
$datain['create_time'] = time();
$result = DB::name($this->table_name_tag)->update($datain);
if ($result) {
$this->success('保存成功!', url('tag'));
}else{
$this->error('保存失败!');
}
}
}
//删
public function tag_delete()
{
$id = $this->request->param('id');
$datain['id'] = $id;
$datain['delete_time'] = time();
$result = DB::name($this->table_name_tag)->update($datain);
if ($result) {
$this->success('删除成功!');
} else {
$this->error('删除失败');
}
}
/***标签管理结束***/
//教练评价
public function trainer(){
$param = $this->request->param();
$name = empty($param['name']) ? '' : $param['name'];
if (!empty($name)) {
$where['u.user_nickname'] = $name;
}
$mobile = empty($param['mobile']) ? '' : $param['mobile'];
if (!empty($mobile)) {
$where['mobile'] = $mobile;
}
$where['c.delete_time'] = 0;
$list = DB::name($this->table_name)
->alias('c')
->join('qnb_user u','u.id=c.teach_id')
->field('c.*')
->where($where)
->paginate(15);
$this->assign("list", $list->items());
$this->assign('page', $list->render());
return $this->fetch();
}
public function del_trainer(){
$id = $this->request->param('id');
if(!$id){
$this->error('删除失败');
}
$result = DB::name($this->table_name)->where(['id'=>$id])->delete();
if ($result) {
$this->success('删除成功!');
} else {
$this->error('删除失败');
}
}
//学生评价
public function student(){
$param = $this->request->param();
$name = empty($param['name']) ? '' : $param['name'];
if (!empty($keyword)) {
$where['u.nick_nickname'] = $name;
}
$mobile = empty($param['mobile']) ? '' : $param['mobile'];
if (!empty($mobile)) {
$where['mobile'] = $mobile;
}
$list = DB::name($this->table_name1)
->alias('c')
->join('qnb_user u','u.id=c.uid')
->field('c.*')
->where(['c.delete_time'=>0])
->paginate(15);
$this->assign("list", $list->items());
$this->assign('page', $list->render());
return $this->fetch();
}
public function del_student(){
$id = $this->request->param('id');
if(!$id){
$this->error('删除失败');
}
$result = DB::name($this->table_name1)->where(['id'=>$id])->delete();
if ($result) {
$this->success('删除成功!');
} else {
$this->error('删除失败');
}
}
}