|
@@ -91,17 +91,17 @@ trait PostTrait
|
|
$commentKey = 'post_new_comment_' . $id;
|
|
$commentKey = 'post_new_comment_' . $id;
|
|
$commentData = Redis::GET($commentKey);
|
|
$commentData = Redis::GET($commentKey);
|
|
if ($commentData) {
|
|
if ($commentData) {
|
|
- $comment = json_decode($commentData);
|
|
|
|
|
|
+ $comment = json_decode($commentData,true);
|
|
foreach ($comment as &$item) {
|
|
foreach ($comment as &$item) {
|
|
$isLike = 0;
|
|
$isLike = 0;
|
|
if ($uid) {
|
|
if ($uid) {
|
|
- $isLike = Redis::ZSCORE($key, $uid . '_' . $item->id) ? 1 : 0;
|
|
|
|
|
|
+ $isLike = Redis::ZSCORE($key, $uid . '_' . $item['id']) ? 1 : 0;
|
|
}
|
|
}
|
|
- $item->uid = intval($item->uid);
|
|
|
|
- $item->is_like = $isLike;
|
|
|
|
- $item->like_count = Redis::ZCOUNT($key, $item->id, $item->id);
|
|
|
|
- $item->reply_count = 0;
|
|
|
|
- $item->reply = [];
|
|
|
|
|
|
+ $item['uid'] = intval($item['uid']);
|
|
|
|
+ $item['is_like'] = $isLike;
|
|
|
|
+ $item['like_count'] = Redis::ZCOUNT($key, $item['id'], $item['id']);
|
|
|
|
+ $item['reply_count'] = 0;
|
|
|
|
+ $item['reply'] = [];
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
$comments = PostComment::where('post_id', $id)->where('parent_id', 0)->where('is_delete', 0)->orderBy('like_count', 'desc')->orderBy('id', 'desc')->limit(2)->get();
|
|
$comments = PostComment::where('post_id', $id)->where('parent_id', 0)->where('is_delete', 0)->orderBy('like_count', 'desc')->orderBy('id', 'desc')->limit(2)->get();
|
|
@@ -127,8 +127,8 @@ trait PostTrait
|
|
Redis::SET($commentKey, json_encode($comment));
|
|
Redis::SET($commentKey, json_encode($comment));
|
|
Redis::EXPIRE($commentKey, 300);
|
|
Redis::EXPIRE($commentKey, 300);
|
|
}
|
|
}
|
|
- sortArrByField($comment, 'like_count', true);
|
|
|
|
- return $comment;
|
|
|
|
|
|
+ sortArrByField($tempComment, 'like_count', true);
|
|
|
|
+ return $tempComment;
|
|
}
|
|
}
|
|
|
|
|
|
//获取评论点赞数、点赞状态
|
|
//获取评论点赞数、点赞状态
|