Authored by xiaofeng.yao@yoho.cn

主播管理

... ... @@ -2,9 +2,11 @@
namespace backend\controllers;
use Yii;
use app\models\Master;
use yii\data\Pagination;
/**
* Site controller
* Live controller
*/
class LiveController extends BaseController
{
... ... @@ -24,7 +26,27 @@ class LiveController extends BaseController
*/
public function actionMaster()
{
return $this->render('master');
$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
]);
}
/**
... ... @@ -35,4 +57,67 @@ class LiveController extends BaseController
{
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;
}
}
}
}
... ...
... ... @@ -30,9 +30,9 @@ class Master extends \yii\db\ActiveRecord
public function rules()
{
return [
[['master_id', 'create_time', 'update_time'], 'integer'],
[['create_time', 'update_time'], 'integer'],
[['name'], 'string', 'max' => 100],
[['pic'], 'string', 'max' => 255],
[['meta', 'pic'], 'string', 'max' => 255],
];
}
... ... @@ -42,12 +42,17 @@ class Master extends \yii\db\ActiveRecord
public function attributeLabels()
{
return [
'id' => 'ID',
'master_id' => 'Master ID',
'name' => 'Name',
'meta' => 'Meta',
'pic' => 'Pic',
'live_nums' => 'Live Nums',
'create_time' => 'Create Time',
'update_time' => 'Update Time',
];
}
public function b(){
$this->create_time = time();
}
}
... ...
<div class="col-md-6">
<form id="form" method="POST" action="<?php echo $action?>">
<div class="panel panel-default">
<input type="hidden" name="opt" value="">
<input type="hidden" name="master_id" value="<?php echo $row->master_id?>">
<div class="panel-body">
<div class="row">
<div class="form-group">
<label class="col-sm-3 control-label">主播名称:<span class="asterisk">*</span></label>
<div class="col-sm-9">
<input type="text" name="name" class="form-control" required="required" value="<?php echo $row->name?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">主播标签:<span class="asterisk">*</span></label>
<div class="col-sm-9">
<input type="text" name="meta" class="form-control" required="required" value="<?php echo $row->meta?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">主播头像:<span class="asterisk">*</span></label>
<div class="col-sm-9">
<input type="text" name="pic" class="form-control" required="required" value="<?php echo $row->pic?>">
</div>
</div>
</div><!-- row -->
</div><!-- panel-body -->
<div class="panel-footer">
<div class="row">
<div class="col-sm-9 col-sm-offset-3">
<button class="btn btn-primary mr5" id="upload_button">保存</button>
<a href="<?=$_refer?>" class="btn btn-dark">取消</a>
</div>
</div>
</div><!-- panel-footer -->
</div><!-- panel -->
</form>
</div>
\ No newline at end of file
... ...
<div class="panel panel-default">
<div class="panel-body">
<form class="form-inline" method="get" >
<div>
<div class="form-group">
<label class="control-label">主播名称:</label>
<input class="form-control" name="name" value="<?php echo $condition['name']?>">
</div>
<button type="submit" class="btn btn-primary mr5">查询</button>
</div>
</form>
</div>
</div>
<div><a class="btn btn-primary" href="/live/addmaster">添加主播</a></div>
<div class="row">
<div class="col-md-12">
<div class="table-responsive">
<table class="table table-dark mb30">
<thead>
<tr>
<th>ID</th>
<th>主播头像</th>
<th>主播名称</th>
<th>主播标签</th>
<th>直播次数</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<?php foreach($list as $v):?>
<tr>
<td><?php echo $v->master_id;?></td>
<td><img src="<?php echo $v->pic;?>" style="max-width: 100px"></td>
<td><?php echo $v->name;?></td>
<td><?php echo $v->meta;?></td>
<td><?php echo $v->live_nums;?></td>
<td>
<a class="btn btn-primary" href="/live/editmaster?id=<?php echo $v->master_id;?>">编辑</a>
<a class="btn btn-danger" href="/live/delmaster?id=<?php echo $v->master_id;?>">删除</a>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
</div>
<!-- table-responsive -->
</div>
<!-- col-md-12 -->
</div>
<script type="text/javascript">
</script>
\ No newline at end of file
... ...