xielin 5 anos atrás
pai
commit
d18205e891

+ 20 - 3
app/Transformers/Topic/TopicDetailTransformer.php

@@ -5,8 +5,10 @@
  * Date: 2019/6/17
  * Time: 18:10
  */
-namespace  App\Transformers\Topic;
 
+namespace App\Transformers\Topic;
+
+use App\Models\InterestCircle;
 use App\Models\Topic;
 use Carbon\Carbon;
 use League\Fractal\TransformerAbstract;
@@ -17,18 +19,33 @@ class TopicDetailTransformer extends TransformerAbstract
     {
         $this->uid = $uid;
     }
+
     public function transform(Topic $topic)
     {
         $isFollow = 0;
-        if($this->uid){
-            $isFollow = $topic->follow->where('uid', $this->uid)->count()?1:0;
+        if ($this->uid) {
+            $isFollow = $topic->follow->where('uid', $this->uid)->count() ? 1 : 0;
         }
+
         return [
             'id' => $topic['id'],
             'name' => $topic['name'],
             'img' => $topic['img'],
             'follow_count' => getNumber($topic['use_count'] + $topic['base_count']),
             'is_follow' => $isFollow,
+            'circle' => $this->getCircleInfo($topic['circle_id'])
         ];
     }
+
+    public function getCircleInfo($circleId)
+    {
+        $circleInfo = InterestCircle::find($circleId);
+        if ($circleInfo) {
+            $circle['id'] = $circleInfo->id;
+            $circle['name'] = $circleInfo->name;
+        } else {
+            $circle = new \stdClass();
+        }
+        return $circle;
+    }
 }

+ 1 - 0
app/Transformers/Topic/TopicPostTransformer.php

@@ -54,6 +54,7 @@ class TopicPostTransformer extends TransformerAbstract
             'username' => $user['username'],
             'avatar' => $user['avatar'],
             'topic' => $this->getTopic($post['topic_ids']),
+            'is_fine' => $post['is_fine'],
             'title' => $post['title'],
             'content' => $post['content'],
             'location' => $post['location'],