zhangchangchun vor 5 Jahren
Ursprung
Commit
ea00fa6fb7

+ 1 - 0
app/Console/Commands/BehaviorRecord.php

@@ -81,6 +81,7 @@ class BehaviorRecord extends Command
 
         $callback = function ($msg) {
             $param = \GuzzleHttp\json_decode($msg->body,true);
+            $this->line(date('Y-m-d H:i:s').'开始记录账本');
             $row = $this->behaviorRecordRepositories->addRecord($param);
             if($row){
                 $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);

+ 8 - 5
app/Console/Commands/CalcPostWeight.php

@@ -42,23 +42,26 @@ class CalcPostWeight extends Command
      */
     public function handle()
     {
-        $this->line('开始计算权重');
+        $this->line(date('Y-m-d H:i:s').'开始计算权重');
         $key = "community_calc_post_score";
         $postIds = Redis::smembers($key);
-        Log::debug('权重帖子ID:'.json_encode($postIds));
+        Log::debug('权重帖子ID:' . json_encode($postIds));
         foreach ($postIds as $postId) {
             $postInfo = PostData::where("post_id", $postId)->first();
-            $temp = $postInfo['pv'] +
+            Log::debug('帖子:' . json_encode($postInfo));
+            $temp = ($postInfo['pv'] +
                 (5 * $postInfo->share_cout) +
                 (2 * $postInfo->praise_count) +
                 (10 * $postInfo->collect_count) +
                 (3 * $postInfo->comment_count) -
-                (10 * $postInfo->dislike_count);
+                (10 * $postInfo->dislike_count));
             $fresh = (Carbon::parse($postInfo['created_at'])->timestamp) - (Carbon::parse("2019-05-01 00:00:00")->timestamp);
             $score = log10($temp) + $fresh / 86400;
             $postInfo->weight = $score;
             $postInfo->save();
-            $this->line(date("Y-m-d H:i:s")."设置帖子".$postInfo->post_id."的权重分为:".$score);
+            Redis::srem($key,$postId);
+            Log::debug(date("Y-m-d H:i:s") . "设置帖子" . $postInfo->post_id . "的权重分为:" . $score);
         }
+        $this->line(date('Y-m-d H:i:s').' 计算权重结束');
     }
 }

+ 1 - 1
app/Console/Commands/ContentFeedCreate.php

@@ -81,7 +81,7 @@ class ContentFeedCreate extends Command
 
         $callback = function ($msg) {
             $param = \GuzzleHttp\json_decode($msg->body,true);
-            $this->line('收到消息'.$msg->body);
+            $this->line(date('Y-m-d H:i:s').'收到消息:'.$msg->body);
             $this->feedRepositories->contentCreate($param);
             $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
         };

+ 111 - 0
app/Http/Controllers/V1/PostController.php

@@ -13,8 +13,13 @@ use App\Traits\UserTrait;
 use App\Transformers\Post\CommentTransformer;
 use App\Transformers\Post\DetailTransformer;
 use App\Transformers\Post\ListTransformer;
+use App\Transformers\Post\MyTransformer;
 use App\Transformers\Post\ReplyTransformer;
 use App\Transformers\Post\SuggestTransformer;
+use App\Transformers\Post\VideoTransformer;
+use App\Transformers\Topic\TopicDetailTransformer;
+use App\Transformers\Topic\TopicListTransformer;
+use App\Transformers\Topic\TopicPostTransformer;
 use Illuminate\Http\Request;
 use Illuminate\Support\Carbon;
 use Illuminate\Support\Facades\Log;
@@ -90,6 +95,51 @@ class PostController extends Controller
         return jsonSuccess($data);
     }
 
