...
|
...
|
@@ -5,6 +5,7 @@ namespace common\models; |
|
|
use Yii;
|
|
|
use common\lib\QcloudApi\Client as QcloudApiClient;
|
|
|
use common\lib\QcloudApi\QcloudApi as Qapi;
|
|
|
use common\lib\YohonowApi\Request as YHNowApiReq;
|
|
|
|
|
|
/**
|
|
|
* This is the model class for table "{{%video}}".
|
...
|
...
|
@@ -114,11 +115,11 @@ class Video extends \yii\db\ActiveRecord |
|
|
{
|
|
|
$transaction = $this->getDb()->beginTransaction();
|
|
|
try {
|
|
|
$qchannel = (new \yii\db\Query())
|
|
|
/*$qchannel = (new \yii\db\Query())
|
|
|
->select('channel_id')
|
|
|
->from('tbl_room_qchannel')
|
|
|
->where(['room_id' => $room_id])
|
|
|
->one();
|
|
|
->one();*/
|
|
|
$room = (new \yii\db\Query())
|
|
|
->select('app,title,master_id')
|
|
|
->from('tbl_room')
|
...
|
...
|
@@ -146,8 +147,20 @@ class Video extends \yii\db\ActiveRecord |
|
|
$result = Yii::$app->db->createCommand()
|
|
|
->update('{{%room}}', ['living' => 1,'update_time'=>time()], ['room_id' => $room_id])
|
|
|
->execute();
|
|
|
$cache_prefix = Yii::$app->params['cache_prefix'];
|
|
|
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,1);
|
|
|
if(!$news_ret){
|
|
|
throw new \Exception(YHNowApiReq::getInstance()->errors);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/*------------清除弹幕相关redis--------------*/
|
|
|
$cache_prefix = Yii::$app->params['cache_prefix'];
|
|
|
//##主播app 向弹幕服务器发送开始命令时也清除,这里也清除是为了防止弹幕服务器连不上没有清掉
|
|
|
//清掉在线马甲数
|
|
|
Yii::$app->redisIm->del(sprintf($cache_prefix . ":vestnum_%s", $room_id));
|
...
|
...
|
@@ -158,9 +171,6 @@ class Video extends \yii\db\ActiveRecord |
|
|
//清直播状态
|
|
|
Yii::$app->redisIm->del(sprintf($cache_prefix . ":play_stat_room_%s", $room_id));
|
|
|
/*------------清除弹幕相关redis--------------*/
|
|
|
if (!$result) {
|
|
|
throw new \Exception('tbl_room update error');
|
|
|
}
|
|
|
$transaction->commit();
|
|
|
return true;
|
|
|
} else {
|
...
|
...
|
@@ -181,11 +191,6 @@ class Video extends \yii\db\ActiveRecord |
|
|
->from('tbl_room_qchannel')
|
|
|
->where(['room_id' => $room_id])
|
|
|
->one();*/
|
|
|
$room = (new \yii\db\Query())
|
|
|
->select('starting_time')
|
|
|
->from('tbl_room')
|
|
|
->where(['room_id' => $room_id])
|
|
|
->one();
|
|
|
$video = $this->find()
|
|
|
->where(['room_id' => $room_id, 'live_end_time' => 0])
|
|
|
->orderBy(['live_start_time' => SORT_DESC])
|
...
|
...
|
@@ -194,6 +199,11 @@ class Video extends \yii\db\ActiveRecord |
|
|
//此处有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
|
|
|
$video->setAttributes([
|
|
|
'live_end_time' => time(),
|
...
|
...
|
@@ -210,6 +220,13 @@ class Video extends \yii\db\ActiveRecord |
|
|
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);
|
|
|
if(!$news_ret){
|
|
|
throw new \Exception(YHNowApiReq::getInstance()->errors);
|
|
|
}
|
|
|
}
|
|
|
$transaction->commit();
|
|
|
return true;
|
|
|
} else {
|
...
|
...
|
|