|
@@ -175,7 +175,8 @@ class LivingController extends BaseController |
|
@@ -175,7 +175,8 @@ class LivingController extends BaseController |
175
|
'url'=>$model->url,
|
175
|
'url'=>$model->url,
|
176
|
'live_title'=>$model->live_title,
|
176
|
'live_title'=>$model->live_title,
|
177
|
'live_room_id'=>(int)$model->room_id,
|
177
|
'live_room_id'=>(int)$model->room_id,
|
178
|
- 'audience_num'=>(int)($model->audience_num+$model->replay_num),
|
178
|
+ 'audience_num'=>(int)$model->audience_num,
|
|
|
179
|
+ 'replay_num'=>(int)$model->replay_num,
|
179
|
'create_time'=>(int)$model->create_time,
|
180
|
'create_time'=>(int)$model->create_time,
|
180
|
];
|
181
|
];
|
181
|
$ret[$k] = $row;
|
182
|
$ret[$k] = $row;
|
|
@@ -186,15 +187,17 @@ class LivingController extends BaseController |
|
@@ -186,15 +187,17 @@ class LivingController extends BaseController |
186
|
->bindValue(':app', $this->app)
|
187
|
->bindValue(':app', $this->app)
|
187
|
->getRawSql()]);
|
188
|
->getRawSql()]);
|
188
|
$this->cache->set($key, $ret, Yii::$app->params['defaultCacheExpire'], $dependency);
|
189
|
$this->cache->set($key, $ret, Yii::$app->params['defaultCacheExpire'], $dependency);
|
189
|
- }else{
|
|
|
190
|
- $keys = [];
|
|
|
191
|
- foreach ($ret as $k=>$row){
|
|
|
192
|
- $keys[] = sprintf("%svideo_id_%s_audience_num",Yii::$app->params['cache_prefix'],$row['video_id']);
|
|
|
193
|
- }
|
|
|
194
|
- $values = $keys ? call_user_func_array(array(Yii::$app->redis,'mget'), $keys) : [];
|
|
|
195
|
- foreach ($values as $k=>$value){
|
|
|
196
|
- $ret[$k]['audience_num'] = (int)($value ? : $ret[$k]['audience_num']);
|
|
|
197
|
- }
|
190
|
+ }
|
|
|
191
|
+
|
|
|
192
|
+ $keys = [];
|
|
|
193
|
+ foreach ($ret as $k=>$row){
|
|
|
194
|
+ $keys[] = sprintf("%svideo_id_%s_replay_num",Yii::$app->params['cache_prefix'],$row['video_id']);
|
|
|
195
|
+ }
|
|
|
196
|
+ $values = $keys ? call_user_func_array(array(Yii::$app->redis,'mget'), $keys) : [];
|
|
|
197
|
+ foreach ($ret as $k=>$row){
|
|
|
198
|
+ $replay_num = (int)(@$values[$k] ? : $ret[$k]['replay_num']);
|
|
|
199
|
+ $ret[$k]['audience_num'] += $replay_num;
|
|
|
200
|
+ $ret[$k]['replay_num'] = $replay_num;
|
198
|
}
|
201
|
}
|
199
|
|
202
|
|
200
|
$this->renderJson(Yii::$app->params['success_code'],'',$ret);
|
203
|
$this->renderJson(Yii::$app->params['success_code'],'',$ret);
|
|
@@ -307,7 +310,8 @@ class LivingController extends BaseController |
|
@@ -307,7 +310,8 @@ class LivingController extends BaseController |
307
|
'watermark'=>'',
|
310
|
'watermark'=>'',
|
308
|
'url'=>$model->url,
|
311
|
'url'=>$model->url,
|
309
|
'like_num'=>(int)$model->like_num,
|
312
|
'like_num'=>(int)$model->like_num,
|
310
|
- 'audience_num'=>(int)($model->audience_num+$model->replay_num),
|
313
|
+ 'audience_num'=>(int)$model->audience_num,
|
|
|
314
|
+ 'replay_num'=>(int)$model->replay_num,
|
311
|
'live_title'=>$model->live_title,
|
315
|
'live_title'=>$model->live_title,
|
312
|
'live_start_time'=>(int)$model->live_start_time,
|
316
|
'live_start_time'=>(int)$model->live_start_time,
|
313
|
'live_end_time'=>(int)$model->live_end_time,
|
317
|
'live_end_time'=>(int)$model->live_end_time,
|
|
@@ -340,17 +344,23 @@ class LivingController extends BaseController |
|
@@ -340,17 +344,23 @@ class LivingController extends BaseController |
340
|
}
|
344
|
}
|
341
|
|
345
|
|
342
|
//缓存回放观看人数
|
346
|
//缓存回放观看人数
|
343
|
- $key = sprintf("%svideo_id_%s_audience_num",Yii::$app->params['cache_prefix'],$video_id);
|
|
|
344
|
- if (!$audience_num = Yii::$app->redis->get($key)){
|
|
|
345
|
- $audience_num = (int)$ret['audience_num'];
|
|
|
346
|
- Yii::$app->redis->setex($key, Yii::$app->params['defaultCacheExpire']*2, $audience_num);
|
347
|
+ $key = sprintf("%svideo_id_%s_replay_num",Yii::$app->params['cache_prefix'],$video_id);
|
|
|
348
|
+ if (!$replay_num = (int)Yii::$app->redis->get($key)){
|
|
|
349
|
+ $replay_num = (int)$ret['replay_num'];
|
|
|
350
|
+ Yii::$app->redis->set($key, $replay_num);
|
347
|
}
|
351
|
}
|
348
|
- $ret['audience_num'] = $audience_num;
|
352
|
+ //$ret['audience_num'] = $audience_num;
|
349
|
|
353
|
|
350
|
//观看回放人数+1
|
354
|
//观看回放人数+1
|
351
|
- if (Video::updateAllCounters(['replay_num' => 1],['id'=>$video_id]) && Yii::$app->redis->incr($key)){
|
355
|
+ /*if (Video::updateAllCounters(['replay_num' => 1],['id'=>$video_id]) && Yii::$app->redis->incr($key)){
|
352
|
$ret['audience_num'] += 1;
|
356
|
$ret['audience_num'] += 1;
|
|
|
357
|
+ }*/
|
|
|
358
|
+
|
|
|
359
|
+ if (Yii::$app->redis->incr($key)){
|
|
|
360
|
+ $replay_num += 1;
|
353
|
}
|
361
|
}
|
|
|
362
|
+ $ret['audience_num'] += $replay_num;
|
|
|
363
|
+ $ret['replay_num'] = $replay_num;
|
354
|
|
364
|
|
355
|
$this->renderJson(Yii::$app->params['success_code'],'',$ret);
|
365
|
$this->renderJson(Yii::$app->params['success_code'],'',$ret);
|
356
|
}else
|
366
|
}else
|