+    /**
+     * 视频列表
+     */
+    public function video(Request $request)
+    {
+        $userInfo = $this->getUserInfo();
+        if(empty($userInfo)){
+            Log::info('获取用户信息失败');
+            return jsonError('获取用户信息失败');
+        }
+        $list = $this->postRepositories->video($request->all());
+        $fractal = new Manager();
+        $resource = new Collection($list, new VideoTransformer($userInfo['uid']));
+        $resource->setPaginator(new IlluminatePaginatorAdapter($list));
+        $data = $fractal->createData($resource)->toArray();
+
+        return jsonSuccess($data);
+    }
+
+    /**
+     * 个人中心内容
+     */
+    public function myPost(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'type' => ['required',Rule::in('create', 'collect', 'share')],
+        ]);
+        if ($validator->fails()) {
+            return jsonError($validator->errors()->first());
+        }
+
+        $userInfo = $this->getUserInfo();
+        if(empty($userInfo)){
+            Log::info('获取用户信息失败');
+            return jsonError('获取用户信息失败');
+        }
+        $list = $this->postRepositories->myPost($request['type'], $userInfo['uid']);
+        $fractal = new Manager();
+        $resource = new Collection($list, new MyTransformer());
+        $resource->setPaginator(new IlluminatePaginatorAdapter($list));
+        $data = $fractal->createData($resource)->toArray();
+
+        return jsonSuccess($data);
+    }
+
     /**
      * 推荐内容列表
      */
@@ -188,5 +238,66 @@ class PostController extends Controller
         return jsonSuccess($data);
     }
 
+    /**
+     * 话题列表
+     */
+    public function topicList(Request $request)
+    {
+        $list = $this->postRepositories->topicList($request->all());
+        $fractal = new Manager();
+        $resource = new Collection($list, new TopicListTransformer());
+        $resource->setPaginator(new IlluminatePaginatorAdapter($list));
+        $data = $fractal->createData($resource)->toArray();
+
+        return jsonSuccess($data);
+    }
+
+
+    /**
+     * 话题详情
+     */
+    public function topicDetail(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'id' => 'required|integer',
+        ]);
+        if ($validator->fails()) {
+            return jsonError($validator->errors()->first());
+        }
+        $userInfo = $this->getUserInfo();
+        if(empty($userInfo)){
+            Log::info('获取用户信息失败');
+            return jsonError('获取用户信息失败');
+        }
+        $detail = $this->postRepositories->topicDetail($request['id']);
+        if(!$detail){
+            return jsonError('获取话题信息失败');
+        }
+        $fractal = new Manager();
+        $res = new Item($detail, new TopicDetailTransformer($userInfo['uid']));
+        $data = $fractal->createData($res)->toArray();
+
+        return jsonSuccess($data);
+    }
+
+    /**
+     * 话题内容列表
+     */
+    public function topicPost(Request $request)
+    {
+        $userInfo = $this->getUserInfo();
+        if(empty($userInfo)){
+            Log::info('获取用户信息失败');
+            return jsonError('获取用户信息失败');
+        }
+        $list = $this->postRepositories->topicPost($request->all());
+        $fractal = new Manager();
+        $resource = new Collection($list, new TopicPostTransformer($userInfo['uid']));
+        $resource->setPaginator(new IlluminatePaginatorAdapter($list));
+        $data = $fractal->createData($resource)->toArray();
+
+        return jsonSuccess($data);
+    }
+
 
 }

+ 1 - 0
app/Models/PostShare.php

@@ -2,6 +2,7 @@
 /**
  * Created by PhpStorm.
  * User: Administrator
+<<<<<<< HEAD
  * Date: 2019-06-18
  * Time: 17:14
  */

+ 4 - 0
app/Models/Topic.php

@@ -15,4 +15,8 @@ class Topic extends Model
     protected $table = 'topic';
     protected $guarded = [];
 
+    public function follow()
+    {
+        return $this->hasMany('App\Models\MemberFollowTopic', 'topic_id', 'id');
+    }
 }

+ 5 - 4
app/Repositories/BehaviorRecordRepositories.php

