|
@@ -4,7 +4,7 @@ namespace app\api\controller;
|
|
|
|
|
|
use app\common\controller\Api;
|
|
|
use think\Db;
|
|
|
-
|
|
|
+use Redis;
|
|
|
class Tvindex extends Api
|
|
|
{
|
|
|
protected $noNeedLogin = ['indexdata','video_list','videoinfo','zhuanti','tudingc','search','history'];
|
|
@@ -165,7 +165,7 @@ class Tvindex extends Api
|
|
|
->orderRaw('rand()')->limit(4)->select();
|
|
|
$guess_list = list_domain_image($guess_list, ['image']);
|
|
|
|
|
|
- //记录浏览历史
|
|
|
+ //记录浏览历史,给浏览历史列表用的,即时的
|
|
|
if($this->auth->isLogin()){
|
|
|
$view_map = [
|
|
|
'user_id' => $this->auth->id,
|
|
@@ -181,6 +181,9 @@ class Tvindex extends Api
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //记录pv,uv
|
|
|
+ $this->video_pvuv($id);
|
|
|
+
|
|
|
//
|
|
|
$result = [
|
|
|
'video_info' => $info,
|
|
@@ -213,7 +216,7 @@ class Tvindex extends Api
|
|
|
$info['is_collection'] = Db::name('video_collection')->where(['user_id' => $this->auth->id, 'video_id' => $id])->count('id');
|
|
|
$info['is_good'] = Db::name('video_good')->where(['user_id' => $this->auth->id, 'video_id' => $id])->count('id');
|
|
|
|
|
|
- //记录浏览历史
|
|
|
+ //记录浏览历史,给浏览历史列表用的,即时的
|
|
|
if($this->auth->isLogin()){
|
|
|
$view_map = [
|
|
|
'user_id' => $this->auth->id,
|
|
@@ -229,6 +232,9 @@ class Tvindex extends Api
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //记录pv,uv
|
|
|
+ $this->video_pvuv($id);
|
|
|
+
|
|
|
//
|
|
|
$result = [
|
|
|
'video_info' => $info,
|
|
@@ -624,4 +630,41 @@ class Tvindex extends Api
|
|
|
$decrypted = openssl_decrypt(hex2bin($string), 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
|
|
|
return $decrypted;
|
|
|
}
|
|
|
+
|
|
|
+ //共有方法,
|
|
|
+ private function video_pvuv($video_id = 0){
|
|
|
+ if(empty($video_id)) {return true;}
|
|
|
+
|
|
|
+ //开启redis
|
|
|
+ $redis = new Redis();
|
|
|
+ $config = config('redis');
|
|
|
+ $redis->connect($config['redis_host'], $config['redis_port']);
|
|
|
+ if ($config['redis_pwd']) {
|
|
|
+ $redis->auth($config['redis_pwd']);
|
|
|
+ }
|
|
|
+ if($config['redis_selectdb'] > 0){
|
|
|
+ $redis->select($config['redis_selectdb']);
|
|
|
+ }
|
|
|
+
|
|
|
+ //今天
|
|
|
+ $today = date('Y-m-d');
|
|
|
+
|
|
|
+ //今日pv+1
|
|
|
+ $today_pv_key = $today.'_video_pv_'.$video_id;
|
|
|
+ $redis->incr($today_pv_key,1);
|
|
|
+
|
|
|
+ //今日uv+1
|
|
|
+ if($this->auth->isLogin() && $this->auth->id){
|
|
|
+ $today_uv_key = $today.'_video_uv_'.$video_id;
|
|
|
+ $uid = $this->auth->id;
|
|
|
+ $redis->sAdd($today_uv_key,$uid);
|
|
|
+ }
|
|
|
+
|
|
|
+ //今日视频id列表
|
|
|
+ $today_video_key = $today.'_video_list';
|
|
|
+ $redis->sAdd($today_video_key,$video_id);
|
|
|
+ }
|
|
|
+ /*public function test(){
|
|
|
+ $this->video_pvuv(input('video_id',0));
|
|
|
+ }*/
|
|
|
}
|