|
@@ -11,15 +11,23 @@ namespace App\Repositories;
|
|
|
|
|
|
use App\Models\Behavior;
|
|
|
use App\Models\Feed;
|
|
|
+use App\Models\PostComment;
|
|
|
use Carbon\Carbon;
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
+use Tymon\JWTAuth\Facades\JWTAuth;
|
|
|
+use App\Models\PostDislike;
|
|
|
+use App\Models\PostLike;
|
|
|
+use App\Models\PostCollect;
|
|
|
+use App\Traits\UserTrait;
|
|
|
|
|
|
class FeedRepositories
|
|
|
{
|
|
|
- public function __construct(Feed $feed,PostRepositories $postRepositories)
|
|
|
+ use UserTrait;
|
|
|
+ public function __construct(Feed $feed,PostRepositories $postRepositories,PostComment $postComment)
|
|
|
{
|
|
|
$this->feed = $feed;
|
|
|
$this->postRepositories = $postRepositories;
|
|
|
+ $this->postComment = $postComment;
|
|
|
}
|
|
|
|
|
|
public function getFeedType($action)
|
|
@@ -99,6 +107,76 @@ class FeedRepositories
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
+ //我的feed
|
|
|
+ public function myFeed($request){
|
|
|
+ $token = JWTAuth::decode(JWTAuth::getToken());
|
|
|
+ $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
|
|
|
+ $where[] = ['uid',$token['user']->uid];
|
|
|
+ $data = $this->feed
|
|
|
+ ->where($where)
|
|
|
+ ->orderBy('id','desc')
|
|
|
+ ->paginate($perPage);
|
|
|
+ if($data){
|
|
|
+ foreach ($data as $key=>$value){
|
|
|
+ if($value['type'] == 6){
|
|
|
+ $post = $this->postRepositories->detail($value['relate_id']);
|
|
|
+ $value['relate_data'] = $this->postDetail($post);
|
|
|
+ }
|
|
|
+ if($value['type'] == 5){
|
|
|
+ $value['relate_data'] = $this->getFollowMemberFans($value['relate_id']);
|
|
|
+ }
|
|
|
+ $data[] = $value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+ public function postDetail($post){
|
|
|
+ $token = JWTAuth::decode(JWTAuth::getToken());
|
|
|
+ $uid = $token['user']->uid;
|
|
|
+ $imgs = [];
|
|
|
+ foreach($post->imgs as $img){
|
|
|
+ $imgs[] = $img['img'];
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
+ $topic = [];
|
|
|
+ foreach($post->topic() as $key => $val){
|
|
|
+ $topic[] = [
|
|
|
+ 'id' => $key,
|
|
|
+ 'name' => $val
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $isFollow = 0;
|
|
|
+ $followStatus = $this->getFollowStatus($uid, $post['follow_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,
|
|
|
+ 'available_bean' => $post->data->available_bean,
|
|
|
+ 'will_collect_bean' => $post->data->will_collect_bean,
|
|
|
+ 'post_comment' => $this->getPostComment($post['id']),
|
|
|
+ 'is_like' => PostLike::where('post_id', $post['id'])->where('uid', $uid)->exists()?1:0,
|
|
|
+ 'is_dislike' => PostDislike::where('post_id', $post['id'])->where('uid', $uid)->exists()?1:0,
|
|
|
+ 'is_collect' => PostCollect::where('post_id', $post['id'])->where('uid', $uid)->exists()?1:0,
|
|
|
+ 'is_follow' => $isFollow,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ public function getPostComment($post_id){
|
|
|
+ return $this->postComment->where(['post_id'=>$post_id,'parent_id'=>0,'is_delete'=>0 ])->select('id','uid','username','content')->orderBy('id','desc')->take(2)->get();
|
|
|
+ }
|
|
|
}
|