@@ -98,6 +98,7 @@ class BehaviorRecordRepositories
             $data['generation_quantity'] = $register['generation_quantity'];
             $data['quantity_issued'] = $register['quantity_issued'];
             $this->registeredAccountsRecord->create($data);
+            //修改行为统计数据
             $behavior = Behavior::where('virus_behavior_id',$register['virus_behavior_id'])->first();
             $behavior->physical_strength += $register['physical_exertion'];
             $behavior->grant_rainbow_beans += $register['quantity_issued'];
@@ -111,7 +112,7 @@ class BehaviorRecordRepositories
             DB::commit();
             return true;
         } catch (QueryException $exception) {
-            Log::debug('记录账本-exception:'.$exception->getMessage());
+            Log::debug('记录账本-注册-exception:'.$exception->getMessage());
             DB::rollBack();
             return false;
         }
@@ -149,7 +150,7 @@ class BehaviorRecordRepositories
             DB::commit();
             return true;
         } catch (QueryException $exception) {
-            Log::debug('addReleaseRecord-exception:'.$exception->getMessage());
+            Log::debug('记录账本-发布-exception:'.$exception->getMessage());
             DB::rollBack();
             return false;
         }
@@ -188,7 +189,7 @@ class BehaviorRecordRepositories
             DB::commit();
             return true;
         } catch (QueryException $exception) {
-            Log::debug('addGeneralRecord-exception:'.$exception->getMessage());
+            Log::debug('记录账本-普通行为-exception:'.$exception->getMessage());
             DB::rollBack();
             return false;
         }
@@ -229,7 +230,7 @@ class BehaviorRecordRepositories
             DB::commit();
             return true;
         } catch (QueryException $exception) {
-            Log::debug('addCommentRecord-exception:'.$exception->getMessage());
+            Log::debug('记录账本-评论-exception:'.$exception->getMessage());
             DB::rollBack();
             return false;
         }

+ 6 - 1
app/Repositories/FeedRepositories.php

@@ -42,7 +42,10 @@ class FeedRepositories
      */
     public function contentCreate($request){
         $this->feedCreate($request);
-        $this->postRepositories->updatePostData($request);
+        //关注操作不需要调用
+        if($request['behavior_flag']!='focus'){
+            $this->postRepositories->updatePostData($request);
+        }
     }
 
 
@@ -79,8 +82,10 @@ class FeedRepositories
                     $content['comment_desc'] = $request['comment_content'];
                 }elseif ($feedType==6){//发布
                     $data['relate_id'] = $request['post_id'];
+                    $content['post_desc'] = $request['post_desc'];
                 }elseif ($feedType==5){//关注
                     $data['relate_id'] = $request['focus_uid'];
+                    $content = "";
                 }
                 $data['content'] = json_encode($content);
                 $data['created_at'] = Carbon::now();

+ 127 - 3
app/Repositories/PostRepositories.php

@@ -16,6 +16,7 @@ use App\Models\PostComment;
 use App\Models\PostData;
 use App\Models\PostImgs;
 use App\Models\PostLike;
+use App\Models\PostShare;
 use App\Models\Topic;
 use App\Service\DetectionService;
 use App\Service\RabbitMqUtil;
@@ -35,6 +36,8 @@ class PostRepositories
                                 PostData $postData,
                                 PostImgs $postImgs,
                                 PostComment $postComment,
+                                PostCollect $postCollect,
+                                PostShare $postShare,
                                 DetectionService $detectionService,
                                 RabbitMqUtil $rabbitMqUtil,
                                 Topic $topic)
@@ -43,6 +46,8 @@ class PostRepositories
         $this->postData = $postData;
         $this->postImgs = $postImgs;
         $this->postComment = $postComment;
+        $this->postCollect = $postCollect;
+        $this->postShare = $postShare;
         $this->detectionService = $detectionService;
         $this->rabbitMqUtil = $rabbitMqUtil;
         $this->topic = $topic;
