...
|
...
|
@@ -175,7 +175,8 @@ class LivingController extends BaseController |
|
|
'url'=>$model->url,
|
|
|
'live_title'=>$model->live_title,
|
|
|
'live_room_id'=>(int)$model->room_id,
|
|
|
'audience_num'=>(int)($model->audience_num+$model->replay_num),
|
|
|
'audience_num'=>(int)$model->audience_num,
|
|
|
'replay_num'=>(int)$model->replay_num,
|
|
|
'create_time'=>(int)$model->create_time,
|
|
|
];
|
|
|
$ret[$k] = $row;
|
...
|
...
|
@@ -186,15 +187,17 @@ class LivingController extends BaseController |
|
|
->bindValue(':app', $this->app)
|
|
|
->getRawSql()]);
|
|
|
$this->cache->set($key, $ret, Yii::$app->params['defaultCacheExpire'], $dependency);
|
|
|
}else{
|
|
|
}
|
|
|
|
|
|
$keys = [];
|
|
|
foreach ($ret as $k=>$row){
|
|
|
$keys[] = sprintf("%svideo_id_%s_audience_num",Yii::$app->params['cache_prefix'],$row['video_id']);
|
|
|
$keys[] = sprintf("%svideo_id_%s_replay_num",Yii::$app->params['cache_prefix'],$row['video_id']);
|
|
|
}
|
|
|
$values = $keys ? call_user_func_array(array(Yii::$app->redis,'mget'), $keys) : [];
|
|
|
foreach ($values as $k=>$value){
|
|
|
$ret[$k]['audience_num'] = (int)($value ? : $ret[$k]['audience_num']);
|
|
|
}
|
|
|
foreach ($ret as $k=>$row){
|
|
|
$replay_num = (int)(@$values[$k] ? : $ret[$k]['replay_num']);
|
|
|
$ret[$k]['audience_num'] += $replay_num;
|
|
|
$ret[$k]['replay_num'] = $replay_num;
|
|
|
}
|
|
|
|
|
|
$this->renderJson(Yii::$app->params['success_code'],'',$ret);
|
...
|
...
|
@@ -307,7 +310,8 @@ class LivingController extends BaseController |
|
|
'watermark'=>'',
|
|
|
'url'=>$model->url,
|
|
|
'like_num'=>(int)$model->like_num,
|
|
|
'audience_num'=>(int)($model->audience_num+$model->replay_num),
|
|
|
'audience_num'=>(int)$model->audience_num,
|
|
|
'replay_num'=>(int)$model->replay_num,
|
|
|
'live_title'=>$model->live_title,
|
|
|
'live_start_time'=>(int)$model->live_start_time,
|
|
|
'live_end_time'=>(int)$model->live_end_time,
|
...
|
...
|
@@ -340,17 +344,23 @@ class LivingController extends BaseController |
|
|
}
|
|
|
|
|
|
//缓存回放观看人数
|
|
|
$key = sprintf("%svideo_id_%s_audience_num",Yii::$app->params['cache_prefix'],$video_id);
|
|
|
if (!$audience_num = Yii::$app->redis->get($key)){
|
|
|
$audience_num = (int)$ret['audience_num'];
|
|
|
Yii::$app->redis->setex($key, Yii::$app->params['defaultCacheExpire']*2, $audience_num);
|
|
|
$key = sprintf("%svideo_id_%s_replay_num",Yii::$app->params['cache_prefix'],$video_id);
|
|
|
if (!$replay_num = (int)Yii::$app->redis->get($key)){
|
|
|
$replay_num = (int)$ret['replay_num'];
|
|
|
Yii::$app->redis->set($key, $replay_num);
|
|
|
}
|
|
|
$ret['audience_num'] = $audience_num;
|
|
|
//$ret['audience_num'] = $audience_num;
|
|
|
|
|
|
//观看回放人数+1
|
|
|
if (Video::updateAllCounters(['replay_num' => 1],['id'=>$video_id]) && Yii::$app->redis->incr($key)){
|
|
|
/*if (Video::updateAllCounters(['replay_num' => 1],['id'=>$video_id]) && Yii::$app->redis->incr($key)){
|
|
|
$ret['audience_num'] += 1;
|
|
|
}*/
|
|
|
|
|
|
if (Yii::$app->redis->incr($key)){
|
|
|
$replay_num += 1;
|
|
|
}
|
|
|
$ret['audience_num'] += $replay_num;
|
|
|
$ret['replay_num'] = $replay_num;
|
|
|
|
|
|
$this->renderJson(Yii::$app->params['success_code'],'',$ret);
|
|
|
}else
|
...
|
...
|
|