Authored by wuxiao

主播管理

@@ -46,26 +46,26 @@ class LiveController extends BaseController @@ -46,26 +46,26 @@ class LiveController extends BaseController
46 */ 46 */
47 public function actionMaster() 47 public function actionMaster()
48 { 48 {
49 - $query = Master::find();  
50 - $conditions = Yii::$app->request->get();  
51 -  
52 - if(array_filter($conditions)){  
53 - $sql ="name like '%".$conditions['name']."%'"; 49 + $filter = Filter::self()->masterName()->submit()->reset();
  50 + if ($condition = $filter->get_where(true)){
  51 + $model = Master::condition($condition);
54 }else{ 52 }else{
55 - $sql = ""; 53 + $model = Master::find();
56 } 54 }
  55 +
  56 + $count = clone $model;
57 $pagination = new Pagination([ 57 $pagination = new Pagination([
58 - 'defaultPageSize' => 15,  
59 - 'totalCount' => $query->count(), 58 + 'totalCount' => $count->count(),
60 ]); 59 ]);
61 - $masters = $query->where($sql)  
62 - ->orderBy('create_time') 60 + $masters = $model
  61 + ->orderBy(['create_time'=>SORT_DESC])
63 ->offset($pagination->offset) 62 ->offset($pagination->offset)
64 ->limit($pagination->limit) 63 ->limit($pagination->limit)
65 ->all(); 64 ->all();
66 return $this->render('master',[ 65 return $this->render('master',[
  66 + 'filter'=>$filter,
  67 + 'pagination'=>$pagination,
67 'list'=>$masters, 68 'list'=>$masters,
68 - 'condition'=>$conditions  
69 ]); 69 ]);
70 } 70 }
71 71
@@ -96,53 +96,81 @@ class LiveController extends BaseController @@ -96,53 +96,81 @@ class LiveController extends BaseController
96 }else{ 96 }else{
97 Yii::$app->session->setFlash('error', '保存失败。'); 97 Yii::$app->session->setFlash('error', '保存失败。');
98 } 98 }
99 - return $this->redirect(['master']);  
100 - } else {  
101 - return $this->render('add_master',['action'=>'/live/addmaster']); 99 + return $this->redirect('live/master');
102 } 100 }
  101 +
  102 + //图片上传组件
  103 + $uploader = \backend\widgets\UploadImage::self()->logo('pic');
  104 +
  105 + return $this->render('add_master',[
  106 + 'row'=> $model,
  107 + 'uploader'=>$uploader,
  108 + ]);
103 } 109 }
104 110
  111 + /**
  112 + * 编辑主播
  113 + * @return type
  114 + */
105 public function actionEditmaster() 115 public function actionEditmaster()
106 { 116 {
107 -  
108 - $id = Yii::$app->request->get('id',0);  
109 - $master_id = Yii::$app->request->post('master_id',0);  
110 -  
111 - if($id || $master_id){  
112 - if($posts = Yii::$app->request->post()){  
113 - $model = Master::findOne($posts['master_id']);  
114 - $model->name = $posts['name'];  
115 - $model->meta = $posts['meta'];  
116 - $model->pic = $posts['pic'];  
117 - if($model->save()){  
118 - //return $this->redirect(['editmaster','id' => $model->master_id]);  
119 - Yii::$app->session->setFlash('success', '编辑成功。');  
120 - }else{  
121 - Yii::$app->session->setFlash('error', '编辑失败。');  
122 - }  
123 - return $this->refresh(); 117 + if (!$id = Yii::$app->getRequest()->getQueryParam('id')){
  118 + return $this->redirect($this->_refer);
  119 + }
  120 +
  121 + $model = new Master;
  122 + if (!$model = $model->findOne($id)){
  123 + Yii::$app->session->setFlash('error', '找不到该主播');
  124 + return $this->redirect($this->_refer);
  125 + }
  126 +
  127 + if($posts = Yii::$app->request->post()){
  128 + $model->name = $posts['name'];
  129 + $model->meta = $posts['meta'];
  130 + $model->pic = $posts['pic'];
  131 +
  132 + if($model->save()){
  133 + Yii::$app->session->setFlash('success', '编辑成功。');
124 }else{ 134 }else{
125 - $row = Master::find()->where(['master_id'=>$id])->one();  
126 - return $this->render('add_master',[  
127 - 'action'=>'/live/editmaster',  
128 - 'opt'=>'update',  
129 - 'row'=>$row  
130 - ]); 135 + Yii::$app->session->setFlash('error', '编辑失败。');
131 } 136 }
  137 + return $this->refresh();
132 } 138 }
  139 +
  140 + //图片上传组件
  141 + $uploader = \backend\widgets\UploadImage::self()->logo('pic',$model->pic);
  142 +
  143 + return $this->render('add_master',[
  144 + 'row'=>$model,
  145 + 'uploader'=>$uploader,
  146 + ]);
133 } 147 }
134 148
  149 + /**
  150 + * 删除主播
  151 + * @return type
  152 + */
