Authored by xiaofeng.yao@yoho.cn

后台房间、视频新增分享内容和排序字段,以及前台相应接口修改

... ... @@ -9,6 +9,8 @@ use backend\widgets\Filter;
use backend\widgets\YHGImage\Common\Images as CommonImages;
use app\models\Video;
use yii\helpers\ArrayHelper;
use app\models\Share;
use common\config\Params;
/**
* Live controller
... ... @@ -123,13 +125,12 @@ class LiveController extends BaseController
$model = Video::findOne($posts['id']);
if(!empty($model))
{
$model->pic = $posts['pic'];
$model->url = $posts['url'];
$model->title = $posts['title'];
if($model->save())
if($model->edit($posts))
{
Yii::$app->session->setFlash('success', '编辑成功。');
}
}else{
Yii::$app->session->setFlash('error', '编辑失败。');
}
}
else
{
... ... @@ -139,20 +140,56 @@ class LiveController extends BaseController
}
else
{
$id = Yii::$app->request->get('id', 0);
$video = Video::findOne(['id'=> $id]);
if(empty($video))
{
Yii::$app->session->setFlash('error', '找不到该视频');
return $this->redirect($this->_refer);
}
//图片上传组件
$uploader = \backend\widgets\UploadImage::self()->logo('pic', $video->pic);
return $this->render('videoedit', ['video' => $video, 'uploader' => $uploader]);
$id = Yii::$app->request->get('id', 0);
$video = Video::findOne(['id' => $id]);
if (empty($video)) {
Yii::$app->session->setFlash('error', '找不到该视频');
return $this->redirect($this->_refer);
}
$videoShare = [];
if ($shareModel = Share::findOne(['obj_id' => $video->id, 'type' => Params::VIDEO_SHARE_TYPE])) {
$videoShare = $shareModel->toArray();
}
//图片上传组件
$uploader = \backend\widgets\UploadImage::self()->single('pic', $video->pic);
$sharePicUploader = \backend\widgets\UploadImage::self()->single('share_pic', $videoShare['pic']);
return $this->render('videoedit', [
'video' => $video,
'uploader' => $uploader,
'sharePicUploader' => $sharePicUploader,
'videoShare' => $videoShare
]);
}
}
/**
* 删除视频记录
* @author yaoxiaofeng
*/
public function actionVideodel()
{
if (!$id = Yii::$app->getRequest()->getQueryParam('id')) {
return $this->redirect($this->_refer);
}
do {
$model = Video::findOne($id);
if (empty($model)) {
Yii::$app->session->setFlash('error', '找不到该视频信息。');
break;
}
if ($model->delete()) {
Yii::$app->session->setFlash('success', '删除成功。');
} else {
Yii::$app->session->setFlash('error', '删除失败。');
}
break;
} while (false);
return $this->redirect($this->_refer);
}
/**
* 视频状态设置
* @return
*/
... ... @@ -307,11 +344,13 @@ class LiveController extends BaseController
//图片上传组件
$picUploader = \backend\widgets\UploadImage::self()->single('pic',$model->pic);
$backgroundUploader = \backend\widgets\UploadImage::self()->single('background_pic',$model->background_pic);
$sharePicUploader = \backend\widgets\UploadImage::self()->single('share_pic',$post['share_pic'] ? :'');
return $this->render('roomedit',[
'model'=> $model,
'picUploader'=>$picUploader,
'backgroundUploader'=>$backgroundUploader,
'sharePicUploader'=>$sharePicUploader,
'masters'=>$masters,
]);
}
... ... @@ -351,12 +390,19 @@ class LiveController extends BaseController
//图片上传组件
$picUploader = \backend\widgets\UploadImage::self()->single('pic',$model->pic);
$backgroundUploader = \backend\widgets\UploadImage::self()->single('background_pic',$model->background_pic);
$sharePicUploader = \backend\widgets\UploadImage::self()->single('share_pic',$post['share_pic'] ? :'');
$roomShare = [];
if($shareModel = Share::findOne(['obj_id'=>$model->room_id,'type'=>Params::LIVE_SHARE_TYPE])) {
$roomShare = $shareModel->toArray();
}
return $this->render('roomedit',[
'model'=> $model,
'picUploader'=>$picUploader,
'backgroundUploader'=>$backgroundUploader,
'sharePicUploader'=>$sharePicUploader,
'masters'=>$masters,
'roomShare' => $roomShare
]);
}
... ...
... ... @@ -5,6 +5,8 @@ namespace app\models;
use Yii;
use common\lib\QcloudApi\Client as QcloudApiClient;
use common\models\RoomNums;
use common\models\Share;
use common\config\Params;
/**
* This is the model class for table "{{%room}}".
... ... @@ -39,7 +41,7 @@ class Room extends \yii\db\ActiveRecord
public function rules()
{
return [
[['room_id', 'master_id', 'starting_time', 'best', 'vest', 'is_addup', 'living', 'status', 'create_time', 'update_time'], 'integer'],
[['room_id', 'master_id', 'starting_time', 'best', 'vest', 'is_addup', 'living', 'status', 'unstart_sort', 'living_sort', 'create_time', 'update_time'], 'integer'],
[['title', 'watermark'], 'string', 'max' => 100],
[['app', 'secret'], 'string', 'max' => 50],
[['pic', 'background_pic'], 'string', 'max' => 255],
... ... @@ -69,6 +71,8 @@ class Room extends \yii\db\ActiveRecord
'vest' => '马甲状态',
'living' => '直播状态',
'status' => '房间状态',
'unstart_sort' => '未开始排序',
'living_sort' => '直播中排序',
'create_time' => '创建时间',
'update_time' => '更新时间',
];
... ... @@ -197,6 +201,19 @@ class Room extends \yii\db\ActiveRecord
throw new \Exception(current($RoomQchannel->getFirstErrors()));
}
//插入分享内容
$RoomShare = new Share;
$RoomShare->setAttributes([
'obj_id'=>$this->room_id,
'type'=>Params::LIVE_SHARE_TYPE,
'pic'=>$data['share_pic'],
'title'=>$data['share_title'],
'content'=>$data['share_content'],
]);
if (!$RoomShare->save()){
throw new \Exception(current($RoomShare->getFirstErrors()));
}
$transaction->commit();
return $this->room_id;
}catch (\Exception $e) {
... ... @@ -244,6 +261,22 @@ class Room extends \yii\db\ActiveRecord
throw new \Exception(current($this->getFirstErrors()));
}
//编辑分享内容
if (!$RoomShare = Share::findOne(['type' => Params::LIVE_SHARE_TYPE, 'obj_id' => $this->room_id])) {
//编辑以前的房间时,没有相应的分享记录,那么这时候要重新创建一个对象来做插入
$RoomShare = new Share();
}
$RoomShare->setAttributes([
'obj_id' => $this->room_id,
'type' => Params::LIVE_SHARE_TYPE,
'pic' => $data['share_pic'],
'title' => $data['share_title'],
'content' => $data['share_content'],
]);
if (!$RoomShare->save()) {
throw new \Exception(current($RoomShare->getFirstErrors()));
}
$transaction->commit();
return true;
}catch (\Exception $e) {
... ... @@ -272,12 +305,17 @@ class Room extends \yii\db\ActiveRecord
if (!$model->roomQchannel->delete()){
throw new \Exception(current($model->roomQchannel->getFirstErrors()));
}
if (!QcloudApiClient::self()->DeleteLVBChannel([$model->roomQchannel->channel_id])){
throw new \Exception(QcloudApiClient::self()->error());
}
}
//删除分享
$delShare = (new Share())->delLivingShare($model->room_id);
if (!$delShare) {
throw new \Exception("删除分享失败");
}
$transaction->commit();
return true;
}catch (\Exception $e) {
... ...
<?php
namespace app\models;
use Yii;
use common\config\Params;
/**
* This is the model class for table "{{%share}}".
*
* @property integer $id
* @property integer $obj_id
* @property integer $type
* @property string $title
* @property string $content
* @property integer $create_time
* @property integer $update_time
*/
class Share extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%share}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['obj_id', 'type', 'create_time', 'update_time'], 'integer'],
[['content'], 'string'],
[['pic'], 'string', 'max' => 200],
[['title'], 'string', 'max' => 100],
[['obj_id', 'type'], 'unique', 'targetAttribute' => ['obj_id', 'type'], 'message' => 'The combination of Obj ID and Type has already been taken.'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'obj_id' => 'Obj ID',
'type' => 'Type',
'pic' => '分享头图',
'title' => '分享标题',
'content' => '分享内容',
'create_time' => 'Create Time',
'update_time' => 'Update Time',
];
}
public function behaviors()
{
return [
[
'class' => \yii\behaviors\TimestampBehavior::className(),
'createdAtAttribute' => 'create_time',
'updatedAtAttribute' => 'update_time',
]
];
}
private function del($obj_id,$type)
{
return self::findOne(['obj_id'=>$obj_id,'type'=>$type])->delete();
}
public function delLivingShare($room_id)
{
return $this->del($room_id,Params::LIVE_SHARE_TYPE);
}
public function delVideoShare($video_id)
{
return $this->del($video_id,Params::VIDEO_SHARE_TYPE);
}
}
... ...
... ... @@ -3,6 +3,7 @@
namespace app\models;
use Yii;
use common\config\Params;
/**
* This is the model class for table "{{%video}}".
... ... @@ -38,7 +39,7 @@ class Video extends \yii\db\ActiveRecord
public function rules()
{
return [
[['task_id', 'live_start_time', 'live_end_time', 'master_id', 'room_id', 'status', 'like_num', 'audience_num', 'replay_num', 'create_time', 'update_time'], 'integer'],
[['task_id', 'live_start_time', 'live_end_time', 'master_id', 'room_id', 'status', 'like_num', 'audience_num', 'replay_num', 'sort', 'create_time', 'update_time'], 'integer'],
[['title', 'live_title'], 'string', 'max' => 100],
[['pic', 'url'], 'string', 'max' => 255],
[['app'], 'string', 'max' => 50],
... ... @@ -66,6 +67,7 @@ class Video extends \yii\db\ActiveRecord
'like_num' => 'Like Num',
'audience_num' => 'Audience Num',
'replay_num' => 'Replay Num',
'sort' => 'Sort',
'create_time' => 'Create Time',
'update_time' => 'Update Time',
];
... ... @@ -107,7 +109,50 @@ class Video extends \yii\db\ActiveRecord
{
return $this->hasOne(Room::className(), ['room_id'=>'room_id']);
}
/**
* 编辑
* @param array $data
* @author yaoxiaofeng
* @return bool
*/
public function edit(array $data)
{
$transaction = $this->getDb()->beginTransaction();
try {
$this->setAttributes([
'pic' => $data['pic'],
'url' => $data['url'],
'title' => $data['title'],
'sort' => $data['sort']
]);
if (!$this->save()){
throw new \Exception(current($this->getFirstErrors()));
}
//编辑分享内容
if (!$share = Share::findOne(['type' => Params::VIDEO_SHARE_TYPE, 'obj_id' => $this->id])) {
//编辑以前的视频时,没有相应的分享记录,那么这时候要重新创建一个对象来做插入
$share = new Share();
}
$share->setAttributes([
'obj_id' => $this->id,
'type' => Params::VIDEO_SHARE_TYPE,
'pic' => $data['share_pic'],
'title' => $data['share_title'],
'content' => $data['share_content'],
]);
if (!$share->save()) {
throw new \Exception(current($share->getFirstErrors()));
}
$transaction->commit();
return true;
} catch (\Exception $e) {
$transaction->rollBack();
Yii::$app->session->setFlash('warning', $e->getMessage());
return false;
}
}
/**
* 根据条件
* @param array $condition
... ... @@ -136,7 +181,7 @@ class Video extends \yii\db\ActiveRecord
$model->andWhere($sql);
}
}
$model->orderBy(['v.create_time' => SORT_DESC]);
$model->orderBy(['v.sort'=>SORT_DESC,'v.create_time' => SORT_DESC]);
return $model;
}
}
... ...
... ... @@ -84,6 +84,8 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
<th>马甲状态|人数累加</th>
<th>直播状态</th>
<th>在线人数</th>
<th>未开始排序</th>
<th>直播中排序</th>
<th>操作</th>
</tr>
</thead>
... ... @@ -110,8 +112,10 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
真实:<?=@$model->roomNums->online_num ? :0?>,
马甲:<?=@$model->roomNums->vest_online_num ? :0?>
</td>
<td><?=$model->unstart_sort?></td>
<td><?=$model->living_sort?></td>
<td>
<span>
<?php if ($model->living == 1)://直播中?>
<button type="button" onclick="stopLiving(<?=$model->room_id?>)" class="btn btn-danger btn-metro">结束直播</button>
... ...
... ... @@ -46,11 +46,12 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
?>
</script>
<div class="col-md-6">
<form id="form" method="POST" action="">
<div class="panel panel-default">
<div class="panel-body">
<div class="col-md-9">
<form id="form" method="POST" action="">
<div class="panel panel-default">
<div class="panel-body">
<!-- 左侧表单 begin-->
<div class="col-md-6">
<div class="row">
<div class="form-group">
<label class="col-sm-3 control-label">房间号: </label>
... ... @@ -58,27 +59,27 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
<?=$model->room_id ? : '保存后生成'?>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">直播标题: <span class="asterisk">*</span></label>
<div class="col-sm-5">
<div class="col-sm-9">
<input type="text" name="title" class="form-control" required="required" value="<?=$model->title?>">(建议不超过18个汉字)
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">水印文案: </label>
<div class="col-sm-5">
<input type="text" name="watermark" class="form-control" value="<?=$model->watermark?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">主播: <span class="asterisk">*</span></label>
<div class="col-sm-5">
<?php echo Html::dropDownList('master_id', $model->master_id,$masters, ['class' => 'width300 select-basic', 'required'=>"required"]);?>
</div>
</div>
<div class="form-group">
... ... @@ -87,21 +88,21 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
<input type="text" name="starting_time" class="form-control" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" value="<?=$model->starting_time ? date('Y-m-d H:i:s',$model->starting_time) : ''?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">房间密钥: <span class="asterisk">*</span></label>
<div class="col-sm-5">
<input type="text" name="secret" class="form-control" required="required" value="<?=$model->secret?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">是否精选: </label>
<div class="col-sm-2">
<?php echo Html::dropDownList('best', $model->best,Yii::$app->params['config']['best'], ['class' => 'form-control']);?>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">马甲状态: </label>
<div class="col-sm-2">
... ... @@ -118,7 +119,7 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
<?php echo Html::dropDownList('living', $model->living,Yii::$app->params['config']['room_living'], ['class' => 'form-control']);?>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">头图: <span class="asterisk">*</span></label>
<div class="col-sm-9">
... ... @@ -128,7 +129,7 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
<?php endif;?>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">背景图: <span class="asterisk">*</span></label>
<div class="col-sm-9">
... ... @@ -138,7 +139,7 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
<?php endif;?>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">业务线: <span class="asterisk">*</span></label>
<div class="col-sm-5">
... ... @@ -147,18 +148,60 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
<?php endforeach;?>
</div>
</div>
</div><!-- row -->
</div><!-- panel-body -->
<div class="panel-footer">
</div>
<!-- 左侧表单 end-->
<!-- 右侧表单 begin-->
<div class="col-md-6">
<div class="row">
<div class="col-sm-9 col-sm-offset-3">
<button class="btn btn-primary mr5" id="upload_button" onclick="return verify()">保存</button>
<a href="<?=$_refer?>" class="btn btn-dark">取消</a>
<div class="form-group">
<label class="col-sm-3 control-label">未开始排序: </label>
<div class="col-sm-3">
<input type="text" name="unstart_sort" class="form-control" value="<?=$model->unstart_sort?>">
</div>
<label class="col-sm-3 control-label">直播中排序: </label>
<div class="col-sm-3">
<input type="text" name="living_sort" class="form-control" value="<?=$model->living_sort?>">
</div>
</div>
</div>
</div><!-- panel-footer -->
</div><!-- panel -->
</form>
<div class="form-group">
<label class="col-sm-3 control-label">分享主图: </label>
<div class="col-sm-9">
<?=$sharePicUploader?>
<?php if ($model->id && $roomShare['pic']):?>
<div class="file-item thumbnail upload-state-done" id="share_pic"><img src="<?=CommonImages::getImageUrl($roomShare['pic'], 110, 110)?>"><div class="info">当前图片</div></div>
<?php endif;?>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">分享标题: </label>
<div class="col-sm-9">
<input type="text" name="share_title" class="form-control" value="<?php echo ($model->id && $roomShare['title']) ? $roomShare['title']:''?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">分享内容: </label>
<div class="col-sm-9">
<!-- <input type="text" name="share_content" class="form-control" value="">-->
<textarea rows="5" name="share_content" class="form-control"><?php echo ($model->id && $roomShare['content']) ? $roomShare['content']:''?></textarea>
</div>
</div>
</div>
</div>
<!-- 右侧表单 end-->
</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" onclick="return verify()">保存</button>
<a href="<?=$_refer?>" class="btn btn-dark">取消</a>
</div>
</div>
</div><!-- panel-footer -->
</div><!-- panel -->
</form>
</div>
... ...
... ... @@ -43,6 +43,7 @@ if(!isset($condition['backState']))
<th>对应主播</th>
<th>对应直播房间号</th>
<th>腾讯视频连接</th>
<th>排序</th>
<th>操作</th>
<th>创建时间</th>
</tr>
... ... @@ -63,10 +64,12 @@ if(!isset($condition['backState']))
</td>
<td><?php echo $video->room_id;?></td>
<td><?php echo $video->url;?></td>
<td><?php echo $video->sort;?></td>
<td style="white-space:nowrap">
<div class="form-group" videoId="<?php echo $video->id;?>">
<button class="btn btn-primary">编辑</button>
<button class="btn btn-warning btn-metro" status="<?php echo $video->status;?>"><?php echo $video->status? '关闭':'开启';?></button>
<a class="btn btn-danger btn-metro" onclick="return confirm('删除该视频?')" href="/live/videodel/<?=$video->id?>" >删除</a>
</div>
</td>
<td><?php echo date('Y-m-d H:i:s', $video->create_time)?></td>
... ...
... ... @@ -26,10 +26,12 @@ use backend\widgets\YHGImage\Common\Images as CommonImages;
<div class="col-sm-5">
<div class="col-sm-9">
<?=$uploader?>
<?php if ($video->pic):?>
<div class="file-item thumbnail upload-state-done">
<img src="<?php echo CommonImages::getImageUrl($video->pic, 200, 200)?>">
<div class="info">当前图片</div>
<img src="<?php echo CommonImages::getImageUrl($video->pic, 200, 200)?>">
<div class="info">当前图片</div>
</div>
<?php endif;?>
</div>
</div>
</div>
... ... @@ -39,6 +41,33 @@ use backend\widgets\YHGImage\Common\Images as CommonImages;
<input type="text" name="url" class="form-control" value="<?php echo $video->url;?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">直播中排序: </label>
<div class="col-sm-3">
<input type="text" name="sort" class="form-control" value="<?=$video->sort?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">分享主图: </label>
<div class="col-sm-9">
<?=$sharePicUploader?>
<?php if ($video->id && $videoShare['pic']):?>
<div class="file-item thumbnail upload-state-done" id="share_pic"><img src="<?=CommonImages::getImageUrl($videoShare['pic'], 110, 110)?>"><div class="info">当前图片</div></div>
<?php endif;?>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">分享标题: </label>
<div class="col-sm-9">
<input type="text" name="share_title" class="form-control" value="<?php echo ($video->id && $videoShare['title']) ? $videoShare['title']:''?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">分享内容: </label>
<div class="col-sm-9">
<textarea rows="5" name="share_content" class="form-control"><?php echo ($video->id && $videoShare['content']) ? $videoShare['content']:''?></textarea>
</div>
</div>
</div><!-- row -->
</div><!-- panel-body -->
<div class="panel-footer">
... ...
... ... @@ -28,7 +28,8 @@ class Environmen{
Yii::setAlias('@admin', 'http://admin.live.yoho.cn');
Yii::setAlias('@api', 'http://api.live.yoho.cn');
define('news_domain','http://newboys.yoho.cn/');
define('NEWS_DOMAIN','http://newboys.yoho.cn/');
define('YOHOBUY_H5_DOMAIN','http://m.yohobuy.com');
}
/**
... ... @@ -39,7 +40,8 @@ class Environmen{
Yii::setAlias('@admin', 'http://testadmin.live.yoho.cn');
Yii::setAlias('@api', 'http://testapi.live.yoho.cn');
define('news_domain','http://newboys.test.yoho.cn/');
define('NEWS_DOMAIN','http://newboys.test.yoho.cn/');
define('YOHOBUY_H5_DOMAIN','http://m.yohobuy.com');
}
}
Environmen::ENV();
... ... @@ -85,6 +87,15 @@ class Params {
*/
const UN_FORBID = 0;
const IS_FORBID = 1;
/**
* 直播分享类型
*/
const LIVE_SHARE_TYPE = 1;
/**
* 回看分享类型
*/
const VIDEO_SHARE_TYPE = 2;
}
return [
... ... @@ -143,5 +154,5 @@ return [
'failed_code'=>8001,
//异常状态
'exception_code'=>500,
'news_domain'=>news_domain,
'news_domain'=>NEWS_DOMAIN,
];
... ...
... ... @@ -37,7 +37,7 @@ class Room extends \yii\db\ActiveRecord
public function rules()
{
return [
[['room_id', 'master_id', 'starting_time', 'best', 'vest', 'living', 'status', 'create_time', 'update_time'], 'integer'],
[['room_id', 'master_id', 'starting_time', 'best', 'vest', 'living', 'status', 'unstart_sort', 'living_sort', 'create_time', 'update_time'], 'integer'],
[['title', 'watermark'], 'string', 'max' => 100],
[['app', 'secret'], 'string', 'max' => 50],
[['pic', 'background_pic'], 'string', 'max' => 255],
... ...
<?php
namespace common\models;
use Yii;
use common\config\Params;
use backend\widgets\YHGImage\Common\Images as CommonImages;
/**
* This is the model class for table "{{%share}}".
*
* @property integer $id
* @property integer $obj_id
* @property integer $type
* @property string $title
* @property string $content
* @property integer $create_time
* @property integer $update_time
*/
class Share extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%share}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['obj_id', 'type', 'create_time', 'update_time'], 'integer'],
[['content'], 'string'],
[['pic'], 'string', 'max' => 200],
[['title'], 'string', 'max' => 100],
[['obj_id', 'type'], 'unique', 'targetAttribute' => ['obj_id', 'type'], 'message' => 'The combination of Obj ID and Type has already been taken.'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'obj_id' => 'Obj ID',
'type' => 'Type',
'pic' => '分享头图',
'title' => '分享标题',
'content' => '分享内容',
'create_time' => 'Create Time',
'update_time' => 'Update Time',
];
}
public function getLivingShare($room_id)
{
return $this->get($room_id, Params::LIVE_SHARE_TYPE);
}
public function getVideoShare($video_id)
{
return $this->get($video_id, Params::VIDEO_SHARE_TYPE);
}
private function get($obj_id, $type)
{
$ret = [
'share_pic' => 'http://img11.static.yhbimg.com/global/2016/08/17/18/01f17a9cd44149052482e4ee58e590cf1b.png?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80',
'share_url' => ($type == Params::LIVE_SHARE_TYPE) ? YOHOBUY_H5_DOMAIN.'/activity/live/' . $obj_id : YOHOBUY_H5_DOMAIN.'/activity/live/replay/' . $obj_id,
'share_title' => '有货潮流新品节直播开始啦,快来看!',
'share_content' => 'YO\'HOOD嘉年华现场火热直播中,明星潮牌等你来!',
];
if ($model = self::findOne(['obj_id' => $obj_id, 'type' => $type])) {
$ret['share_pic'] = CommonImages::getTemplateComplex($model->pic, 2);
$ret['share_title'] = $model->title;
$ret['share_content'] = $model->content;
}
return $ret;
}
}
... ...
... ... @@ -6,6 +6,7 @@ use Yii;
use common\lib\QcloudApi\Client as QcloudApiClient;
use common\lib\QcloudApi\QcloudApi as Qapi;
use common\lib\YohonowApi\Request as YHNowApiReq;
use common\config\Params;
/**
* This is the model class for table "{{%video}}".
... ... @@ -115,26 +116,21 @@ class Video extends \yii\db\ActiveRecord
{
$transaction = $this->getDb()->beginTransaction();
try {
/*$qchannel = (new \yii\db\Query())
->select('channel_id')
->from('tbl_room_qchannel')
->where(['room_id' => $room_id])
->one();*/
$room = (new \yii\db\Query())
->select('app,title,master_id')
->select('app,title,master_id,status')
->from('tbl_room')
->where(['room_id' => $room_id])
->one();
$time = time();
//此处有bug,channel_id必须要转成字符串,不然底层会转换成科学计数法的格式
//$ret = QcloudApiClient::self()->CreateRecord(strval($qchannel['channel_id']), date('Y-m-d H:i:s',time()+120), '');
//file_put_contents("/tmp/live.log",date('Y-m-d H:i:s')."|start ".var_export($ret,true),FILE_APPEND)."\n";
if (1) {//$ret['code'] == 0
if(!$room['status']){
throw new \Exception("该房间已被禁用,请联系管理员");
}
if (1) {
$this->setAttributes([
'app' => $room['app'],
'task_id' => 0,//$ret['task_id']
'live_title' => $room['title'],
'live_start_time' => $time,
'live_start_time' => time(),
'live_end_time' => 0,
'master_id' => $room['master_id'],
'room_id' => $room_id,
... ... @@ -145,7 +141,7 @@ class Video extends \yii\db\ActiveRecord
}
//更新房间主表直播状态
$result = Yii::$app->db->createCommand()
->update('{{%room}}', ['living' => 1,'update_time'=>time()], ['room_id' => $room_id])
->update('{{%room}}', ['living' => Params::LIVING,'update_time'=>time()], ['room_id' => $room_id])
->execute();
if (!$result) {
throw new \Exception('tbl_room update error');
... ... @@ -189,40 +185,38 @@ class Video extends \yii\db\ActiveRecord
{
$transaction = $this->getDb()->beginTransaction();
try {
/*$qchannel = (new \yii\db\Query())
->select('channel_id')
->from('tbl_room_qchannel')
->where(['room_id' => $room_id])
->one();*/
$video = $this->find()
->where(['room_id' => $room_id, 'live_end_time' => 0])
->orderBy(['live_start_time' => SORT_DESC])
->one();
if ($video) {
//此处有bug,channel_id必须要转成字符串,不然底层会转换成科学计数法的格式
//$ret = QcloudApiClient::self()->StopRecord(strval($qchannel['channel_id']), $video['task_id']);
//file_put_contents("/tmp/live.log",date('Y-m-d H:i:s')."|stop ".var_export($ret,true),FILE_APPEND)."\n";
$room = (new \yii\db\Query())
->select('app,title,master_id')
->from('tbl_room')
->where(['room_id' => $room_id])
->one();
if (1) {//$ret['code'] == 0
if (1) {
$video->setAttributes([
'live_end_time' => time(),
]);
if (!$video->update()) {
throw new \Exception(current($this->getFirstErrors()));
}
$living_status = 2;
$updateFields = [
'living' => Params::LIVE_END,
'update_time' => time(),
'unstart_sort' => 0,
'living_sort' => 0
];
//更新房间主表直播状态
$result = Yii::$app->db->createCommand()
->update('{{%room}}', ['living' => $living_status,'update_time'=>time()], ['room_id' => $room_id])
->update('{{%room}}', $updateFields, ['room_id' => $room_id])
->execute();
if (!$result) {
throw new \Exception('tbl_room update error');
}
//该房间如果包含资讯业务线,那么要更新资讯那边状态
if(in_array(\common\config\Params::YOHONOW,explode(',',$room['app']))){
$news_ret = YHNowApiReq::getInstance()->setLiveStat($room_id,0);
... ...
... ... @@ -8,6 +8,7 @@ use common\models\Room;
use common\models\Video;
use common\models\LiveComment;
use common\models\RoomNums;
use common\models\Share;
class LivingController extends BaseController
{
... ... @@ -61,7 +62,10 @@ class LivingController extends BaseController
$key = __CLASS__.__FUNCTION__.'app'.$this->app;
if (!$ret = $this->cache->get($key)){
$ret = Room::find()->with(['master','roomNums'])->where(['and',['living'=>1],"find_in_set({$this->app},app)"])->joinWith('roomNums rn')->orderBy(['rn.online_num'=>SORT_DESC])->all();
$ret = Room::find()->with(['master','roomNums'])->where(['and',['living'=>1],"find_in_set({$this->app},app)"])
->joinWith('roomNums rn')
->orderBy(['living_sort'=>SORT_DESC,'rn.online_num'=>SORT_DESC])
->all();
foreach ($ret as $k=>$model){
$row = [
... ... @@ -112,7 +116,10 @@ class LivingController extends BaseController
$key = __CLASS__.__FUNCTION__.'app'.$this->app;
if (!$ret = $this->cache->get($key)){
$ret = Room::find()->with(['master'])->where(['and',['living'=>0],['!=','starting_time',0],"find_in_set({$this->app},app)"])->orderBy(['starting_time'=>SORT_ASC])->all();
$ret = Room::find()->with(['master'])
->where(['and',['living'=>0],['!=','starting_time',0],"find_in_set({$this->app},app)"])
->orderBy(['unstart_sort'=>SORT_DESC,'starting_time'=>SORT_ASC])
->all();
foreach ($ret as $k=>$model){
$row = [
... ... @@ -152,7 +159,10 @@ class LivingController extends BaseController
$key = __CLASS__.__FUNCTION__.'app'.$this->app;
if (!$ret = $this->cache->get($key)){
$ret = Video::find()->with(['master'])->where(['and',['status' => 1],['not', ['url' => null]],['not', ['url' => '']],"find_in_set({$this->app},app)"])->orderBy(['create_time'=>SORT_DESC])->all();
$ret = Video::find()->with(['master'])
->where(['and',['status' => 1],['not', ['url' => null]],['not', ['url' => '']],"find_in_set({$this->app},app)"])
->orderBy(['sort'=>SORT_DESC,'create_time'=>SORT_DESC])
->all();
foreach ($ret as $k=>$model){
$row = [
... ... @@ -267,10 +277,9 @@ class LivingController extends BaseController
}
$ret['background_pic'] = $ret['background_pic'] ? : 'http://img11.static.yhbimg.com/global/2016/08/17/18/01f17a9cd44149052482e4ee58e590cf1b.png';
$ret['share_url'] = 'http://m.yohobuy.com/activity/live/'.$room_id;
$ret['share_title'] = '有货潮流新品节直播开始啦,快来看!';
$ret['share_content'] = 'YO\'HOOD嘉年华现场火热直播中,明星潮牌等你来!';
$share = (new Share)->getLivingShare($room_id);
$ret += $share;
$dependency = new \yii\caching\DbDependency(['sql' => Yii::$app->db
->createCommand('SELECT update_time FROM {{%room}} WHERE room_id=:room_id')
->bindValue(':room_id', $room_id)
... ... @@ -320,9 +329,8 @@ class LivingController extends BaseController
}
$ret['background_pic'] = 'http://img11.static.yhbimg.com/global/2016/08/17/18/01f17a9cd44149052482e4ee58e590cf1b.png';
$ret['share_url'] = 'http://m.yohobuy.com/activity/live/replay/'.$video_id;
$ret['share_title'] = '有货潮流新品节直播开始啦,快来看!';
$ret['share_content'] = 'YO\'HOOD嘉年华现场火热直播中,明星潮牌等你来!';
$share = (new Share)->getVideoShare($video_id);
$ret += $share;
$dependency = new \yii\caching\DbDependency(['sql' => Yii::$app->db
->createCommand('SELECT update_time FROM {{%video}} WHERE id=:video_id')
... ...
... ... @@ -138,11 +138,6 @@ class RoomController extends BaseController
$this->renderJson($retArr['code'], $retArr['messsage']);
}
public function actionGetlivingroomid()
{
return [10000, 10001];
}
/**
* 获取禁言用户列表
*/
... ...