Authored by xiaofeng.yao@yoho.cn

Merge branch 'feature/redmin13115' into test

... ... @@ -4,6 +4,7 @@ namespace backend\controllers;
use Yii;
use common\components\cachekey\Parser;
use common\config\Params;
use common\models\Video;
/**
* Ajax controller
*/
... ... @@ -26,11 +27,21 @@ class AjaxController extends BaseController
{
$room_id = Yii::$app->request->get('room_id');
//更新房间主表直播状态
/*//更新房间主表直播状态
$living_status = Params::LIVE_END;
$result = Yii::$app->db->createCommand()
->update('{{%room}}', ['living' => $living_status,'update_time'=>time()], ['room_id' => $room_id])
->execute();
$this->renderJson(Yii::$app->params['success_code'],'',$room_id);
->execute();*/
try {
$model = new Video();
$result = $model->setVideoStop($room_id);
if($result){
$this->renderJson(Yii::$app->params['success_code'],'结束成功',$room_id);
}else{
$this->renderJson(Yii::$app->params['failed_code'],'结束失败');
}
} catch (\Exception $e){
$this->renderJson(Yii::$app->params['failed_code'],$e->getMessage(),'');
}
}
}
... ...
... ... @@ -5,6 +5,8 @@ use Yii;
use backend\components\Pagination;
use app\models\Forbidden;
use app\models\Room;
use yii\helpers\ArrayHelper;
/**
* Live controller
*/
... ... @@ -19,6 +21,7 @@ class ForbiddenController extends BaseController
{
$model = Forbidden::find();
$filter = Yii::$app->request->get();
$filter = ArrayHelper::filter($filter,['room_id','name','uid']);
$room_id = $filter['room_id'];
if($room_id){
//获取房间数据
... ... @@ -27,7 +30,6 @@ class ForbiddenController extends BaseController
die('房间不存在');
}
if ($filter) {
// var_dump($filter);
foreach ($filter as $field => $value) {
if ($field == 'name') {
if (!empty($value)) {
... ... @@ -40,12 +42,8 @@ class ForbiddenController extends BaseController
}
}
}
//获取房间数据
$room = Room::findOne(['room_id'=>$room_id]);
$count = clone $model;
$pagination = new Pagination(['totalCount' => $count->count()]);
$list = $model->offset($pagination->offset)->limit($pagination->limit)->orderBy(['create_time' => SORT_DESC])->all();
return $this->render('index', [
'filter' => $filter ?: [],
... ... @@ -132,7 +130,7 @@ class ForbiddenController extends BaseController
$room_id = $gets['room_id'];
if($room_id) {
//$sqlwhere = ['cmd' => 5];
$sqlwhere = ['room_id'=>$room_id];
$sqlwhere = ['room_id'=>$room_id,'cmd' => 5];
$count = (new \yii\db\Query())
->from($this->getTableName($room_id))
->where($sqlwhere)
... ...
... ... @@ -388,6 +388,8 @@ class LiveController extends BaseController
case 'enable'://启用直播间
$r = $model->status(1);
break;
case 'start'://开始直播
$r = (new \common\models\Video)->setVideoStart($model->room_id);
default:
break;
}
... ...
... ... @@ -70,7 +70,8 @@ class SystemController extends BaseController
}
}
public function actionVest(){
public function actionVest()
{
$cache_prefix = Yii::$app->params['cache_prefix'];
$imVestNums = Yii::$app->redisIm->llen($cache_prefix.'vest_users');
if(Yii::$app->request->isAjax){
... ... @@ -101,5 +102,61 @@ class SystemController extends BaseController
return $this->render('vest',['imVestNums'=>$imVestNums]);
}
public function actionGetaudnums()
{
$cache_prefix = Yii::$app->params['cache_prefix'];
$room_id = trim(Yii::$app->request->post('room_id'));
$ret = [
'audience'=>0,
'like'=>0,
'addup'=>0,
];
if($room_id) {
$keys = [
'audience'=>$cache_prefix.'audience_nums_room_'.$room_id,
'like'=>$cache_prefix.'like_numbers_room_'.$room_id,
'addup'=>$cache_prefix.'addup_num_'.$room_id,
];
$index = array_keys($keys);
$values = $keys ? call_user_func_array(array(Yii::$app->redisIm,'mget'), $keys) : [];
foreach ($values as $k=>$v) {
$ret[$index[$k]] = $v ? :0;
}
}
$data = [
'code'=>'200',
'msg'=>'',
'data'=>$ret
];
echo json_encode($data);exit;
}
public function actionModifycache()
{
$cache_prefix = Yii::$app->params['cache_prefix'];
$room_id = trim(Yii::$app->request->post('room_id'));
$cache_key = trim(Yii::$app->request->post('cache_key'));
$cache_val = trim(Yii::$app->request->post('cache_val'));
if($room_id && $cache_key && $cache_val){
$expire = 86400;
if($cache_key == 'addup'){
$res = Yii::$app->redisIm->setex($cache_prefix.'addup_num_'.$room_id,$expire,$cache_val);
}
if($cache_key == 'like'){
$res = Yii::$app->redisIm->setex($cache_prefix.'like_numbers_room_'.$room_id,$expire,$cache_val);
}
$data = [
'code'=>'200',
'msg'=>'修改成功',
'data'=>$res
];
}else{
$data = [
'code'=>'400',
'msg'=>'参数不能为空',
'data'=>''
];
}
echo json_encode($data);exit;
}
}
... ...
... ... @@ -39,7 +39,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', 'is_addup', 'living', 'status', 'create_time', 'update_time'], 'integer'],
[['title', 'watermark'], 'string', 'max' => 100],
[['app', 'secret'], 'string', 'max' => 50],
[['pic', 'background_pic'], 'string', 'max' => 255],
... ... @@ -234,7 +234,11 @@ class Room extends \yii\db\ActiveRecord
throw new \Exception('精选房间上限是2个');
}
}
if (isset($data['is_addup'])){
$data['is_addup'] = Yii::$app->params['config']['is_addup'];
}else{
$data['is_addup'] = 0;
}
$this->setAttributes($data);
if (!$this->save()){
throw new \Exception(current($this->getFirstErrors()));
... ... @@ -298,8 +302,8 @@ class Room extends \yii\db\ActiveRecord
if ($status == 1){//启用时,直播状态设为未开始
$model->living = 0;
}elseif ($status == 0){//禁用时,直播状态设为已结束
$model->living = 2;
if ($model->videoRecording){
//fixbug 只有正在直播中的房间才会把视频片段设置观看人数 add by yaoxiaofeng|2016.9.29
if ($model->living == 1 && $model->videoRecording){
//停止正在录制的视频
$roomNums = \common\models\RoomNums::getRoomNums($model->room_id);
$model->videoRecording->audience_num = $roomNums['audience_nums'];
... ... @@ -307,6 +311,7 @@ class Room extends \yii\db\ActiveRecord
$model->videoRecording->live_end_time = time();
$model->videoRecording->save();
}
$model->living = 2;
}
if (!$model->save(false)){
throw new \Exception(current($model->getFirstErrors()));
... ...
... ... @@ -81,7 +81,7 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
<th>预告开始时间</th>
<th>房间密钥</th>
<th>是否精选</th>
<th>马甲状态</th>
<th>马甲状态|人数累加</th>
<th>直播状态</th>
<th>在线人数</th>
<th>操作</th>
... ... @@ -99,7 +99,12 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
<td style="white-space:nowrap"><?=$model->starting_time ? date('Y-m-d H:i:s',$model->starting_time) : ''?></td>
<td><?=$model->secret?></td>
<td><?=Yii::$app->params['config']['best'][$model->best]?></td>
<td><?=Yii::$app->params['config']['vest'][$model->vest]?></td>
<td>
<?php
$is_addup = $model->is_addup == Yii::$app->params['config']['is_addup'] ? "是":"否";
echo Yii::$app->params['config']['vest'][$model->vest]."|".$is_addup;
?>
</td>
<td><?=Yii::$app->params['config']['room_living'][$model->living]?></td>
<td>
真实:<?=@$model->roomNums->online_num ? :0?>,
... ... @@ -110,6 +115,8 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
<span>
<?php if ($model->living == 1)://直播中?>
<button type="button" onclick="stopLiving(<?=$model->room_id?>)" class="btn btn-danger btn-metro">结束直播</button>
<?php else:?>
<a onclick="return confirm('将房间设为直播中状态,确定?')" href="/live/roomoperate/<?=$model->id?>?type=start" class="btn btn-success btn-metro">开始直播</a>
<?php endif;?>
</span>
... ...
... ... @@ -107,6 +107,9 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
<div class="col-sm-2">
<?php echo Html::dropDownList('vest', $model->vest,Yii::$app->params['config']['vest'], ['class' => 'form-control']);?>
</div>
<div class="col-sm-2">
累加人数:<?php echo Html::checkbox('is_addup', $model->is_addup==Yii::$app->params['config']['is_addup'],['value'=>Yii::$app->params['config']['is_addup']])?>
</div>
</div>
<div class="form-group" style="display: none">
... ...
... ... @@ -5,10 +5,11 @@ $this->title = '管理后台首页';
?>
<div class="col-md-6">
<p><span>剩余马甲数:</span><?php echo $imVestNums?></p>
<div class="panel panel-default">
<div class="panel-heading">
<h5 class="panel-title">导入马甲</h5>
<p>剩余马甲数:<?php echo $imVestNums?></p>
</div>
<div class="panel-body">
... ... @@ -30,12 +31,59 @@ $this->title = '管理后台首页';
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h5 class="panel-title">查看观看人数</h5>
</div>
<div class="panel-body">
<div class="form-group">
<label class="col-sm-3 control-label">请输入房间号:</label>
<div class="col-sm-3">
<input type="text" class="form-control" id="room_id" name="room_id" >
</div>
<div class="col-sm-4">
<button type="button" class="btn btn-primary mr5" id="search_audi_btn">查询</button>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">观看数:</label>
<div class="col-sm-2">
<input type="text" class="form-control" id="actual_num" disabled>
</div>
<div class="col-sm-1">
+
</div>
<div class="col-sm-2">
<input type="text" class="form-control" id="addup_num">
</div>
<div class="col-sm-1">
*10 =
</div>
<div class="col-sm-2">
<input type="text" class="form-control" id="result_num" disabled>
</div>
<div class="col-sm-1">
<button type="button" class="btn btn-primary" id="modify_addup_btn">修改</button>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">点赞数:</label>
<div class="col-sm-3">
<input type="text" class="form-control" id="like_num">
</div>
<div class="col-sm-1">
<button type="button" class="btn btn-primary" id="modify_like_btn">修改</button>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-6">
马甲库里总共可用马甲为4902条,如果要全部导入,须分5批导入,每批1000条
offset:导入马甲的起始序号,第一次填0,后面会自动根据导入的批量累加<br>
limit:每批次导入马甲的数量<br>
(ps:不会的不要乱添加,否则后果自负!!!)<br>
<p>马甲库里总共可用马甲为4902条,如果要全部导入,须分5批导入,每批1000条</p>
<p>offset:导入马甲的起始序号,第一次填0,后面会自动根据导入的批量累加</p>
<p>limit:每批次导入马甲的数量</p>
<p>(ps:不会的不要乱添加,否则后果自负!!!)</p>
</div>
<script>
$(function(){
... ... @@ -59,5 +107,48 @@ $this->title = '管理后台首页';
$("#btn_bar").html(import_html);
},'json');
});
//查询房间信息
$('#search_audi_btn').live("click",function(){
var room_id = $('#room_id').val();
if(room_id == '')
return;
$.post("/system/getaudnums",{room_id:room_id},function(data){
if(data.code==200){
var values = data.data;
$("#actual_num").val(values.audience);
$("#addup_num").val(values.addup);
$("#result_num").val(Number(values.audience)+Number(values.addup)*10);
$("#like_num").val(values.like);
}
},'json')
});
//修改观看数
$('#modify_addup_btn').live("click",function(){
var room_id = $('#room_id').val();
var addup_num = $('#addup_num').val();
if(room_id == '')
return;
modify_cache(room_id,'addup',addup_num);
});
//修改点赞数
$('#modify_like_btn').live("click",function(){
var room_id = $('#room_id').val();
var like_num = $('#like_num').val();
if(room_id == '')
return;
modify_cache(room_id,'like',like_num);
});
function modify_cache(room_id,cache_key,cache_val) {
$.post("/system/modifycache",{room_id:room_id,cache_key:cache_key,cache_val:cache_val},function(data){
if(data.code==200) {
alert(data.msg);
}else {
alert(data.msg);
}
},'json')
}
});
</script>
\ No newline at end of file
... ...
... ... @@ -57,6 +57,8 @@ return [
'un_forbid_stat'=>0,
//被禁言状态
'is_forbid_stat'=>1,
//累加人数
'is_addup'=>1,
],
/**
* 分页每页数目
... ... @@ -76,5 +78,5 @@ return [
'failed_code'=>8001,
//异常状态
'exception_code'=>500,
'news_domain'=>'http://newboys.test.yoho.cn/',
'news_domain'=>'http://new.yohoboys.com/',
];
... ...
... ... @@ -167,9 +167,11 @@ class Video extends \yii\db\ActiveRecord
//清在线观看数
Yii::$app->redisIm->del(sprintf($cache_prefix . "audience_nums_room_%s", $room_id));
//清点赞数
//Yii::$app->redisIm->del(sprintf($cache_prefix . "like_numbers_room_%s", $room_id));
Yii::$app->redisIm->del(sprintf($cache_prefix . "like_numbers_room_%s", $room_id));
//清直播状态
Yii::$app->redisIm->del(sprintf($cache_prefix . "play_stat_room_%s", $room_id));
//清房间观看虚假累加值
Yii::$app->redisIm->del(sprintf($cache_prefix . "addup_num_%s", $room_id));
/*------------清除弹幕相关redis--------------*/
$transaction->commit();
return true;
... ...
... ... @@ -15,8 +15,10 @@ if (!YII_ENV_TEST) {
$config['modules']['8FmTQbUC'] = [
'class' => 'yii\debug\Module',
'allowedIPs' => ['*'],
'historySize'=> 100000,
'dataPath' => is_dir('/dev/shm') ? '/dev/shm/debug' : '@runtime/debug',
'historySize'=> 2000,
//'dataPath' => is_dir('/dev/shm') ? '/dev/shm/debug' : '@runtime/debug',
'dataPath' => sys_get_temp_dir().'/debug',
'enableDebugLogs' => true,
];
}
... ...
... ... @@ -9,6 +9,10 @@ use Yii;
class IndexController extends BaseController
{
public function behaviors() {
return [];
}
/**
* @inheritdoc
*/
... ... @@ -23,7 +27,6 @@ class IndexController extends BaseController
public function actionIndex()
{
echo __FILE__;
exit;
}
... ...
... ... @@ -291,6 +291,7 @@ class RoomController extends BaseController
$row = [
'room_id'=>(int)$model->room_id,
'vest'=>$model->vest,
'is_addup'=>$model->is_addup
];
$list[$k] = $row;
}
... ...