|
@@ -15,6 +15,7 @@ use App\Models\MemberFollowTopic;
|
|
use App\Models\Post;
|
|
use App\Models\Post;
|
|
use App\Models\PostCollect;
|
|
use App\Models\PostCollect;
|
|
use App\Models\PostComment;
|
|
use App\Models\PostComment;
|
|
|
|
+use App\Models\PostCommentLike;
|
|
use App\Models\PostData;
|
|
use App\Models\PostData;
|
|
use App\Models\PostDislike;
|
|
use App\Models\PostDislike;
|
|
use App\Models\PostImgs;
|
|
use App\Models\PostImgs;
|
|
@@ -511,7 +512,7 @@ class PostRepositories
|
|
}
|
|
}
|
|
|
|
|
|
$topicIds = [];
|
|
$topicIds = [];
|
|
- if(isset($request['category_id']) && $request['category_id']){
|
|
|
|
|
|
+ if (isset($request['category_id']) && $request['category_id']) {
|
|
$topicIds = $this->categoryTopic->where('category_id', $request['category_id'])->pluck('topic_id')->toArray();
|
|
$topicIds = $this->categoryTopic->where('category_id', $request['category_id'])->pluck('topic_id')->toArray();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -563,6 +564,7 @@ class PostRepositories
|
|
return $this->postComment
|
|
return $this->postComment
|
|
->where('post_id', $request['post_id'])
|
|
->where('post_id', $request['post_id'])
|
|
->where('parent_id', 0)
|
|
->where('parent_id', 0)
|
|
|
|
+ ->orderBy('like_count', 'desc')
|
|
->orderBy('id', 'desc')
|
|
->orderBy('id', 'desc')
|
|
->paginate($perPage);
|
|
->paginate($perPage);
|
|
}
|
|
}
|
|
@@ -580,6 +582,16 @@ class PostRepositories
|
|
->paginate($perPage);
|
|
->paginate($perPage);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 根据评论id获取内容id
|
|
|
|
+ */
|
|
|
|
+ public function getPostId($commentId)
|
|
|
|
+ {
|
|
|
|
+ return $this->postComment
|
|
|
|
+ ->where('id', $commentId)
|
|
|
|
+ ->value('post_id');
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 话题列表
|
|
* 话题列表
|
|
*/
|
|
*/
|
|
@@ -647,6 +659,7 @@ class PostRepositories
|
|
$postInfoKey = "post_info_" . $postId;
|
|
$postInfoKey = "post_info_" . $postId;
|
|
$post = PostData::where('post_id', $postId)->first();
|
|
$post = PostData::where('post_id', $postId)->first();
|
|
if (!$post) return true;
|
|
if (!$post) return true;
|
|
|
|
+ $row = false;
|
|
if (isset($request['behavior_flag']) && $request['behavior_flag'] == 'read') {
|
|
if (isset($request['behavior_flag']) && $request['behavior_flag'] == 'read') {
|
|
$post->pv += 1;
|
|
$post->pv += 1;
|
|
$post->pv_real += 1;
|
|
$post->pv_real += 1;
|
|
@@ -659,6 +672,7 @@ class PostRepositories
|
|
$this->topic->where('id', $id)->increment('pv');
|
|
$this->topic->where('id', $id)->increment('pv');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ $row = $post->save();
|
|
Log::debug("帖子:" . $postId . "被阅读,pv +1");
|
|
Log::debug("帖子:" . $postId . "被阅读,pv +1");
|
|
} elseif (isset($request['behavior_flag']) && $request['behavior_flag'] == 'unlike') {
|
|
} elseif (isset($request['behavior_flag']) && $request['behavior_flag'] == 'unlike') {
|
|
//用户不喜欢帖子key
|
|
//用户不喜欢帖子key
|
|
@@ -667,6 +681,7 @@ class PostRepositories
|
|
PostDislike::create(['uid' => $request['target_id'], 'post_id' => $request['post_id']]);
|
|
PostDislike::create(['uid' => $request['target_id'], 'post_id' => $request['post_id']]);
|
|
Redis::sadd($postUnLikeKey, $request['target_id']);
|
|
Redis::sadd($postUnLikeKey, $request['target_id']);
|
|
Redis::HINCRBY($postInfoKey, 'dislike_count', 1);
|
|
Redis::HINCRBY($postInfoKey, 'dislike_count', 1);
|
|
|
|
+ $row = $post->save();
|
|
Log::debug("帖子:" . $postId . "被不喜欢,unlike +1");
|
|
Log::debug("帖子:" . $postId . "被不喜欢,unlike +1");
|
|
} elseif (isset($request['behavior_flag']) && $request['behavior_flag'] == 'like') {
|
|
} elseif (isset($request['behavior_flag']) && $request['behavior_flag'] == 'like') {
|
|
//用户点赞帖子
|
|
//用户点赞帖子
|
|
@@ -686,6 +701,23 @@ class PostRepositories
|
|
Redis::HINCRBY($postInfoKey, 'praise_count', -1);
|
|
Redis::HINCRBY($postInfoKey, 'praise_count', -1);
|
|
Log::debug("帖子:" . $postId . "被取消点赞,praise_count -1");
|
|
Log::debug("帖子:" . $postId . "被取消点赞,praise_count -1");
|
|
}
|
|
}
|
|
|
|
+ $row = $post->save();
|
|
|
|
+ } elseif (isset($request['behavior_flag']) && $request['behavior_flag'] == 'comment_like') {
|
|
|
|
+ //用户点赞评论
|
|
|
|
+ $comment = PostComment::where('id', $request['comment_id'])->first();
|
|
|
|
+ $postLikeKey = "comment_like_" . $postId;
|
|
|
|
+ if ($request['behavior_value']) {
|
|
|
|
+ $comment->like_count += 1;
|
|
|
|
+ PostCommentLike::create(['uid' => $request['target_id'], 'comment_id' => $request['comment_id']]);
|
|
|
|
+ Redis::zadd($postLikeKey, $request['comment_id'], $request['target_id'] . '_' . $request['comment_id']);
|
|
|
|
+ Log::debug("评论:" . $request['comment_id'] . "被点赞,like_count +1");
|
|
|
|
+ } else {
|
|
|
|
+ $comment->like_count -= 1;
|
|
|
|
+ PostCommentLike::where(['uid' => $request['target_id'], 'comment_id' => $request['comment_id']])->delete();
|
|
|
|
+ Redis::zrem($postLikeKey, $request['target_id'] . '_' . $request['comment_id']);
|
|
|
|
+ Log::debug("评论:" . $request['comment_id'] . "被取消点赞,like_count -1");
|
|
|
|
+ }
|
|
|
|
+ $row = $comment->save();
|
|
} elseif (isset($request['behavior_flag']) && $request['behavior_flag'] == 'forward') {
|
|
} elseif (isset($request['behavior_flag']) && $request['behavior_flag'] == 'forward') {
|
|
$post->share_count += 1;
|
|
$post->share_count += 1;
|
|
$post->share_real_count += 1;
|
|
$post->share_real_count += 1;
|
|
@@ -696,10 +728,12 @@ class PostRepositories
|
|
} else {
|
|
} else {
|
|
PostShare::create(['uid' => $request['target_id'], 'post_id' => $request['post_id']]);
|
|
PostShare::create(['uid' => $request['target_id'], 'post_id' => $request['post_id']]);
|
|
}
|
|
}
|
|
|
|
+ $row = $post->save();
|
|
Log::debug("帖子:" . $postId . "被分享,share_count +1");
|
|
Log::debug("帖子:" . $postId . "被分享,share_count +1");
|
|
} elseif (isset($request['behavior_flag']) && $request['behavior_flag'] == 'comment') {
|
|
} elseif (isset($request['behavior_flag']) && $request['behavior_flag'] == 'comment') {
|
|
$post->comment_count += 1;
|
|
$post->comment_count += 1;
|
|
Redis::HINCRBY($postInfoKey, 'comment_count', 1);
|
|
Redis::HINCRBY($postInfoKey, 'comment_count', 1);
|
|
|
|
+ $row = $post->save();
|
|
Log::debug("帖子:" . $postId . "被评论,comment_count +1");
|
|
Log::debug("帖子:" . $postId . "被评论,comment_count +1");
|
|
} elseif (isset($request['behavior_flag']) && $request['behavior_flag'] == 'collect') {
|
|
} elseif (isset($request['behavior_flag']) && $request['behavior_flag'] == 'collect') {
|
|
//用户收藏帖子
|
|
//用户收藏帖子
|
|
@@ -719,9 +753,10 @@ class PostRepositories
|
|
Redis::HINCRBY($postInfoKey, 'collect_count', -1);
|
|
Redis::HINCRBY($postInfoKey, 'collect_count', -1);
|
|
Log::debug("帖子:" . $postId . "被取消收藏,collect_count -1");
|
|
Log::debug("帖子:" . $postId . "被取消收藏,collect_count -1");
|
|
}
|
|
}
|
|
|
|
+ $row = $post->save();
|
|
}
|
|
}
|
|
$this->collectPostId($request['post_id']);
|
|
$this->collectPostId($request['post_id']);
|
|
- return $post->save();
|
|
|
|
|
|
+ return $row;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|