@@ -255,12 +260,12 @@ class PostRepositories
 
         DB::beginTransaction();
         try{
-            $this->postComment->create($data);
+            $comment = $this->postComment->create($data);
             $post->data->comment_count += 1;
             $post->data->save();
 
             DB::commit();
-            return jsonSuccess();
+            return jsonSuccess(['id' => $comment->id], '评论成功');
 
         }catch (QueryException $exception){
             DB::rollBack();
@@ -285,10 +290,71 @@ class PostRepositories
                         ->orWhere('content', 'like', "%{$request['keyword']}%");
                 }
             })
+            ->where(function($query) use ($request){
+                if(isset($request['topic_ids'])){
+                    $topicIds = json_decode($request['topic_ids'], true);
+                    foreach ($topicIds as $key=>$id) {
+                        if ($key==0) {
+                            $query->whereRaw('FIND_IN_SET('.$id.', post.topic_ids)');
+                        } else {
+                            $query->orWhereRaw('FIND_IN_SET('.$id.', post.topic_ids)');
+                        }
+                    }
+                }
+            })
+            ->orderBy('weight','desc')
+            ->paginate($perPage);
+    }
+
+    /**
+     * 视频列表
+     */
+    public function video($request)
+    {
+        $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
+
+        $where = [];
+        if(isset($request['id'])){
+            $where[] = ['post.id', '<>', $request['id']];
+        }
+        $where[] = ['type', 'video'];
+        return $this->post
+            ->join('post_data', 'post_data.post_id', '=', 'post.id')
+            ->select('post.*')
+            ->where($where)
             ->orderBy('weight','desc')
             ->paginate($perPage);
     }
 
+    /**
+     * 个人中心内容列表
+     */
+    public function MyPost($type, $uid)
+    {
+        $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
+
+        $where = [];
+        if($type == 'create'){
+            $where[] = ['post.uid', $uid];
+            $post = $this->post;
+            $order = 'post.id';
+        }elseif($type == 'collect'){
+            $post = $this->post->join('post_collect', 'post_collect.post_id', '=', 'post.id');
+            $where[] = ['post_collect.uid', $uid];
+            $order = 'post_collect.id';
+        }else{
+            $post = $this->post->join('post_share', 'post_share.post_id', '=', 'post.id');
+            $where[] = ['post_share.uid', $uid];
+            $order = 'post_share.updated_at';
+        }
+        return $post
+            ->join('post_data', 'post_data.post_id', '=', 'post.id')
+            ->select('post.*')
+            ->where($where)
+            ->orderBy($order,'desc')
+            ->paginate($perPage);
+    }
+
     /**
      * 内容详情
      */
@@ -314,6 +380,21 @@ class PostRepositories
             ->paginate($perPage);
     }
 
