Authored by wuxiao

主播管理

... ... @@ -46,26 +46,26 @@ class LiveController extends BaseController
*/
public function actionMaster()
{
$query = Master::find();
$conditions = Yii::$app->request->get();
if(array_filter($conditions)){
$sql ="name like '%".$conditions['name']."%'";
$filter = Filter::self()->masterName()->submit()->reset();
if ($condition = $filter->get_where(true)){
$model = Master::condition($condition);
}else{
$sql = "";
$model = Master::find();
}
$count = clone $model;
$pagination = new Pagination([
'defaultPageSize' => 15,
'totalCount' => $query->count(),
'totalCount' => $count->count(),
]);
$masters = $query->where($sql)
->orderBy('create_time')
$masters = $model
->orderBy(['create_time'=>SORT_DESC])
->offset($pagination->offset)
->limit($pagination->limit)
->all();
return $this->render('master',[
'filter'=>$filter,
'pagination'=>$pagination,
'list'=>$masters,
'condition'=>$conditions
]);
}
... ... @@ -96,53 +96,81 @@ class LiveController extends BaseController
}else{
Yii::$app->session->setFlash('error', '保存失败。');
}
return $this->redirect(['master']);
} else {
return $this->render('add_master',['action'=>'/live/addmaster']);
return $this->redirect('live/master');
}
//图片上传组件
$uploader = \backend\widgets\UploadImage::self()->logo('pic');
return $this->render('add_master',[
'row'=> $model,
'uploader'=>$uploader,
]);
}
/**
* 编辑主播
* @return type
*/
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();
if (!$id = Yii::$app->getRequest()->getQueryParam('id')){
return $this->redirect($this->_refer);
}
$model = new Master;
if (!$model = $model->findOne($id)){
Yii::$app->session->setFlash('error', '找不到该主播');
return $this->redirect($this->_refer);
}
if($posts = Yii::$app->request->post()){
$model->name = $posts['name'];
$model->meta = $posts['meta'];
$model->pic = $posts['pic'];
if($model->save()){
Yii::$app->session->setFlash('success', '编辑成功。');
}else{
$row = Master::find()->where(['master_id'=>$id])->one();
return $this->render('add_master',[
'action'=>'/live/editmaster',
'opt'=>'update',
'row'=>$row
]);
Yii::$app->session->setFlash('error', '编辑失败。');
}
return $this->refresh();
}
//图片上传组件
$uploader = \backend\widgets\UploadImage::self()->logo('pic',$model->pic);
return $this->render('add_master',[
'row'=>$model,
'uploader'=>$uploader,
]);
}
/**
* 删除主播
* @return type
*/
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', '删除失败。');
}
if (!$id = Yii::$app->getRequest()->getQueryParam('id')){
return $this->redirect($this->_refer);
}
$model = new Master;
if (!$model = $model->findOne($id)){
Yii::$app->session->setFlash('error', '找不到该主播');
return $this->redirect($this->_refer);
}
if($model->delete()){
Yii::$app->session->setFlash('success', '删除成功');
}else{
Yii::$app->session->setFlash('error', '删除失败。');
}
return $this->redirect($this->_refer);
}
/**
* 创建直播间
* @return type
... ...
... ... @@ -51,6 +51,24 @@ class Master extends \yii\db\ActiveRecord
'update_time' => 'Update Time',
];
}
/**
* 注入查询条件
* @param array $condition
*/
public static function condition($condition){
$model = parent::find();
foreach ($condition as $field=>$value){
if ($field == 'name'){
if (!empty($value)){
$model->andWhere(['like','name',$value]);
}
}else{
$model->andWhere([$field=>$value]);
}
}
return $model;
}
public function b(){
$this->create_time = time();
... ...
<?php
use backend\widgets\YHGImage\Common\Images as CommonImages;
$this->title = $this->params['main_title'].'-'.$this->params['sub_title'];
?>
<div class="col-md-6">
<form id="form" method="POST" action="<?php echo $action?>">
<form id="form" method="POST" action="">
<div class="panel panel-default">
<input type="hidden" name="opt" value="">
<input type="hidden" name="master_id" value="<?php echo $row->master_id?>">
... ... @@ -22,7 +28,10 @@
<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?>">
<?=$uploader?>
<?php if ($row->pic):?>
<div class="file-item thumbnail upload-state-done"><img src="<?=CommonImages::getImageUrl($row->pic, 110, 110)?>"><div class="info">当前图片</div></div>
<?php endif;?>
</div>
</div>
</div><!-- row -->
... ... @@ -31,7 +40,7 @@
<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>
<a href="/live/master" class="btn btn-dark">取消</a>
</div>
</div>
</div><!-- panel-footer -->
... ...
<?php
use yii\helpers\Html;
use backend\widgets\LinkPager;
use backend\widgets\YHGImage\Common\Images as CommonImages;
$this->title = $this->params['main_title'].'-'.$this->params['sub_title'];
?>
<div class="panel panel-default">
<div class="panel-body">
<form class="form-inline" method="get" >
<form action="" 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>
<?=$filter?>
</div>
</form>
</div>
... ... @@ -22,10 +26,10 @@
<table class="table table-dark mb30">
<thead>
<tr>
<th>ID</th>
<th>主播头像</th>
<th>主播ID</th>
<th>主播名称</th>
<th>主播标签</th>
<th>主播头像</th>
<th>直播次数</th>
<th>操作</th>
</tr>
... ... @@ -34,13 +38,13 @@
<?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><img height="70" src="<?=CommonImages::getImageUrl($v->pic, 70, 70, 2)?>"></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>
<a class="btn btn-primary" href="/live/editmaster/<?php echo $v->master_id;?>">编辑</a>
<a class="btn btn-danger" onclick="return confirm('删除该主播?')" href="/live/delmaster/<?php echo $v->master_id;?>">删除</a>
</td>
</tr>
... ... @@ -49,6 +53,7 @@
</table>
</div>
<!-- table-responsive -->
<?php echo LinkPager::widget(['pagination' => $pagination]);?>
</div>
<!-- col-md-12 -->
</div>
... ...
... ... @@ -8,7 +8,7 @@ $this->title = $this->params['main_title'].'-'.$this->params['sub_title'];
<div class="panel panel-default">
<div class="panel-body">
<form aciton="" method="GET" class="form-inline">
<form action="" method="GET" class="form-inline">
<div>
<?=$filter?>
</div>
... ... @@ -59,7 +59,7 @@ $this->title = $this->params['main_title'].'-'.$this->params['sub_title'];
<a href="/forbidden/index?room_id=<?=$model->id?>" class="btn btn-default btn-white">禁言</a>
<span type="status">
<button type="disable" onclick="if(confirm('删除直播间?'))location.href='/live/roomoperate/<?=$model->id?>?type=del'" class="btn btn-danger btn-metro">删除</button>
<button type="disable" onclick="return confirm('删除直播间?')" href="/live/roomoperate/<?=$model->id?>?type=del" class="btn btn-danger btn-metro">删除</button>
<button type="close" onclick="set_shelf('5011880', 'off')" class="btn btn-danger btn-metro" style="display:none">关闭直播</button>
</span>
</td>
... ...
... ... @@ -101,4 +101,19 @@ EOT;
return $this;
}
/*
* 关键字查询
*/
public function masterName($name = null, $value = NULL){
if (!$name)
$name = 'name';
//构造当前元素
$this
->html('<div class="form-group"><label class="control-label">名称:</label>')
->input_equal($name, $value,array('class'=>'form-control','placeholder'=>"搜索主播名称"))
->html('</div>');
return $this;
}
}
\ No newline at end of file
... ...