Authored by xiaofeng.yao@yoho.cn

主播管理

@@ -2,9 +2,11 @@ @@ -2,9 +2,11 @@
2 namespace backend\controllers; 2 namespace backend\controllers;
3 3
4 use Yii; 4 use Yii;
  5 +use app\models\Master;
  6 +use yii\data\Pagination;
5 7
6 /** 8 /**
7 - * Site controller 9 + * Live controller
8 */ 10 */
9 class LiveController extends BaseController 11 class LiveController extends BaseController
10 { 12 {
@@ -24,7 +26,27 @@ class LiveController extends BaseController @@ -24,7 +26,27 @@ class LiveController extends BaseController
24 */ 26 */
25 public function actionMaster() 27 public function actionMaster()
26 { 28 {
27 - return $this->render('master'); 29 + $query = Master::find();
  30 + $conditions = Yii::$app->request->get();
  31 +
  32 + if(array_filter($conditions)){
  33 + $sql ="name like '%".$conditions['name']."%'";
  34 + }else{
  35 + $sql = "";
  36 + }
  37 + $pagination = new Pagination([
  38 + 'defaultPageSize' => 15,
  39 + 'totalCount' => $query->count(),
  40 + ]);
  41 + $masters = $query->where($sql)
  42 + ->orderBy('create_time')
  43 + ->offset($pagination->offset)
  44 + ->limit($pagination->limit)
  45 + ->all();
  46 + return $this->render('master',[
  47 + 'list'=>$masters,
  48 + 'condition'=>$conditions
  49 + ]);
28 } 50 }
29 51
30 /** 52 /**
@@ -35,4 +57,67 @@ class LiveController extends BaseController @@ -35,4 +57,67 @@ class LiveController extends BaseController
35 { 57 {
36 return $this->render('video'); 58 return $this->render('video');
37 } 59 }
  60 +
  61 + /**
  62 + * 添加主播
  63 + * @return type
  64 + */
  65 + public function actionAddmaster()
  66 + {
  67 + $model = new Master();
  68 +
  69 + if ($posts = Yii::$app->request->post()) {
  70 + $model->name = $posts['name'];
  71 + $model->meta = $posts['meta'];
  72 + $model->pic = $posts['pic'];
  73 + $model->create_time = $model->update_time = time();
  74 + if($model->save()){
  75 + return $this->redirect(['master']);
  76 + }else{
  77 + die("保存失败");
  78 + }
  79 + } else {
  80 + return $this->render('add_master',['action'=>'/live/addmaster']);
  81 + }
  82 + }
  83 +
  84 + public function actionEditmaster()
  85 + {
  86 +
  87 + $id = Yii::$app->request->get('id',0);
  88 + $master_id = Yii::$app->request->post('master_id',0);
  89 +
  90 + if($id || $master_id){
  91 + if($posts = Yii::$app->request->post()){
  92 + $model = Master::findOne($posts['master_id']);
  93 + $model->name = $posts['name'];
  94 + $model->meta = $posts['meta'];
  95 + $model->pic = $posts['pic'];
  96 + if($model->save()){
  97 + return $this->redirect(['editmaster','id' => $model->master_id]);
  98 + }else{
  99 + die("保存失败");
  100 + }
  101 + }else{
  102 + $row = Master::find()->where(['master_id'=>$id])->one();
  103 + return $this->render('add_master',[
  104 + 'action'=>'/live/editmaster',
  105 + 'opt'=>'update',
  106 + 'row'=>$row
  107 + ]);
  108 + }
  109 + }
  110 + }
  111 +
  112 + public function actionDelmaster(){
  113 + $id = Yii::$app->request->get('id',0);
  114 + if($id){
  115 + $model = Master::findOne($id);
  116 + if($model->delete()){
  117 + return $this->redirect(['master']);
  118 + }else{
  119 + echo "删除失败";exit;
  120 + }
  121 + }
  122 + }
38 } 123 }
@@ -30,9 +30,9 @@ class Master extends \yii\db\ActiveRecord @@ -30,9 +30,9 @@ class Master extends \yii\db\ActiveRecord
30 public function rules() 30 public function rules()
31 { 31 {
32 return [ 32 return [
33 - [['master_id', 'create_time', 'update_time'], 'integer'], 33 + [['create_time', 'update_time'], 'integer'],
34 [['name'], 'string', 'max' => 100], 34 [['name'], 'string', 'max' => 100],
35 - [['pic'], 'string', 'max' => 255], 35 + [['meta', 'pic'], 'string', 'max' => 255],
36 ]; 36 ];
37 } 37 }
38 38
@@ -42,12 +42,17 @@ class Master extends \yii\db\ActiveRecord @@ -42,12 +42,17 @@ class Master extends \yii\db\ActiveRecord
42 public function attributeLabels() 42 public function attributeLabels()
43 { 43 {
44 return [ 44 return [
45 - 'id' => 'ID',  
46 'master_id' => 'Master ID', 45 'master_id' => 'Master ID',
47 'name' => 'Name', 46 'name' => 'Name',
  47 + 'meta' => 'Meta',
48 'pic' => 'Pic', 48 'pic' => 'Pic',
  49 + 'live_nums' => 'Live Nums',
49 'create_time' => 'Create Time', 50 'create_time' => 'Create Time',
50 'update_time' => 'Update Time', 51 'update_time' => 'Update Time',
51 ]; 52 ];
52 } 53 }
  54 +
  55 + public function b(){
  56 + $this->create_time = time();
  57 + }
