SysController.php
7.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<?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 UserController
* @package app\admin\controller
* @adminMenuRoot(
* 'name' => '管理组',
* 'action' => 'default',
* 'parent' => 'user/AdminIndex/default',
* 'display'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '管理组'
* )
*/
class SysController extends AdminBaseController
{
public $table_name_tag = 'goods';
/***标签管理***/
//评论标签管理
public function train_type(){
$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['price'] = $data['price'];
$datain['des'] = $data['des'];
$datain['hetong'] = $data['hetong'];
$datain['create_time'] = time();
$result = DB::name($this->table_name_tag)->insert($datain);
if ($result) {
$this->success('添加成功!', url('train_type'));
}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['name'] = $data['name'];
$datain['price'] = $data['price'];
$datain['des'] = $data['des'];
$datain['hetong'] = $data['hetong'];
$datain['create_time'] = time();
$result = DB::name($this->table_name_tag)->update($datain);
if ($result) {
$this->success('修改成功!', url('train_type'));
}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 ban()
{
$id = $this->request->param('id', 0, 'intval');
if (!empty($id)) {
$result = Db::name('goods')->where(["id" => $id])->setField('status', '0');
if ($result !== false) {
$this->success("停用成功!");
} else {
$this->error('停用失败!');
}
} else {
$this->error('数据传入失败!');
}
}
/**
* 启用管理员
*/
public function cancelBan()
{
$id = $this->request->param('id', 0, 'intval');
if (!empty($id)) {
$result = Db::name('goods')->where(["id" => $id])->setField('status', '1');
if ($result !== false) {
$this->success("启用成功!");
} else {
$this->error('启用失败!');
}
} else {
$this->error('数据传入失败!');
}
}
//列表页
public function data_list(){
//获取筛选参数
$param = $this->request->param();
//1
$keyword = empty($param['keyword']) ? '' : $param['keyword'];
if (!empty($keyword)) {
$where['name'] = ['like', "%$keyword%"];
}
//2
$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 data_edit(){
$param = $this->request->param();
//提交数据
if($this->request->isPost()){
//添加提交
$datain['name'] = $param['name'];
$datain['price'] = $param['price'];
$datain['des'] = $param['des'];
$datain['hetong'] = $param['hetong'];
$datain['create_time'] = time();
$result = DB::name($this->table_name_tag)->insert($datain);
if ($result) {
$this->success('添加成功!', url('data_list'));
}else{
$this->error('添加失败!');
}
//提交修改
if($param['id']){
$datain['id'] = $param['id'];
$result = DB::name($this->table_name_tag)->update($datain);
if ($result) {
$this->success('修改成功!', url('data_list'));
}else{
$this->error('添加失败!');
}
}
}else{
//展示表单
if($param['id']){
$info = DB::name($this->table_name_tag)->where(['id'=>$param['id']])->find();
$this->assign('info', $info);
}
return $this->fetch();
}
}
//列表状态修改
public function data_satus(){
$param = $this->request->param();
$id = $param['id'];
$type = $param['type'];
if($type == 'ban'){
$field = 'status';
$field_value = '0';
$field_msg = '停用';
}elseif($type == 'cancelban'){
$field = 'status';
$field_value = '1';
$field_msg = '启用';
}elseif($type == 'sel'){
$field = 'delete_time';
$field_value = time();
$field_msg = '删除';
}
$result = Db::name('goods')->where(["id" => $id])->setField($field, $field_value);
if ($result != false) {
$this->success("{$field_msg}成功!");
} else {
$this->error("{$field_msg}失败!");
}
}
}