135 public function actionDelmaster(){ 153 public function actionDelmaster(){
136 - $id = Yii::$app->request->get('id',0);  
137 - if($id){  
138 - $model = Master::findOne($id);  
139 - if($model->delete()){  
140 - return $this->redirect(['master']);  
141 - }else{  
142 - Yii::$app->session->setFlash('error', '删除失败。');  
143 - } 154 +
  155 + if (!$id = Yii::$app->getRequest()->getQueryParam('id')){
  156 + return $this->redirect($this->_refer);
  157 + }
  158 +
  159 + $model = new Master;
  160 + if (!$model = $model->findOne($id)){
  161 + Yii::$app->session->setFlash('error', '找不到该主播');
  162 + return $this->redirect($this->_refer);
  163 + }
  164 +
  165 + if($model->delete()){
  166 + Yii::$app->session->setFlash('success', '删除成功');
  167 + }else{
  168 + Yii::$app->session->setFlash('error', '删除失败。');
144 } 169 }
  170 +
  171 + return $this->redirect($this->_refer);
145 } 172 }
  173 +
146 /** 174 /**
147 * 创建直播间 175 * 创建直播间
148 * @return type 176 * @return type
@@ -51,6 +51,24 @@ class Master extends \yii\db\ActiveRecord @@ -51,6 +51,24 @@ class Master extends \yii\db\ActiveRecord
51 'update_time' => 'Update Time', 51 'update_time' => 'Update Time',
52 ]; 52 ];
53 } 53 }
  54 +
  55 + /**
  56 + * 注入查询条件
  57 + * @param array $condition
  58 + */
  59 + public static function condition($condition){
  60 + $model = parent::find();
  61 + foreach ($condition as $field=>$value){
  62 + if ($field == 'name'){
  63 + if (!empty($value)){
  64 + $model->andWhere(['like','name',$value]);
  65 + }
  66 + }else{
  67 + $model->andWhere([$field=>$value]);
  68 + }
  69 + }
  70 + return $model;
  71 + }
