LiveController.php
3.06 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
<?php
namespace backend\controllers;
use Yii;
use app\models\Master;
use yii\data\Pagination;
/**
* Live controller
*/
class LiveController extends BaseController
{
/**
* 直播间
* @return type
*/
public function actionRoom()
{
return $this->render('room');
}
/**
* 主播
* @return type
*/
public function actionMaster()
{
$query = Master::find();
$conditions = Yii::$app->request->get();
if(array_filter($conditions)){
$sql ="name like '%".$conditions['name']."%'";
}else{
$sql = "";
}
$pagination = new Pagination([
'defaultPageSize' => 15,
'totalCount' => $query->count(),
]);
$masters = $query->where($sql)
->orderBy('create_time')
->offset($pagination->offset)
->limit($pagination->limit)
->all();
return $this->render('master',[
'list'=>$masters,
'condition'=>$conditions
]);
}
/**
* 视频
* @return type
*/
public function actionVideo()
{
return $this->render('video');
}
/**
* 添加主播
* @return type
*/
public function actionAddmaster()
{
$model = new Master();
if ($posts = Yii::$app->request->post()) {
$model->name = $posts['name'];
$model->meta = $posts['meta'];
$model->pic = $posts['pic'];
$model->create_time = $model->update_time = time();
if($model->save()){
return $this->redirect(['master']);
}else{
die("保存失败");
}
} else {
return $this->render('add_master',['action'=>'/live/addmaster']);
}
}
public function actionEditmaster()
{
$id = Yii::$app->request->get('id',0);
$master_id = Yii::$app->request->post('master_id',0);
if($id || $master_id){
if($posts = Yii::$app->request->post()){
$model = Master::findOne($posts['master_id']);
$model->name = $posts['name'];
$model->meta = $posts['meta'];
$model->pic = $posts['pic'];
if($model->save()){
return $this->redirect(['editmaster','id' => $model->master_id]);
}else{
die("保存失败");
}
}else{
$row = Master::find()->where(['master_id'=>$id])->one();
return $this->render('add_master',[
'action'=>'/live/editmaster',
'opt'=>'update',
'row'=>$row
]);
}
}
}
public function actionDelmaster(){
$id = Yii::$app->request->get('id',0);
if($id){
$model = Master::findOne($id);
if($model->delete()){
return $this->redirect(['master']);
}else{
echo "删除失败";exit;
}
}
}
}