|
@@ -136,6 +136,8 @@ class PostRepositories
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ $fresh = (Carbon::now()->timestamp) - (Carbon::parse("2019-05-01 00:00:00")->timestamp);
|
|
|
+ $score = $fresh / 86400;
|
|
|
$data = [
|
|
|
'uid' => $userInfo['uid'],
|
|
|
'username' => $userInfo['username'],
|
|
@@ -150,14 +152,12 @@ class PostRepositories
|
|
|
'content' => $request['content'],
|
|
|
'location' => isset($request['location'])? $request['location'] : '',
|
|
|
'is_suggest' => 0,
|
|
|
- 'is_hide' => 0
|
|
|
+ 'is_hide' => 0,
|
|
|
+ 'weight' => $score
|
|
|
];
|
|
|
|
|
|
$date = date('Y-m-d H:i:s');
|
|
|
|
|
|
- $fresh = (Carbon::now()->timestamp) - (Carbon::parse("2019-05-01 00:00:00")->timestamp);
|
|
|
- $score = $fresh / 86400;
|
|
|
-
|
|
|
DB::beginTransaction();
|
|
|
try{
|
|
|
$post = $this->post->create($data);
|
|
@@ -176,8 +176,7 @@ class PostRepositories
|
|
|
'collect_real_count' => 0,
|
|
|
'available_bean' => $this->availableBean(),
|
|
|
'will_collect_bean' => rand(100, 200),
|
|
|
- 'collect_bean' => 0,
|
|
|
- 'weight' => $score
|
|
|
+ 'collect_bean' => 0
|
|
|
]);
|
|
|
|
|
|
if($imgs){
|
|
@@ -198,6 +197,29 @@ class PostRepositories
|
|
|
foreach($topicIds as $id){
|
|
|
Redis::zincrby('topic.user_uid'.$userInfo['uid'], 1, $id);
|
|
|
}
|
|
|
+ Redis::HSET('post_info_'.$post->id,
|
|
|
+ 'id', $post->id,
|
|
|
+ 'uid', $post->uid,
|
|
|
+ 'type', $post->type,
|
|
|
+ 'img', $post->img,
|
|
|
+ 'imgs', json_encode($imgs),
|
|
|
+ 'video', $post->video,
|
|
|
+ 'topic_ids', $post->topic_ids,
|
|
|
+ 'title', $post->title,
|
|
|
+ 'content', $post->content,
|
|
|
+ 'location', $post->location,
|
|
|
+ 'pv', $postData->pv,
|
|
|
+ 'dislike_count', $postData->dislike_count,
|
|
|
+ 'praise_count', $postData->praise_count,
|
|
|
+ 'share_count', $postData->share_count,
|
|
|
+ 'comment_count', $postData->comment_count,
|
|
|
+ 'collect_count', $postData->collect_count,
|
|
|
+ 'available_bean', $postData->available_bean,
|
|
|
+ 'will_collect_bean', $postData->will_collect_bean,
|
|
|
+ 'create_bean', $postData->create_bean,
|
|
|
+ 'collect_bean', $postData->collect_bean,
|
|
|
+ 'created_at', $post->created_at);
|
|
|
+
|
|
|
return jsonSuccess([
|
|
|
'post_id' => $post->id,
|
|
|
'h5url' => config('customer.share_post_h5url')."?post_id={$post->id}&invite_code={$userInfo['invite_code']}",
|
|
@@ -278,7 +300,16 @@ class PostRepositories
|
|
|
try{
|
|
|
$comment = $this->postComment->create($data);
|
|
|
|
|
|
+ if($comment->parent_id){
|
|
|
+ $this->postComment->where('id', $comment->parent_id)->increment('reply_count');
|
|
|
+ }
|
|
|
+
|
|
|
DB::commit();
|
|
|
+ if(!$comment->parent_id){
|
|
|
+ Redis::DEL('post_new_comment_'.$comment->post_id);
|
|
|
+ }else{
|
|
|
+ Redis::DEL('post_new_reply_'.$comment->id);
|
|
|
+ }
|
|
|
return jsonSuccess(['id' => $comment->id], '评论成功');
|
|
|
|
|
|
}catch (QueryException $exception){
|
|
@@ -316,6 +347,11 @@ class PostRepositories
|
|
|
$comment->save();
|
|
|
|
|
|
DB::commit();
|
|
|
+ if(!$comment->parent_id){
|
|
|
+ Redis::DEL('post_new_comment_'.$comment->post_id);
|
|
|
+ }else{
|
|
|
+ Redis::DEL('post_new_reply_'.$comment->id);
|
|
|
+ }
|
|
|
Redis::SADD('delete_post_comment_ids', $comment->id);
|
|
|
return jsonSuccess('删除评论成功');
|
|
|
|
|
@@ -335,8 +371,6 @@ class PostRepositories
|
|
|
$perPage = isset($request['per_page']) ? $request['per_page'] : 20;
|
|
|
|
|
|
return $this->post
|
|
|
- ->join('post_data', 'post_data.post_id', '=', 'post.id')
|
|
|
- ->select('post.*')
|
|
|
->where(function($query) use ($request){
|
|
|
if(isset($request['keyword'])){
|
|
|
$query->where('title', 'like', "%{$request['keyword']}%")
|
|
@@ -348,9 +382,9 @@ class PostRepositories
|
|
|
$topicIds = json_decode($request['topic_ids'], true);
|
|
|
foreach ($topicIds as $key=>$id) {
|
|
|
if ($key==0) {
|
|
|
- $query->whereRaw('FIND_IN_SET('.$id.', post.topic_ids)');
|
|
|
+ $query->whereRaw('FIND_IN_SET('.$id.', topic_ids)');
|
|
|
} else {
|
|
|
- $query->orWhereRaw('FIND_IN_SET('.$id.', post.topic_ids)');
|
|
|
+ $query->orWhereRaw('FIND_IN_SET('.$id.', topic_ids)');
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -383,30 +417,26 @@ class PostRepositories
|
|
|
}
|
|
|
Log::debug('热门视频ids'.$ids);
|
|
|
return $this->post
|
|
|
- ->join('post_data', 'post_data.post_id', '=', 'post.id')
|
|
|
- ->select('post.*', DB::raw("IF (post.id = {$id},1,0) as sort"))
|
|
|
+ ->select('*', DB::raw("IF (id = {$id},1,0) as sort"))
|
|
|
->where($where)
|
|
|
- ->whereIn('post.id', explode(',', $ids))
|
|
|
+ ->whereIn('id', explode(',', $ids))
|
|
|
->orderBy('sort', 'desc')
|
|
|
- ->orderByRaw(DB::raw("FIELD(post.id,{$ids})"))
|
|
|
+ ->orderByRaw(DB::raw("FIELD(id,{$ids})"))
|
|
|
->paginate($perPage);
|
|
|
}elseif($request['type'] == 'one'){
|
|
|
- $where[] = ['post.id', $id];
|
|
|
+ $where[] = ['id', $id];
|
|
|
return $this->post
|
|
|
- ->join('post_data', 'post_data.post_id', '=', 'post.id')
|
|
|
- ->select('post.*')
|
|
|
->where($where)
|
|
|
->paginate($perPage);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
return $this->post
|
|
|
- ->join('post_data', 'post_data.post_id', '=', 'post.id')
|
|
|
- ->select('post.*', DB::raw("IF (post.id = {$id},1,0) as sort"))
|
|
|
+ ->select('*', DB::raw("IF (id = {$id},1,0) as sort"))
|
|
|
->where($where)
|
|
|
->where(function($query) use ($request){
|
|
|
if(isset($request['topic_id']) && $request['topic_id']){
|
|
|
- $query->whereRaw('FIND_IN_SET('.$request['topic_id'].', post.topic_ids)');
|
|
|
+ $query->whereRaw('FIND_IN_SET('.$request['topic_id'].', topic_ids)');
|
|
|
}
|
|
|
})
|
|
|
->orderBy('sort', 'desc')
|
|
@@ -437,7 +467,6 @@ class PostRepositories
|
|
|
$order = 'post_share.updated_at';
|
|
|
}
|
|
|
return $post
|
|
|
- ->join('post_data', 'post_data.post_id', '=', 'post.id')
|
|
|
->select('post.*')
|
|
|
->where($where)
|
|
|
->orderBy($order,'desc')
|
|
@@ -450,8 +479,6 @@ class PostRepositories
|
|
|
public function detail($id)
|
|
|
{
|
|
|
return $this->post
|
|
|
- ->join('post_data', 'post_data.post_id', '=', 'post.id')
|
|
|
- ->select('post.*')
|
|
|
->find($id);
|
|
|
}
|
|
|
|
|
@@ -471,8 +498,6 @@ class PostRepositories
|
|
|
$perPage = isset($request['per_page']) ? $request['per_page'] : 20;
|
|
|
|
|
|
return $this->post
|
|
|
- ->join('post_data', 'post_data.post_id', '=', 'post.id')
|
|
|
- ->select('post.*')
|
|
|
->orderBy('is_suggest','desc')
|
|
|
->orderBy('weight','desc')
|
|
|
->paginate($perPage);
|
|
@@ -486,9 +511,7 @@ class PostRepositories
|
|
|
$perPage = isset($request['per_page']) ? $request['per_page'] : 20;
|
|
|
|
|
|
return $this->post
|
|
|
- ->join('post_data', 'post_data.post_id', '=', 'post.id')
|
|
|
- ->select('post.*')
|
|
|
- ->whereRaw('FIND_IN_SET(' . $request['id'] . ',post.topic_ids)')
|
|
|
+ ->whereRaw('FIND_IN_SET(' . $request['id'] . ',topic_ids)')
|
|
|
->orderBy('id','desc')
|
|
|
->paginate($perPage);
|
|
|
}
|
|
@@ -554,7 +577,6 @@ class PostRepositories
|
|
|
public function myTopicList($request)
|
|
|
{
|
|
|
$perPage = isset($request['per_page']) ? $request['per_page'] : 20;
|
|
|
-
|
|
|
$uid = 0;
|
|
|
$user = $this->getUserInfo();
|
|
|
if($user){
|
|
@@ -580,31 +602,45 @@ class PostRepositories
|
|
|
Log::debug("非帖子类操作,不操作帖子统计数量".json_encode($request));
|
|
|
return true;
|
|
|
}
|
|
|
+ //帖子缓存信息key
|
|
|
+ $postInfoKey = "post_info_".$postId;
|
|
|
$post = PostData::where('post_id', $postId)->first();
|
|
|
if(!$post) return true;
|
|
|
if (isset($request['behavior_flag']) && $request['behavior_flag'] == 'read') {
|
|
|
$post->pv += 1;
|
|
|
$post->pv_real += 1;
|
|
|
+ Redis::HINCRBY($postInfoKey,'pv',1);
|
|
|
Log::debug("帖子:".$postId."被阅读,pv +1");
|
|
|
} elseif (isset($request['behavior_flag']) && $request['behavior_flag'] == 'unlike') {
|
|
|
+ //用户不喜欢帖子key
|
|
|
+ $postUnLikeKey = "post_unlike_".$postId;
|
|
|
$post->dislike_count += 1;
|
|
|
PostDislike::create(['uid'=>$request['target_id'],'post_id'=>$request['post_id']]);
|
|
|
+ Redis::sadd($postUnLikeKey,$request['target_id']);
|
|
|
+ Redis::HINCRBY($postInfoKey,'dislike_count',1);
|
|
|
Log::debug("帖子:".$postId."被不喜欢,unlike +1");
|
|
|
} elseif (isset($request['behavior_flag']) && $request['behavior_flag'] == 'like') {
|
|
|
+ //用户点赞帖子
|
|
|
+ $postLikeKey = "post_like_".$postId;
|
|
|
if($request['behavior_value']){
|
|
|
$post->praise_count += 1;
|
|
|
$post->praise_real_count += 1;
|
|
|
PostLike::create(['uid'=>$request['target_id'],'post_id'=>$request['post_id']]);
|
|
|
+ Redis::sadd($postLikeKey,$request['target_id']);
|
|
|
+ Redis::HINCRBY($postInfoKey,'praise_count',1);
|
|
|
Log::debug("帖子:".$postId."被点赞,praise_count +1");
|
|
|
}else{
|
|
|
$post->praise_count -= 1;
|
|
|
$post->praise_real_count -= 1;
|
|
|
PostLike::where(['uid'=>$request['target_id'],'post_id'=>$request['post_id']])->delete();
|
|
|
+ Redis::srem($postLikeKey,$request['target_id']);
|
|
|
+ Redis::HINCRBY($postInfoKey,'praise_count',-1);
|
|
|
Log::debug("帖子:".$postId."被取消点赞,praise_count -1");
|
|
|
}
|
|
|
} elseif (isset($request['behavior_flag']) && $request['behavior_flag'] == 'forward') {
|
|
|
$post->share_count += 1;
|
|
|
$post->share_real_count += 1;
|
|
|
+ Redis::HINCRBY($postInfoKey,'share_count',1);
|
|
|
$shareRow = PostShare::where(['uid'=>$request['target_id'],'post_id'=>$request['post_id']])->first();
|
|
|
if($shareRow){
|
|
|
PostShare::where(['uid'=>$request['target_id'],'post_id'=>$request['post_id']])->update(['uid'=>$request['target_id'],'post_id'=>$request['post_id']]);
|
|
@@ -614,17 +650,24 @@ class PostRepositories
|
|
|
Log::debug("帖子:".$postId."被分享,share_count +1");
|
|
|
} elseif (isset($request['behavior_flag']) && $request['behavior_flag'] == 'comment') {
|
|
|
$post->comment_count += 1;
|
|
|
+ Redis::HINCRBY($postInfoKey,'comment_count',1);
|
|
|
Log::debug("帖子:".$postId."被评论,comment_count +1");
|
|
|
} elseif (isset($request['behavior_flag']) && $request['behavior_flag'] == 'collect') {
|
|
|
+ //用户收藏帖子
|
|
|
+ $postCollectKey = "post_collect_".$postId;
|
|
|
if($request['behavior_value']) {
|
|
|
$post->collect_count += 1;
|
|
|
$post->collect_real_count += 1;
|
|
|
PostCollect::create(['uid'=>$request['target_id'],'post_id'=>$request['post_id']]);
|
|
|
+ Redis::sadd($postCollectKey,$request['target_id']);
|
|
|
+ Redis::HINCRBY($postInfoKey,'collect_count',1);
|
|
|
Log::debug("帖子:".$postId."被收藏,collect_count +1");
|
|
|
}else{
|
|
|
$post->collect_count -= 1;
|
|
|
$post->collect_real_count -= 1;
|
|
|
PostCollect::where(['uid'=>$request['target_id'],'post_id'=>$request['post_id']])->delete();
|
|
|
+ Redis::srem($postCollectKey,$request['target_id']);
|
|
|
+ Redis::HINCRBY($postInfoKey,'collect_count',-1);
|
|
|
Log::debug("帖子:".$postId."被取消收藏,collect_count -1");
|
|
|
}
|
|
|
}
|