+    /**
+     * 话题内容
+     */
+    public function topicPost($request)
+    {
+        $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
+
+        return $this->post
+            ->join('post_data', 'post_data.post_id', '=', 'post.id')
+            ->select('post.*')
+            ->whereRaw('FIND_IN_SET(' . $request['id'] . ',post.topic_ids)')
+            ->orderBy('id','desc')
+            ->paginate($perPage);
+    }
+
 
     /**
      * 评论列表
@@ -342,6 +423,29 @@ class PostRepositories
             ->paginate($perPage);
     }
 
+    /**
+     * 话题列表
+     */
+    public function topicList($request)
+    {
+        $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
+
+        $where = [];
+        if(isset($request['category_id'])){
+           $topic = $this->topic->join('category_topic', 'category_topic.topic_id', '=', 'topic.id')->select('topic.*');
+           $where[] = ['category_topic.category_id', $request['category_id']];
+        }else{
+            $topic = $this->topic;
+        }
+        if(isset($request['is_suggest'])){
+            $where[] = ['topic.is_suggest', $request['is_suggest']];
+        }
+        return $topic
+            ->where($where)
+            ->orderBy('id','desc')
+            ->paginate($perPage);
+    }
+
 
     /**
      * 更新帖子统计数量
@@ -350,7 +454,11 @@ class PostRepositories
      */
     public function updatePostData($request)
     {
-        $postId = $request['post_id'];
+        $postId = isset($request['post_id'])?$request['post_id']:0;
+        if(empty($postId)){
+            Log::debug("非帖子类操作,不操作帖子统计数量".json_encode($request));
+            return true;
+        }
         $post = PostData::where('post_id', $postId)->first();
         if (isset($request['behavior_flag']) && $request['behavior_flag'] == 'read') {
             $post->pv += 1;
@@ -374,6 +482,12 @@ class PostRepositories
         } elseif (isset($request['behavior_flag']) && $request['behavior_flag'] == 'forward') {
             $post->share_count += 1;
             $post->share_real_count += 1;
+            $shareRow = PostShare::where(['uid'=>$request['target_id'],'post_id'=>$request['post_id']])->first();
+            if($shareRow){
+                PostShare::where(['uid'=>$request['target_id'],'post_id'=>$request['post_id']])->update(['uid'=>$request['target_id'],'post_id'=>$request['post_id']]);
+            }else{
+                PostShare::create(['uid'=>$request['target_id'],'post_id'=>$request['post_id']]);
+            }
             Log::debug("帖子:".$postId."被分享,share_count +1");
         } elseif (isset($request['behavior_flag']) && $request['behavior_flag'] == 'comment') {
             $post->comment_count += 1;
@@ -408,4 +522,14 @@ class PostRepositories
     }
 
 
+    /**
+     * 话题详情
+     */
+    public function topicDetail($id)
+    {
+        return $this->topic
+            ->find($id);
+    }
+
+
 }

+ 1 - 1
app/Traits/UserTrait.php

