Browse Source

话题列表

wzq 5 years ago
parent
commit
96baaf2733
2 changed files with 11 additions and 3 deletions
  1. 10 2
      app/Traits/PostTrait.php
  2. 1 1
      app/Transformers/Post/PostTransformer.php

+ 10 - 2
app/Traits/PostTrait.php

@@ -33,14 +33,22 @@ trait PostTrait
     }
     }
 
 
     //获取内容话题
     //获取内容话题
-    public function getTopic($topic_ids)
+    public function getTopic($topic_ids, $type = 0)
     {
     {
         $ids = explode(',', $topic_ids);
         $ids = explode(',', $topic_ids);
         $topic = [];
         $topic = [];
         foreach($ids as $id){
         foreach($ids as $id){
             $name = Redis::ZRANGEBYSCORE('topic.name', $id, $id);
             $name = Redis::ZRANGEBYSCORE('topic.name', $id, $id);
             if($name && isset($name[0])){
             if($name && isset($name[0])){
-                $topic[] = $name[0];
+                if($type){
+                    $topic[] = [
+                        'id' => intval($id),
+                        'name' => $name[0],
+                    ];
+                }else{
+                    $topic[] = $name[0];
+                }
+
             }
             }
         }
         }
         return $topic;
         return $topic;

+ 1 - 1
app/Transformers/Post/PostTransformer.php

@@ -24,7 +24,7 @@ class PostTransformer extends TransformerAbstract
             'uid' => $post['uid'],
             'uid' => $post['uid'],
             'username' => $post['username'],
             'username' => $post['username'],
             'avatar' => $post['avatar'],
             'avatar' => $post['avatar'],
-            'topic' => $this->getTopic($post['topic_ids']),
+            'topic' => $this->getTopic($post['topic_ids'], 1),
             'content' => subtext(strip_tags($post['content']), 20),
             'content' => subtext(strip_tags($post['content']), 20),
             'location' => $post['location'],
             'location' => $post['location'],
             'pv' => $post->data->pv_real.'/'.$post->data->pv,
             'pv' => $post->data->pv_real.'/'.$post->data->pv,