wzq před 5 roky
rodič
revize
3492923fe3

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

@@ -88,13 +88,16 @@ class PostController extends Controller
     {
         Log::debug('内容搜索' . json_encode($request));
         $userInfo = $this->getUserInfo();
-        if (empty($userInfo)) {
-            Log::debug('获取用户信息失败index'.json_encode($request));
-            return jsonError('获取用户信息失败');
+        if ($userInfo) {
+            $uid = $userInfo['uid'];
+            $inviteCode = $userInfo['invite_code'];
+        }else{
+            $uid = 0;
+            $inviteCode = '';
         }
         $list = $this->postRepositories->lists($request->all());
         $fractal = new Manager();
-        $resource = new Collection($list, new ListTransformer($userInfo['uid'], $userInfo['invite_code']));
+        $resource = new Collection($list, new ListTransformer($uid, $inviteCode));
         $resource->setPaginator(new IlluminatePaginatorAdapter($list));
         $data = $fractal->createData($resource)->toArray();
 
@@ -107,13 +110,16 @@ class PostController extends Controller
     public function video(Request $request)
     {
         $userInfo = $this->getUserInfo();
-        if (empty($userInfo)) {
-            Log::debug('获取用户信息失败video'.json_encode($request));
-            return jsonError('获取用户信息失败');
+        if ($userInfo) {
+            $uid = $userInfo['uid'];
+            $inviteCode = $userInfo['invite_code'];
+        }else{
+            $uid = 0;
+            $inviteCode = '';
         }
         $list = $this->postRepositories->video($request->all());
         $fractal = new Manager();
-        $resource = new Collection($list, new VideoTransformer($userInfo['uid'], $userInfo['invite_code']));
+        $resource = new Collection($list, new VideoTransformer($uid, $inviteCode));
         $resource->setPaginator(new IlluminatePaginatorAdapter($list));
         $data = $fractal->createData($resource)->toArray();
 
@@ -254,16 +260,19 @@ class PostController extends Controller
             return jsonError($validator->errors()->first());
         }
         $userInfo = $this->getUserInfo();
-        if (empty($userInfo)) {
-            Log::debug('获取用户信息失败detail'.json_encode($request));
-            return jsonError('获取用户信息失败');
+        if ($userInfo) {
+            $uid = $userInfo['uid'];
+            $inviteCode = $userInfo['invite_code'];
+        }else{
+            $uid = 0;
+            $inviteCode = '';
         }
         $detail = $this->postRepositories->detail($request['id']);
         if (!$detail) {
             return jsonError('内容飞走了');
         }
         $fractal = new Manager();
-        $res = new Item($detail, new DetailTransformer($userInfo['uid'], $userInfo['invite_code']));
+        $res = new Item($detail, new DetailTransformer($uid, $inviteCode));
         $data = $fractal->createData($res)->toArray();
 
         return jsonSuccess($data);
@@ -342,16 +351,17 @@ class PostController extends Controller
             return jsonError($validator->errors()->first());
         }
         $userInfo = $this->getUserInfo();
-        if (empty($userInfo)) {
-            Log::debug('获取用户信息失败topicDetail'.json_encode($request));
-            return jsonError('获取用户信息失败');
+        if ($userInfo) {
+            $uid = $userInfo['uid'];
+        }else{
+            $uid = 0;
         }
         $detail = $this->postRepositories->topicDetail($request['id']);
         if (!$detail) {
             return jsonError('获取话题信息失败');
         }
         $fractal = new Manager();
-        $res = new Item($detail, new TopicDetailTransformer($userInfo['uid']));
+        $res = new Item($detail, new TopicDetailTransformer($uid));
         $data = $fractal->createData($res)->toArray();
 
         return jsonSuccess($data);
@@ -363,13 +373,16 @@ class PostController extends Controller
     public function topicPost(Request $request)
     {
         $userInfo = $this->getUserInfo();
-        if (empty($userInfo)) {
-            Log::debug('获取用户信息失败topicPost'.json_encode($request));
-            return jsonError('获取用户信息失败');
+        if ($userInfo) {
+            $uid = $userInfo['uid'];
+            $inviteCode = $userInfo['invite_code'];
+        }else{
+            $uid = 0;
+            $inviteCode = '';
         }
         $list = $this->postRepositories->topicPost($request->all());
         $fractal = new Manager();
-        $resource = new Collection($list, new TopicPostTransformer($userInfo['uid'], $userInfo['invite_code']));
+        $resource = new Collection($list, new TopicPostTransformer($uid, $inviteCode));
         $resource->setPaginator(new IlluminatePaginatorAdapter($list));
         $data = $fractal->createData($resource)->toArray();
 

+ 15 - 6
app/Transformers/Post/DetailTransformer.php

@@ -38,10 +38,19 @@ class DetailTransformer extends TransformerAbstract
                 'name' => $val
             ];
         }
+
+        $isLike = 0;
+        $isDislike = 0;
+        $isCollect = 0;
         $isFollow = 0;
-        $followStatus = $this->getFollowStatus($this->uid, $post['uid']);
-        if($followStatus){
-            $isFollow = $followStatus;
+        if($this->uid){
+            $isLike = PostLike::where('post_id', $post['id'])->where('uid', $this->uid)->exists()?1:0;
+            $isDislike = PostDislike::where('post_id', $post['id'])->where('uid', $this->uid)->exists()?1:0;
+            $isCollect = PostCollect::where('post_id', $post['id'])->where('uid', $this->uid)->exists()?1:0;
+            $followStatus = $this->getFollowStatus($this->uid, $post['uid']);
+            if($followStatus){
+                $isFollow = $followStatus;
+            }
         }
         return [
             'id' => $post['id'],
@@ -64,9 +73,9 @@ class DetailTransformer extends TransformerAbstract
             'comment_count' => $post->data->comment_count,
             'available_bean' => $post->data->available_bean,
             'will_collect_bean' => $post->data->will_collect_bean + 3 * $post->data->pv,
-            'is_like' => PostLike::where('post_id', $post['id'])->where('uid', $this->uid)->exists()?1:0,
-            'is_dislike' => PostDislike::where('post_id', $post['id'])->where('uid', $this->uid)->exists()?1:0,
-            'is_collect' => PostCollect::where('post_id', $post['id'])->where('uid', $this->uid)->exists()?1:0,
+            'is_like' => $isLike,
+            'is_dislike' => $isDislike,
+            'is_collect' => $isCollect,
             'is_follow' => $isFollow,
             'h5url' => config('customer.share_post_h5url')."?post_id={$post['id']}&invite_code={$this->invite_code}",
             'desc_url' => $post['type'] == 'html'?config('customer.app_service_url').'/community/fragment/detail/'.$post['id']:'',

+ 5 - 1
app/Transformers/Post/ListTransformer.php

@@ -20,6 +20,10 @@ class ListTransformer extends TransformerAbstract
     }
     public function transform(Post $post)
     {
+        $isLike = 0;
+        if($this->uid){
+            $isLike = PostLike::where('post_id', $post['id'])->where('uid', $this->uid)->exists()?1:0;
+        }
         return [
             'id' => $post['id'],
             'type' => $post['type'],
@@ -30,7 +34,7 @@ class ListTransformer extends TransformerAbstract
             'content' => subtext($post['content'], 100),
             'img' => $post['img'],
             'praise_count' => $post->data->praise_count,
-            'is_like' => PostLike::where('post_id', $post['id'])->where('uid', $this->uid)->exists()?1:0,
+            'is_like' => $isLike,
             'h5url' => config('customer.share_post_h5url')."?post_id={$post['id']}&invite_code={$this->invite_code}",
             'desc_url' => $post['type'] == 'html'?config('customer.app_service_url').'/community/fragment/detail/'.$post['id']:'',
         ];

+ 11 - 5
app/Transformers/Post/VideoTransformer.php

@@ -23,10 +23,16 @@ class VideoTransformer extends TransformerAbstract
     }
     public function transform(Post $post)
     {
+        $isLike = 0;
+        $isCollect = 0;
         $isFollow = 0;
-        $followStatus = $this->getFollowStatus($this->uid, $post['uid']);
-        if($followStatus){
-            $isFollow = $followStatus;
+        if($this->uid){
+            $isLike = PostLike::where('post_id', $post['id'])->where('uid', $this->uid)->exists()?1:0;
+            $isCollect = PostCollect::where('post_id', $post['id'])->where('uid', $this->uid)->exists()?1:0;
+            $followStatus = $this->getFollowStatus($this->uid, $post['uid']);
+            if($followStatus){
+                $isFollow = $followStatus;
+            }
         }
         $topic = [];
         foreach($post->topic() as $key => $val){
@@ -50,8 +56,8 @@ class VideoTransformer extends TransformerAbstract
             'collect_count' => $post->data->collect_count,
             'comment_count' => $post->data->comment_count,
             'will_collect_bean' => $post->data->will_collect_bean + 3 * $post->data->pv,
-            'is_like' => PostLike::where('post_id', $post['id'])->where('uid', $this->uid)->exists()?1:0,
-            'is_collect' => PostCollect::where('post_id', $post['id'])->where('uid', $this->uid)->exists()?1:0,
+            'is_like' => $isLike,
+            'is_collect' => $isCollect,
             'is_follow' => $isFollow,
             'h5url' => config('customer.share_post_h5url')."?post_id={$post['id']}&invite_code={$this->invite_code}",
             'desc_url' => $post['type'] == 'html'?config('customer.app_service_url').'/community/fragment/detail/'.$post['id']:'',

+ 5 - 1
app/Transformers/Topic/TopicDetailTransformer.php

@@ -19,12 +19,16 @@ class TopicDetailTransformer extends TransformerAbstract
     }
     public function transform(Topic $topic)
     {
+        $isFollow = 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->follow->count() + $topic['base_count']),
-            'is_follow' => $topic->follow->where('uid', $this->uid)->count()?1:0,
+            'is_follow' => $isFollow,
         ];
     }
 }

+ 14 - 6
app/Transformers/Topic/TopicPostTransformer.php

@@ -58,10 +58,18 @@ class TopicPostTransformer extends TransformerAbstract
                 'name' => $val
             ];
         }
+        $isLike = 0;
+        $isDislike = 0;
+        $isCollect = 0;
         $isFollow = 0;
-        $followStatus = $this->getFollowStatus($this->uid, $post['uid']);
-        if($followStatus){
-            $isFollow = $followStatus;
+        if($this->uid){
+            $isLike = PostLike::where('post_id', $post['id'])->where('uid', $this->uid)->exists()?1:0;
+            $isDislike = PostDislike::where('post_id', $post['id'])->where('uid', $this->uid)->exists()?1:0;
+            $isCollect = PostCollect::where('post_id', $post['id'])->where('uid', $this->uid)->exists()?1:0;
+            $followStatus = $this->getFollowStatus($this->uid, $post['uid']);
+            if($followStatus){
+                $isFollow = $followStatus;
+            }
         }
         return [
             'id' => $post['id'],
@@ -81,9 +89,9 @@ class TopicPostTransformer extends TransformerAbstract
             'praise_count' => $post->data->praise_count,
             'comment_count' => $post->data->comment_count,
             'will_collect_bean' => $post->data->will_collect_bean + 3 * $post->data->pv,
-            'is_like' => PostLike::where('post_id', $post['id'])->where('uid', $this->uid)->exists()?1:0,
-            'is_dislike' => PostDislike::where('post_id', $post['id'])->where('uid', $this->uid)->exists()?1:0,
-            'is_collect' => PostCollect::where('post_id', $post['id'])->where('uid', $this->uid)->exists()?1:0,
+            'is_like' => $isLike,
+            'is_dislike' => $isDislike,
+            'is_collect' => $isCollect,
             'comment' => $comment,
             'is_follow' => $isFollow,
             'h5url' => config('customer.share_post_h5url')."?post_id={$post['id']}&invite_code={$this->invite_code}",

+ 12 - 11
routes/api.php

@@ -30,8 +30,6 @@ $api->version('v1', [
     });
     //登录
     $api->group(['middleware' => ['chxq_jwt_auth']], function ($api) {
-        //内容详情
-        $api->get('post/detail', 'PostController@detail');
         //获取热门分类下音乐列表
         $api->get('musicList', 'MusicListController@index');
         //音乐分类列表
@@ -43,8 +41,20 @@ $api->version('v1', [
         $api->post('music/upload', 'MusicListController@addMusic');
 
     });
+
+    //内容列表
+    $api->get('post', 'PostController@index');
+    //视频列表
+    $api->get('post/video', 'PostController@video');
     //推荐内容
     $api->get('post/suggest', 'PostController@suggestPost');
+    //内容详情
+    $api->get('post/detail', 'PostController@detail');
+    //话题内容列表
+    $api->get('post/topic', 'PostController@topicPost');
+    //话题详情
+    $api->get('topic/detail', 'PostController@topicDetail');
+
     //登录+验签
     $api->group(['middleware' => ['chxq_jwt_auth','chxq_sign']], function ($api) {
         //发布内容
@@ -53,10 +63,6 @@ $api->version('v1', [
         $api->delete('post', 'PostController@delete');
         //个人中心内容
         $api->get('post/my', 'PostController@myPost');
-        //内容列表
-        $api->get('post', 'PostController@index');
-        //视频列表
-        $api->get('post/video', 'PostController@video');
         //评价&回复
         $api->post('post/comment', 'PostController@comment');
         //评价列表
@@ -69,14 +75,10 @@ $api->version('v1', [
         $api->get('topicCategory/getTopics', 'CategoryController@getTopics');
         //获取话题
         $api->get('topic/group', 'PostController@getTopic');
-        //话题内容列表
-        $api->get('post/topic', 'PostController@topicPost');
         //话题列表
         $api->get('topic', 'PostController@topicList');
         //获取内容视频组
         $api->get('post/video/group', 'PostController@getPostVideo');
-        //话题详情
-        $api->get('topic/detail', 'PostController@topicDetail');
         //关注推荐话题
         $api->post('memberFollowTopic', 'MemberFollowTopic@memberFollowTopic');
         //关注单个话题
@@ -89,7 +91,6 @@ $api->version('v1', [
         $api->get('memberFollowTopic', 'MemberFollowTopic@index');
         //收藏列表
         $api->get('postCollect', 'PostCollectController@index');
-
         //用户发布数,收藏数,转发数
         $api->get('post/memberPostStatistics', 'PostController@memberPostStatistics');
         //关注feed流