zhangchangchun 5 years ago
parent
commit
3a114b311d

+ 9 - 0
app/Http/Controllers/Topic/TopicController.php

@@ -139,4 +139,13 @@ class TopicController extends Controller {
     public function resetRedis(){
         return  $this->topicRepository->resetRedis();
     }
+    public function getMemberTopic(Request $request){
+        $validator = Validator::make($request->all(), [
+            'uid' => 'required',
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return  $this->topicRepository->getMemberTopics($request['uid']);
+    }
 }

+ 16 - 0
app/Models/MemberFollowTopic.php

@@ -0,0 +1,16 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019-06-14
+ * Time: 14:12
+ */
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+class MemberFollowTopic extends Model{
+    public $table='member_follow_topic';
+
+}

+ 10 - 2
app/Repositories/TopicRepository.php

@@ -10,6 +10,7 @@ namespace App\Repositories;
 
 use App\Models\Category;
 use App\Models\CategoryTopic;
+use App\Models\MemberFollowTopic;
 use App\Models\Topic;
 use Dingo\Api\Http\Response;
 use Illuminate\Support\Facades\DB;
@@ -18,9 +19,10 @@ use Illuminate\Support\Facades\Log;
 use Illuminate\Support\Facades\Redis;
 
 class TopicRepository {
-    public function __construct(Topic $topic,CategoryTopic $categoryTopic){
+    public function __construct(Topic $topic,CategoryTopic $categoryTopic,MemberFollowTopic $memberFollowTopic){
         $this->topic = $topic;
         $this->categoryTopic = $categoryTopic;
+        $this->memberFollowTopic = $memberFollowTopic;
     }
     //列表
     public function index($request){
@@ -203,7 +205,13 @@ class TopicRepository {
     public function getTopics($ids = []){
         return $this->topic->whereIn('id', $ids)->select('id','name')->get();
     }
-
+    public function getMemberTopics($uid){
+       return $this->memberFollowTopic
+            ->leftJoin('topic','topic.id','=','member_follow_topic.topic_id')
+            ->where('member_follow_topic.uid',$uid)
+            ->select('topic.id','topic.name')
+            ->get();
+    }
     /**
      * 重置话题redis
      */

+ 2 - 0
routes/api.php

@@ -99,6 +99,8 @@ $api->version('v1', [
             $api->put('topic/topicSetStatus', 'TopicController@setStatus');
             //获取多个话题
             $api->get('topic/getTopic', 'TopicController@getTopic');
+            //获取用户关注话题
+            $api->get('topic/getMemberTopic', 'TopicController@getMemberTopic');
         });
 
         //行为