浏览代码

Merge branch 'develop'

xielin 5 年之前
父节点
当前提交
2aa998b4e5
共有 1 个文件被更改,包括 9 次插入9 次删除
  1. 9 9
      app/Traits/PostTrait.php

+ 9 - 9
app/Traits/PostTrait.php

@@ -91,17 +91,17 @@ trait PostTrait
         $commentKey = 'post_new_comment_' . $id;
         $commentData = Redis::GET($commentKey);
         if ($commentData) {
-            $comment = json_decode($commentData);
+            $comment = json_decode($commentData,true);
             foreach ($comment as &$item) {
                 $isLike = 0;
                 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 {
             $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::EXPIRE($commentKey, 300);
         }
-        sortArrByField($comment, 'like_count', true);
-        return $comment;
+        sortArrByField($tempComment, 'like_count', true);
+        return $tempComment;
     }
 
     //获取评论点赞数、点赞状态