瀏覽代碼

获取话题组

wzq 5 年之前
父節點
當前提交
1cbb07f67d
共有 3 個文件被更改,包括 55 次插入1 次删除
  1. 33 1
      app/Http/Controllers/V1/PostController.php
  2. 20 0
      app/Repositories/PostRepositories.php
  3. 2 0
      routes/api.php

+ 33 - 1
app/Http/Controllers/V1/PostController.php

@@ -165,7 +165,23 @@ class PostController extends Controller
             $newData = [];
             foreach($data['data'] as $key => $val){
                 if(isset($floor[$key+1])){
-                    $newData[] = $floor[$key+1];
+                    if($floor[$key+1]['show_type'] == 'banner'){
+                        $newData[] = [
+                            'show_type' => 'banner',
+                        ];
+                    }elseif($floor[$key+1]['show_type'] == 'user'){
+                        $newData[] = [
+                            'show_type' => 'user',
+                        ];
+                    }elseif($floor[$key+1]['show_type'] == 'video'){
+                        $newData[] = [
+                            'show_type' => 'video',
+                        ];
+                    }elseif($floor[$key+1]['show_type'] == 'topic'){
+                        $newData[] = [
+                            'show_type' => 'topic',
+                        ];
+                    }
                 }
                 $newData[] = $val;
             }
@@ -303,5 +319,21 @@ class PostController extends Controller
         return jsonSuccess($data);
     }
 
+    /**
+     * 获取话题
+     */
+    public function getTopic(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'ids' => 'required|string',
+        ]);
+        if ($validator->fails()) {
+            return jsonError($validator->errors()->first());
+        }
+
+        $data = $this->postRepositories->getTopic($request['ids']);
+        return jsonSuccess($data);
+    }
+
 
 }

+ 20 - 0
app/Repositories/PostRepositories.php

@@ -534,5 +534,25 @@ class PostRepositories
             ->find($id);
     }
 
+    /**
+     * 获取话题
+     */
+    public function getTopic($ids)
+    {
+        $topics = $this->topic
+            ->whereIn('id', explode(',',$ids))
+            ->get();
+        $data = [];
+        foreach($topics as $topic){
+            $data[] = [
+                'id' => $topic->id,
+                'name' => $topic->name,
+                'img' => $topic->img,
+                'follow_count' => $topic->follow->count() + 9876,
+            ];
+        }
+        return $data;
+    }
+
 
 }

+ 2 - 0
routes/api.php

@@ -46,6 +46,8 @@ $api->version('v1', [
         $api->get('post/topic', 'PostController@topicPost');
         //话题列表
         $api->get('topic', 'PostController@topicList');
+        //获取话题
+        $api->get('topic/group', 'PostController@getTopic');
         //话题详情
         $api->get('topic/detail', 'PostController@topicDetail');
         //关注推荐话题