54 72
55 public function b(){ 73 public function b(){
56 $this->create_time = time(); 74 $this->create_time = time();
  1 +<?php
  2 +use backend\widgets\YHGImage\Common\Images as CommonImages;
  3 +
  4 +$this->title = $this->params['main_title'].'-'.$this->params['sub_title'];
  5 +?>
  6 +
1 <div class="col-md-6"> 7 <div class="col-md-6">
2 - <form id="form" method="POST" action="<?php echo $action?>"> 8 + <form id="form" method="POST" action="">
3 <div class="panel panel-default"> 9 <div class="panel panel-default">
4 <input type="hidden" name="opt" value=""> 10 <input type="hidden" name="opt" value="">
5 <input type="hidden" name="master_id" value="<?php echo $row->master_id?>"> 11 <input type="hidden" name="master_id" value="<?php echo $row->master_id?>">
@@ -22,7 +28,10 @@ @@ -22,7 +28,10 @@
22 <div class="form-group"> 28 <div class="form-group">
23 <label class="col-sm-3 control-label">主播头像:<span class="asterisk">*</span></label> 29 <label class="col-sm-3 control-label">主播头像:<span class="asterisk">*</span></label>
24 <div class="col-sm-9"> 30 <div class="col-sm-9">
25 - <input type="text" name="pic" class="form-control" required="required" value="<?php echo $row->pic?>"> 31 + <?=$uploader?>
  32 + <?php if ($row->pic):?>
  33 + <div class="file-item thumbnail upload-state-done"><img src="<?=CommonImages::getImageUrl($row->pic, 110, 110)?>"><div class="info">当前图片</div></div>
  34 + <?php endif;?>
26 </div> 35 </div>
27 </div> 36 </div>
28 </div><!-- row --> 37 </div><!-- row -->
@@ -31,7 +40,7 @@ @@ -31,7 +40,7 @@
31 <div class="row"> 40 <div class="row">
32 <div class="col-sm-9 col-sm-offset-3"> 41 <div class="col-sm-9 col-sm-offset-3">
33 <button class="btn btn-primary mr5" id="upload_button">保存</button> 42 <button class="btn btn-primary mr5" id="upload_button">保存</button>
34 - <a href="<?=$_refer?>" class="btn btn-dark">取消</a> 43 + <a href="/live/master" class="btn btn-dark">取消</a>
35 </div> 44 </div>
36 </div> 45 </div>
37 </div><!-- panel-footer --> 46 </div><!-- panel-footer -->
  1 +<?php
  2 +use yii\helpers\Html;
  3 +use backend\widgets\LinkPager;
  4 +use backend\widgets\YHGImage\Common\Images as CommonImages;
  5 +
  6 +$this->title = $this->params['main_title'].'-'.$this->params['sub_title'];
  7 +?>
  8 +
1 <div class="panel panel-default"> 9 <div class="panel panel-default">
2 <div class="panel-body"> 10 <div class="panel-body">
3 - <form class="form-inline" method="get" > 11 + <form action="" class="form-inline" method="get" >
4 <div> 12 <div>
5 - <div class="form-group">  
6 - <label class="control-label">主播名称:</label>  
7 - <input class="form-control" name="name" value="<?php echo @$condition['name']?>">  
8 - </div>  
9 - <button type="submit" class="btn btn-primary mr5">查询</button> 13 + <?=$filter?>
10 </div> 14 </div>
11 </form> 15 </form>
12 </div> 16 </div>
@@ -22,10 +26,10 @@ @@ -22,10 +26,10 @@
22 <table class="table table-dark mb30"> 26 <table class="table table-dark mb30">
23 <thead> 27 <thead>
24 <tr> 28 <tr>
25 - <th>ID</th>  
26 - <th>主播头像</th> 29 + <th>主播ID</th>
27 <th>主播名称</th> 30 <th>主播名称</th>
28 <th>主播标签</th> 31 <th>主播标签</th>
  32 + <th>主播头像</th>
29 <th>直播次数</th> 33 <th>直播次数</th>
30 <th>操作</th> 34 <th>操作</th>
31 </tr> 35 </tr>
@@ -34,13 +38,13 @@ @@ -34,13 +38,13 @@
34 <?php foreach($list as $v):?> 38 <?php foreach($list as $v):?>
35 <tr> 39 <tr>
36 <td><?php echo $v->master_id;?></td> 40 <td><?php echo $v->master_id;?></td>
37 - <td><img src="<?php echo $v->pic;?>" style="max-width: 100px"></td>  
38 <td><?php echo $v->name;?></td> 41 <td><?php echo $v->name;?></td>
39 <td><?php echo $v->meta;?></td> 42 <td><?php echo $v->meta;?></td>
  43 + <td><img height="70" src="<?=CommonImages::getImageUrl($v->pic, 70, 70, 2)?>"></td>
40 <td><?php echo $v->live_nums;?></td> 44 <td><?php echo $v->live_nums;?></td>
41 <td> 45 <td>
42 - <a class="btn btn-primary" href="/live/editmaster?id=<?php echo $v->master_id;?>">编辑</a>  
43 - <a class="btn btn-danger" href="/live/delmaster?id=<?php echo $v->master_id;?>">删除</a> 46 + <a class="btn btn-primary" href="/live/editmaster/<?php echo $v->master_id;?>">编辑</a>
  47 + <a class="btn btn-danger" onclick="return confirm('删除该主播?')" href="/live/delmaster/<?php echo $v->master_id;?>">删除</a>
44 </td> 48 </td>
45 </tr> 49 </tr>
46 50
@@ -49,6 +53,7 @@ @@ -49,6 +53,7 @@
49 </table> 53 </table>
50 </div> 54 </div>
51 <!-- table-responsive --> 55 <!-- table-responsive -->
  56 + <?php echo LinkPager::widget(['pagination' => $pagination]);?>
52 </div> 57 </div>
53 <!-- col-md-12 --> 58 <!-- col-md-12 -->
54 </div> 59 </div>
@@ -8,7 +8,7 @@ $this->title = $this->params['main_title'].'-'.$this->params['sub_title']; @@ -8,7 +8,7 @@ $this->title = $this->params['main_title'].'-'.$this->params['sub_title'];
8 8
9 <div class="panel panel-default"> 9 <div class="panel panel-default">
10 <div class="panel-body"> 10 <div class="panel-body">
11 - <form aciton="" method="GET" class="form-inline"> 11 + <form action="" method="GET" class="form-inline">
12 <div> 12 <div>
13 <?=$filter?> 13 <?=$filter?>
14 </div> 14 </div>
@@ -59,7 +59,7 @@ $this->title = $this->params['main_title'].'-'.$this->params['sub_title']; @@ -59,7 +59,7 @@ $this->title = $this->params['main_title'].'-'.$this->params['sub_title'];
59 <a href="/forbidden/index?room_id=<?=$model->id?>" class="btn btn-default btn-white">禁言</a> 59 <a href="/forbidden/index?room_id=<?=$model->id?>" class="btn btn-default btn-white">禁言</a>
60 60
61 <span type="status"> 61 <span type="status">
62 - <button type="disable" onclick="if(confirm('删除直播间?'))location.href='/live/roomoperate/<?=$model->id?>?type=del'" class="btn btn-danger btn-metro">删除</button> 62 + <button type="disable" onclick="return confirm('删除直播间?')" href="/live/roomoperate/<?=$model->id?>?type=del" class="btn btn-danger btn-metro">删除</button>
63 <button type="close" onclick="set_shelf('5011880', 'off')" class="btn btn-danger btn-metro" style="display:none">关闭直播</button> 63 <button type="close" onclick="set_shelf('5011880', 'off')" class="btn btn-danger btn-metro" style="display:none">关闭直播</button>
64 </span> 64 </span>
65 </td> 65 </td>
@@ -101,4 +101,19 @@ EOT; @@ -101,4 +101,19 @@ EOT;
101 return $this; 101 return $this;
102 } 102 }
103 103
  104 + /*
  105 + * 关键字查询
  106 + */
  107 + public function masterName($name = null, $value = NULL){
  108 + if (!$name)
  109 + $name = 'name';
  110 +
  111 + //构造当前元素
  112 + $this
  113 + ->html('<div class="form-group"><label class="control-label">名称:</label>')
  114 + ->input_equal($name, $value,array('class'=>'form-control','placeholder'=>"搜索主播名称"))
  115 + ->html('</div>');
  116 + return $this;
  117 + }
  118 +
104 } 119 }