...
|
...
|
@@ -87,16 +87,19 @@ class LivingController extends BaseController |
|
|
->getRawSql()]);
|
|
|
$this->cache->set($key, json_encode($ret), Yii::$app->params['defaultCacheExpire'], $dependency);
|
|
|
}else{
|
|
|
Yii::$app->db->cache(function() use (&$ret){
|
|
|
$models = Yii::$app->db->cache(function(){
|
|
|
return RoomNums::find()->indexBy('room_id')->all();
|
|
|
},60);
|
|
|
if ($models){
|
|
|
$_ret = json_decode($ret,true);
|
|
|
$models = RoomNums::find()->indexBy('room_id')->all();
|
|
|
foreach ($_ret as $k=>$row){
|
|
|
if (!empty($models[$row['room_id']]->online_num)){
|
|
|
$row['audience_num'] = (int)$models[$row['room_id']]->online_num;//在线人数
|
|
|
}
|
|
|
$_ret[$k] = $row;
|
|
|
}
|
|
|
}, 60);
|
|
|
$ret = $_ret;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
@@ -170,16 +173,19 @@ class LivingController extends BaseController |
|
|
->getRawSql()]);
|
|
|
$this->cache->set($key, json_encode($ret), Yii::$app->params['defaultCacheExpire'], $dependency);
|
|
|
}else{
|
|
|
Yii::$app->db->cache(function() use (&$ret){
|
|
|
$models = Yii::$app->db->cache(function(){
|
|
|
return Video::find()->indexBy('id')->all();
|
|
|
},60);
|
|
|
if ($models){
|
|
|
$_ret = json_decode($ret,true);
|
|
|
$models = Video::find()->indexBy('id')->all();
|
|
|
foreach ($_ret as $k=>$row){
|
|
|
if (!empty($models[$row['video_id']])){
|
|
|
$row['audience_num'] = (int)($models[$row['video_id']]->audience_num+$models[$row['video_id']]->replay_num);
|
|
|
}
|
|
|
$_ret[$k] = $row;
|
|
|
}
|
|
|
}, 60);
|
|
|
$ret = $_ret;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$this->renderJson(Yii::$app->params['success_code'],'',$ret);
|
...
|
...
|
@@ -262,17 +268,17 @@ class LivingController extends BaseController |
|
|
->bindValue(':room_id', $room_id)
|
|
|
->getRawSql()]);
|
|
|
$this->cache->set($key, json_encode($ret), Yii::$app->params['defaultCacheExpire'], $dependency);
|
|
|
}else{
|
|
|
Yii::$app->db->cache(function() use ($room_id,&$ret){
|
|
|
if (!$model = RoomNums::findOne(['room_id'=>$room_id])){
|
|
|
return;
|
|
|
}
|
|
|
}else{
|
|
|
$model = Yii::$app->db->cache(function() use ($room_id){
|
|
|
return RoomNums::findOne(['room_id'=>$room_id]);
|
|
|
},60);
|
|
|
if ($model){
|
|
|
$_ret = json_decode($ret,true);
|
|
|
$ret = array_merge($_ret,[
|
|
|
'like_num'=>(int)$model->like_num,
|
|
|
'audience_num'=>(int)$model->online_num,
|
|
|
]);
|
|
|
}, 60);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$this->renderJson(Yii::$app->params['success_code'],'',$ret);
|
...
|
...
|
|