ForbiddenController.php
2.71 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
<?php
namespace backend\controllers;
use Yii;
use backend\components\Pagination;
use app\models\Forbidden;
/**
* Live controller
*/
class ForbiddenController extends BaseController
{
/**
* 禁言列表
* @return type
*/
public function actionIndex()
{
$model = Forbidden::find();
//$room_id = Yii::$app->request->get('room_id',0);
if ($filter = Yii::$app->request->get()) {
// var_dump($filter);
foreach ($filter as $field => $value) {
if ($field == 'keyword') {
if (!empty($value)) {
$model->andWhere(['like', 'title', "%{$value}%"])
->orWhere(['room_id' => $value])
->orWhere(['master_id' => $value]);
}
} else {
$model->andWhere([$field => $value]);
}
}
}
$count = clone $model;
$pagination = new Pagination(['totalCount' => $count->count()]);
$list = $model->offset($pagination->offset)->limit($pagination->limit)->orderBy(['create_time' => SORT_DESC])->all();
return $this->render('index', [
'filter' => $filter ?: [],
'pagination' => $pagination,
'list' => $list
]);
}
/**
* 新增禁言用户
* @return \yii\web\Response
*/
public function actionCreate()
{
$model = new Forbidden();
if ($posts = Yii::$app->request->post()) {
$model->room_id = $posts['room_id'];
$model->uid = $posts['uid'];
$model->name = $posts['name'];
$model->status = 1;
$model->create_time = time();
if (!$model->save()) {
// var_dump($model->errors);
Yii::$app->session->setFlash('error', '添加失败。');
} else {
Yii::$app->session->setFlash('success', '添加成功。');
}
return $this->redirect(['index', 'room_id' => $posts['room_id']]);
}
}
public function actionSetStatus()
{
$id = Yii::$app->request->get('id', 0);
if ($id) {
$status = Yii::$app->request->get('status', 0);
$model = Forbidden::findOne($id);
$model->status = $status;
if (!$model->save()) {
$ret = [
'code' => 400,
'msg' => '保存失败'
];
} else {
$ret = [
'code' => 200,
'msg' => '保存成功'
];
}
echo json_encode($ret);
exit;
}
}
}