|
@@ -199,6 +199,7 @@ class LiveService extends BaseService
|
|
|
];
|
|
|
VideoCollectModel::insert($data);
|
|
|
RedisService::clear("caches:videos:recommend:{$userId}_2");
|
|
|
+ RedisService::clear("caches:member:fans:{$userId}_{$id}_2");
|
|
|
}
|
|
|
|
|
|
// 更新播放量
|
|
@@ -250,18 +251,48 @@ class LiveService extends BaseService
|
|
|
VideoCollectModel::insert($data);
|
|
|
RedisService::set("caches:videos:collect:temp_{$userId}_{$id}_1_2", $data, rand(10,30));
|
|
|
RedisService::clear("caches:videos:recommend:{$userId}_1_2");
|
|
|
+ RedisService::clear("caches:member:fans:{$userId}_{$id}_2");
|
|
|
}
|
|
|
|
|
|
// 更新播放量
|
|
|
- if(!RedisService::get("caches:live:player:{$userId}_{$id}")){
|
|
|
+ if(!RedisService::get("caches:player:live:{$userId}_{$id}")){
|
|
|
$this->model->where(['id'=> $id])->update(['views'=>DB::raw('views + 1'),'update_time'=>time()]);
|
|
|
- RedisService::set("caches:live:player:{$userId}_{$id}", ['user_id'=> $userId,'id'=>$id], rand(600, 1800));
|
|
|
+ RedisService::set("caches:player:live:{$userId}_{$id}", ['user_id'=> $userId,'id'=>$id], rand(6*3600, 86400));
|
|
|
}
|
|
|
$this->error = 1010;
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 缓存数据
|
|
|
+ * @param $id
|
|
|
+ * @param int $status
|
|
|
+ * @return array|mixed
|
|
|
+ */
|
|
|
+ public function getCacheInfo($id, $status=0)
|
|
|
+ {
|
|
|
+ $cacheKey = "caches:live:info:{$id}_{$status}";
|
|
|
+ $info = RedisService::get($cacheKey);
|
|
|
+ if($info){
|
|
|
+ return $info;
|
|
|
+ }
|
|
|
+
|
|
|
+ $where = ['id' => $id, 'mark' => 1];
|
|
|
+ if($status){
|
|
|
+ $where['status'] = $status;
|
|
|
+ }
|
|
|
+ $info = $this->model->where($where)
|
|
|
+ ->select(['id','user_id','create_time','end_time','views','reward_num','reward_total','like_num'])
|
|
|
+ ->first();
|
|
|
+ $info = $info? $info->toArray() : [];
|
|
|
+ if($info){
|
|
|
+ RedisService::set($cacheKey, $info, rand(3, 5));
|
|
|
+ }
|
|
|
+
|
|
|
+ return $info;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 状态设置
|
|
|
* @return bool
|
|
|
*/
|
|
@@ -269,13 +300,24 @@ class LiveService extends BaseService
|
|
|
{
|
|
|
$id = request()->post('id', 0);
|
|
|
$status = request()->post('status', 2);
|
|
|
- if ($id && !$info = $this->model->where(['id' => $id, 'mark' => 1])->select(['id','views','reward_total','like_num'])->first()) {
|
|
|
+ if ($id && !$info = $this->getCacheInfo($id)) {
|
|
|
$this->error = 2981;
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
- if($this->model->where(['id'=> $id,'mark'=>1])->update(['status'=>$status, 'update_time'=> time()])){
|
|
|
+ $updateData = ['status'=>$status, 'update_time'=> time()];
|
|
|
+ if($status == 2){
|
|
|
+ $updateData['end_time'] = time();
|
|
|
+ }
|
|
|
+ if($this->model->where(['id'=> $id,'mark'=>1])->update($updateData)){
|
|
|
$this->error = 1002;
|
|
|
+ $time = $info['end_time']? intval($info['end_time'] - $info['create_time']) : intval(time() - $info['create_time']);
|
|
|
+ $info['status'] = $status;
|
|
|
+ $info['live_hour'] = $time > 3600 ? intval($time/3600) : 0;
|
|
|
+ $info['live_minute'] = $time%3600? intval($time%3600/60) : 0;
|
|
|
+ $info['time_text'] = date('H:i', $info['create_time']);
|
|
|
+ $info['end_time_text'] = date('H:i', $info['end_time']? $info['end_time'] : time());
|
|
|
+ $info['fans_num'] = MemberCollectService::make()->getViewFansCountByType($info['user_id'], $id, 2);
|
|
|
+ $info['new_fans'] = MemberCollectService::make()->getNewFansCount($info['user_id'], $id,2, $info['create_time']);
|
|
|
return $info;
|
|
|
}
|
|
|
|
|
@@ -372,7 +414,7 @@ class LiveService extends BaseService
|
|
|
'type' => isset($params['type']) ? intval($params['type']) : 1,
|
|
|
'user_id' => $userId,
|
|
|
'title' => isset($params['title']) && $params['title'] ? trim($params['title']) : $nickname.'正在直播',
|
|
|
- 'description' => isset($params['description']) && $params['description'] ? trim($params['description']) : '我正在直播,快来看看吧',
|
|
|
+ 'description' => isset($params['description']) && $params['description'] ? trim($params['description']) : lang('我正在直播,快来看看吧'),
|
|
|
'category' => isset($params['category']) ? intval($params['category']) : 0,
|
|
|
'visible_type' => isset($params['visible_type']) ? intval($params['visible_type']) : 0,
|
|
|
'visible_users' => isset($params['visible_users']) ? trim($params['visible_users']) : '',
|