LiveController.php
6.28 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
<?php
namespace backend\controllers;
use Yii;
use app\models\Master;
use backend\components\Pagination;
/**
* Live controller
*/
class LiveController extends BaseController
{
/**
* 直播间
* @return type
*/
public function actionRoom()
{
$model = \app\models\Room::find();
if ($filter = Yii::$app->getRequest()->getQueryParam('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 = \app\models\Room::find()->asArray()->offset($pagination->offset)->limit($pagination->limit)->orderBy(['create_time'=>SORT_DESC])->all();
return $this->render('room',[
'filter'=>$filter ? : [],
'pagination'=>$pagination,
'list'=>$list
]);
}
/**
* 主播
* @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()){
Yii::$app->session->setFlash('success', '保存成功。');
}else{
Yii::$app->session->setFlash('error', '保存失败。');
}
return $this->redirect(['master']);
} 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]);
Yii::$app->session->setFlash('success', '编辑成功。');
}else{
Yii::$app->session->setFlash('error', '编辑失败。');
}
return $this->refresh();
}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{
Yii::$app->session->setFlash('error', '删除失败。');
}
}
}
/**
* 创建直播间
* @return type
*/
public function actionRoomcreate()
{
$this->setParam('uploader', '');
$model = new \app\models\Room;
if (Yii::$app->getRequest()->isPost){
$post = Yii::$app->getRequest()->post();
$post['starting_time'] = !$post['starting_time'] ? : strtotime($post['starting_time']);
$model->setAttributes($post);
if ($model->save()){
Yii::$app->session->setFlash('success', '创建成功。');
}else{
Yii::$app->session->setFlash('error', '创建失败。');
}
return $this->redirect('/live/room');
}
return $this->render('roomedit',[
'model'=> $model
]);
}
/**
* 编辑直播间
* @return type
*/
public function actionRoomedit()
{
if (!$id = Yii::$app->getRequest()->getQueryParam('id')){
$this->redirect($this->_refer);
}
$this->setParam('uploader', '');
$model = new \app\models\Room;
$model = $model->findOne($id) ? : $model;
if (Yii::$app->getRequest()->isPost){
$post = Yii::$app->getRequest()->post();
$post['starting_time'] = !$post['starting_time'] ? : strtotime($post['starting_time']);
$model->setAttributes($post);
Yii::$app->session->setFlash('success', '编辑成功。');
if ($model->save()){
Yii::$app->session->setFlash('success', '编辑成功。');
}else{
Yii::$app->session->setFlash('error', '编辑失败。');
}
return $this->redirect('/live/room');
}
return $this->render('roomedit',[
'model'=> $model
]);
}
/**
* 直播间操作
* @return type
*/
public function actionRoomoperate()
{
;
}
}