53 } 58 }
  1 +<div class="col-md-6">
  2 + <form id="form" method="POST" action="<?php echo $action?>">
  3 + <div class="panel panel-default">
  4 + <input type="hidden" name="opt" value="">
  5 + <input type="hidden" name="master_id" value="<?php echo $row->master_id?>">
  6 + <div class="panel-body">
  7 + <div class="row">
  8 + <div class="form-group">
  9 + <label class="col-sm-3 control-label">主播名称:<span class="asterisk">*</span></label>
  10 + <div class="col-sm-9">
  11 + <input type="text" name="name" class="form-control" required="required" value="<?php echo $row->name?>">
  12 + </div>
  13 + </div>
  14 +
  15 + <div class="form-group">
  16 + <label class="col-sm-3 control-label">主播标签:<span class="asterisk">*</span></label>
  17 + <div class="col-sm-9">
  18 + <input type="text" name="meta" class="form-control" required="required" value="<?php echo $row->meta?>">
  19 + </div>
  20 + </div>
  21 +
  22 + <div class="form-group">
  23 + <label class="col-sm-3 control-label">主播头像:<span class="asterisk">*</span></label>
  24 + <div class="col-sm-9">
  25 + <input type="text" name="pic" class="form-control" required="required" value="<?php echo $row->pic?>">
  26 + </div>
  27 + </div>
  28 + </div><!-- row -->
  29 + </div><!-- panel-body -->
  30 + <div class="panel-footer">
  31 + <div class="row">
  32 + <div class="col-sm-9 col-sm-offset-3">
  33 + <button class="btn btn-primary mr5" id="upload_button">保存</button>
  34 + <a href="<?=$_refer?>" class="btn btn-dark">取消</a>
  35 + </div>
  36 + </div>
  37 + </div><!-- panel-footer -->
  38 + </div><!-- panel -->
  39 + </form>
  40 +
  41 +</div>
  1 +<div class="panel panel-default">
  2 + <div class="panel-body">
  3 + <form class="form-inline" method="get" >
  4 + <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>
  10 + </div>
  11 + </form>
  12 + </div>
  13 +</div>
  14 +<div><a class="btn btn-primary" href="/live/addmaster">添加主播</a></div>
  15 +<div class="row">
  16 + <div class="col-md-12">
  17 + <div class="table-responsive">
  18 + <table class="table table-dark mb30">
  19 + <thead>
  20 + <tr>
  21 + <th>ID</th>
  22 + <th>主播头像</th>
  23 + <th>主播名称</th>
  24 + <th>主播标签</th>
  25 + <th>直播次数</th>
  26 + <th>操作</th>
  27 + </tr>
  28 + </thead>
  29 + <tbody>
  30 + <?php foreach($list as $v):?>
  31 + <tr>
  32 + <td><?php echo $v->master_id;?></td>
  33 + <td><img src="<?php echo $v->pic;?>" style="max-width: 100px"></td>
  34 + <td><?php echo $v->name;?></td>
  35 + <td><?php echo $v->meta;?></td>
  36 + <td><?php echo $v->live_nums;?></td>
  37 + <td>
  38 + <a class="btn btn-primary" href="/live/editmaster?id=<?php echo $v->master_id;?>">编辑</a>
  39 + <a class="btn btn-danger" href="/live/delmaster?id=<?php echo $v->master_id;?>">删除</a>
  40 + </td>
  41 + </tr>
  42 +
  43 + <?php endforeach;?>
  44 + </tbody>
  45 + </table>
  46 + </div>
  47 + <!-- table-responsive -->
  48 + </div>
  49 + <!-- col-md-12 -->
  50 +</div>
  51 +
  52 +<script type="text/javascript">
  53 +
  54 +</script>