Преглед на файлове

获取关注分类用户

wzq преди 5 години
родител
ревизия
a107ed2b78
променени са 3 файла, в които са добавени 37 реда и са изтрити 0 реда
  1. 15 0
      app/Http/Controllers/Post/PostController.php
  2. 20 0
      app/Repositories/Post/PostRepository.php
  3. 2 0
      routes/api.php

+ 15 - 0
app/Http/Controllers/Post/PostController.php

@@ -143,6 +143,21 @@ class PostController extends Controller
         return $this->postRepository->getType($request->all());
     }
 
+    /**
+     * 获取关注分类用户uids
+     */
+    public function getCategoryUids(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'category' => 'required|string'
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+
+        return $this->postRepository->getCategoryUids($request->all());
+    }
+
     /**
      * 评论列表
      */

+ 20 - 0
app/Repositories/Post/PostRepository.php

@@ -11,6 +11,7 @@ namespace App\Repositories\Post;
 
 use App\Models\Behavior;
 use App\Models\CategoryTopic;
+use App\Models\MemberFollowTopic;
 use App\Models\Post;
 use App\Models\PostComment;
 use App\Models\PostData;
@@ -47,6 +48,7 @@ class PostRepository
                                 RabbitMqUtil $rabbitMqUtil,
                                 Behavior $behavior,
                                 CategoryTopic $categoryTopic,
+                                MemberFollowTopic $memberFollowTopic,
                                 PostStatistics $postStatistics,
                                 PostStore $postStore,
                                 PostStoreImgs $postStoreImgs,
@@ -60,6 +62,7 @@ class PostRepository
         $this->rabbitMqUtil = $rabbitMqUtil;
         $this->behavior = $behavior;
         $this->categoryTopic = $categoryTopic;
+        $this->memberFollowTopic = $memberFollowTopic;
         $this->topic = $topic;
         $this->postStatistics = $postStatistics;
         $this->postStore = $postStore;
@@ -603,6 +606,23 @@ class PostRepository
         ]);
     }
 
+    /**
+     * 获取关注分类用户uids
+     */
+    public function getCategoryUids($request)
+    {
+        $categoryIds = json_decode($request['category'], true);
+        $topicIds = $this->categoryTopic->whereIn('category_id', $categoryIds)->pluck('topic_id')->toArray();
+        $uids = $this->memberFollowTopic->whereIn('topic_id', $topicIds)->pluck('uid')->toArray();
+        $uids = array_unique($uids);
+        sort($uids);
+        return Response::create([
+            'message' => '成功',
+            'status_code' => 200,
+            'data' => $uids
+        ]);
+    }
+
     /**
      * 评论列表
      */

+ 2 - 0
routes/api.php

@@ -48,6 +48,8 @@ $api->version('v1', [
             $api->get('post/detail', 'PostController@detail');
             //内容类型
             $api->get('post/getType', 'PostController@getType');
+            //获取关注分类用户uids
+            $api->get('post/getCategoryUids', 'PostController@getCategoryUids');
             //推荐内容
             $api->put('post/suggest', 'PostController@suggest');
             //删除内容