@@ -31,7 +31,7 @@ trait UserTrait
             $sign = generateSign([], config('customer.app_secret'));
             $url = config("customer.app_service_url").'/user/v2/follow/checkStatus';
             $array = [
-                'json' => ['sign' => $sign, 'uid' => $uid, 'follow_uid' => $followUid], 'query' => [], 'http_errors' => false,'headers'=>['Authorization'=>"Bearer ".JWTAuth::getToken()]
+                'json' => ['sign' => $sign, 'uid' => $followUid, 'follow_uid' => $uid], 'query' => [], 'http_errors' => false,'headers'=>['Authorization'=>"Bearer ".JWTAuth::getToken()]
             ];
             return http($url,$array,'get');
         } catch (\Exception $e) {

+ 2 - 1
app/Transformers/Post/CommentTransformer.php

@@ -21,10 +21,11 @@ class CommentTransformer extends TransformerAbstract
         foreach($replies as $val){
             $reply[] = [
                 'uid' => $val->uid,
-                'nickname' => $val->nickname,
+                'username' => $val->username,
                 'avatar' => $val->avatar,
                 'reply_username' => $val->reply_username,
                 'content' => $val->content,
+                'created_at' => Carbon::parse($val->created_at)->diffForHumans(),
             ];
         }
         return [

+ 24 - 0
app/Transformers/Post/MyTransformer.php

@@ -0,0 +1,24 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/18
+ * Time: 10:44
+ */
+namespace  App\Transformers\Post;
+
+use App\Models\Post;
+use League\Fractal\TransformerAbstract;
+
+class MyTransformer extends TransformerAbstract
+{
+    public function transform(Post $post)
+    {
+        return [
+            'id' => $post['id'],
+            'img' => $post['img'],
+            'create_bean' => $post->data->create_bean,
+            'collect_bean' => $post->data->collect_bean,
+        ];
+    }
+}

+ 2 - 2
app/Transformers/Post/SuggestTransformer.php

@@ -38,14 +38,14 @@ class SuggestTransformer extends TransformerAbstract
             $reply = [];
             foreach($replies as $val){
                 $reply[] = [
-                    'nickname' => $val->nickname,
+                    'username' => $val->username,
                     'reply_username' => $val->reply_username,
                     'content' => $val->content,
                 ];
             }
             $comment[] = [
                 'id' => $item->id,
-                'nickname' => $item->nickname,
+                'username' => $item->username,
                 'content' => $item->content,
                 'reply_count' => $replyCount,
                 'reply' => $reply,

+ 56 - 0
app/Transformers/Post/VideoTransformer.php

@@ -0,0 +1,56 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/18
+ * Time: 10:08
+ */
+namespace  App\Transformers\Post;
+
+use App\Models\Post;
+use App\Models\PostCollect;
+use App\Models\PostLike;
+use App\Traits\UserTrait;
+use League\Fractal\TransformerAbstract;
+
+class VideoTransformer extends TransformerAbstract
+{
+    use UserTrait;
+    public function __construct($uid)
+    {
+        $this->uid = $uid;
+    }
+    public function transform(Post $post)
+    {
+        $isFollow = 0;
+        $followStatus = $this->getFollowStatus($this->uid, $post['uid']);
+        if($followStatus){
+            $isFollow = $followStatus;
+        }
+        $topic = [];
+        foreach($post->topic() as $key => $val){
+            $topic[] = [
+                'id' => $key,
+                'name' => $val
+            ];
+        }
+        return [
+            'id' => $post['id'],
+            'type' => $post['type'],
+            'uid' => $post['uid'],
+            'username' => $post['username'],
+            'avatar' => $post['avatar'],
+            'title' => $post['title'],
+            'content' => $post['content'],
+            'img' => $post['img'],
+            'video' => $post['video'],
+            'topic' => $topic,
+            'praise_count' => $post->data->praise_count,
+            'collect_count' => $post->data->collect_count,
+            'comment_count' => $post->data->comment_count,
+            '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_follow' => $isFollow,
+        ];
+    }
+}

+ 30 - 0
app/Transformers/Topic/TopicDetailTransformer.php

@@ -0,0 +1,30 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/17
+ * Time: 18:10
+ */
+namespace  App\Transformers\Topic;
+
+use App\Models\Topic;
+use Carbon\Carbon;
+use League\Fractal\TransformerAbstract;
+
+class TopicDetailTransformer extends TransformerAbstract
+{
+    public function __construct($uid)
+    {
+        $this->uid = $uid;
+    }
+    public function transform(Topic $topic)
+    {
+        return [
+            'id' => $topic['id'],
+            'name' => $topic['name'],
+            'img' => $topic['img'],
+            'follow_count' => $topic->follow->count() + 9876,
+            'is_follow' => $topic->follow->where('uid', $this->uid)->count()?1:0,
+        ];
+    }
+}

+ 24 - 0
app/Transformers/Topic/TopicListTransformer.php

@@ -0,0 +1,24 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/18
+ * Time: 13:57
+ */
+namespace  App\Transformers\Topic;
+
+use App\Models\Topic;
+use Carbon\Carbon;
+use League\Fractal\TransformerAbstract;
+
+class TopicListTransformer extends TransformerAbstract
+{
+    public function transform(Topic $topic)
+    {
+        return [
+            'id' => $topic['id'],
+            'name' => $topic['name'],
+            'follow_count' => $topic->follow->count() + 9876,
+        ];
+    }
+}

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

@@ -0,0 +1,90 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/17
+ * Time: 19:26
+ */
+namespace  App\Transformers\Topic;
+
+use App\Models\Post;
+use App\Models\PostCollect;
+use App\Models\PostComment;
+use App\Models\PostDislike;
+use App\Models\PostLike;
+use App\Traits\UserTrait;
+use Carbon\Carbon;
+use League\Fractal\TransformerAbstract;
+
+class TopicPostTransformer extends TransformerAbstract
+{
+    use UserTrait;
+    public function __construct($uid)
+    {
+        $this->uid = $uid;
+    }
+    public function transform(Post $post)
+    {
+        $imgs = [];
+        foreach($post->imgs as $img){
+            $imgs[] = $img['img'];
+        }
+        $comment = [];
+        $comments = PostComment::where('post_id', $post['id'])->where('parent_id', 0)->orderBy('id', 'desc')->limit(2)->get();
+        foreach($comments as $item){
+            $replyCount = $item->reply->count();
+            $replies = PostComment::where('parent_id', $item->id)->orderBy('id', 'desc')->limit(2)->get();
+            $reply = [];
+            foreach($replies as $val){
+                $reply[] = [
+                    'username' => $val->username,
+                    'reply_username' => $val->reply_username,
+                    'content' => $val->content,
+                ];
+            }
+            $comment[] = [
+                'id' => $item->id,
+                'username' => $item->username,
+                'content' => $item->content,
+                'reply_count' => $replyCount,
+                'reply' => $reply,
+            ];
+        }
+        $topic = [];
+        foreach($post->topic() as $key => $val){
+            $topic[] = [
+                'id' => $key,
+                'name' => $val
+            ];
+        }
+        $isFollow = 0;
+        $followStatus = $this->getFollowStatus($this->uid, $post['uid']);
+        if($followStatus){
+            $isFollow = $followStatus;
+        }
+        return [
+            'id' => $post['id'],
+            'type' => $post['type'],
+            'created_at' => Carbon::parse($post['created_at'])->diffForHumans(),
+            'uid' => $post['uid'],
+            'username' => $post['username'],
+            'avatar' => $post['avatar'],
+            'topic' => $topic,
+            'title' => $post['title'],
+            'content' => $post['content'],
+            'location' => $post['location'],
+            'img' => $post['img'],
+            'imgs' => $imgs,
+            'video' => $post['video'],
+            'pv' => $post->data->pv,
+            'praise_count' => $post->data->praise_count,
+            'comment_count' => $post->data->comment_count,
+            'will_collect_bean' => $post->data->will_collect_bean,
+            '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,
+            'comment' => $comment,
+            'is_follow' => $isFollow,
+        ];
+    }
+}

+ 19 - 0
routes/api.php

@@ -20,15 +20,34 @@ $api->version('v1', [
     $api->get('getBehaviorByIdentify', 'BehaviorController@getBehaviorByIdentify');
     //登录+验签
     $api->group(['middleware' => ['chxq_jwt_auth']], function ($api) {
+        //发布内容
         $api->post('post', 'PostController@create');
+        //个人中心内容
+        $api->get('post/my', 'PostController@myPost');
+        //内容列表
         $api->get('post', 'PostController@index');
+        //视频列表
+        $api->get('post/video', 'PostController@video');
+        //内容详情
         $api->get('post/detail', 'PostController@detail');
+        //推荐内容
         $api->get('post/suggest', 'PostController@suggestPost');
+        //评价&回复
         $api->post('post/comment', 'PostController@comment');
+        //评价列表
         $api->get('post/comment', 'PostController@commentList');
+        //回复列表
         $api->get('post/reply', 'PostController@replyList');
+        //话题分类
         $api->get('topicCategory', 'CategoryController@index');
+        //获取话题
         $api->get('topicCategory/getTopics', 'CategoryController@getTopics');
+        //话题内容列表
+        $api->get('post/topic', 'PostController@topicPost');
+        //话题列表
+        $api->get('topic', 'PostController@topicList');
+        //话题详情
+        $api->get('topic/detail', 'PostController@topicDetail');
         //关注推荐话题
         $api->post('memberFollowTopic', 'MemberFollowTopic@memberFollowTopic');
         //关注话题