|
@@ -12,6 +12,7 @@ namespace App\Repositories;
|
|
|
use App\Models\Behavior;
|
|
|
use App\Models\Feed;
|
|
|
use App\Models\PostComment;
|
|
|
+use App\Traits\PostTrait;
|
|
|
use Carbon\Carbon;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Support\Facades\Log;
|
|
@@ -25,6 +26,7 @@ use App\Traits\UserTrait;
|
|
|
class FeedRepositories
|
|
|
{
|
|
|
use UserTrait;
|
|
|
+ use PostTrait;
|
|
|
|
|
|
public function __construct(PostRepositories $postRepositories, PostComment $postComment)
|
|
|
{
|
|
@@ -186,18 +188,8 @@ class FeedRepositories
|
|
|
{
|
|
|
Log::debug('feed流内容--' . json_encode($post));
|
|
|
$uid = $userInfo['uid'];
|
|
|
- $imgs = [];
|
|
|
- foreach ($post->imgs as $img) {
|
|
|
- $imgs[] = $img['img'];
|
|
|
- }
|
|
|
+ $postInfo = $this->getPostInfo($post['id']);
|
|
|
|
|
|
- $topic = [];
|
|
|
- foreach ($post->topic() as $key => $val) {
|
|
|
- $topic[] = [
|
|
|
- 'id' => $key,
|
|
|
- 'name' => $val
|
|
|
- ];
|
|
|
- }
|
|
|
$isFollow = 0;
|
|
|
Log::debug("内容feed关注uid{$uid}followUid{$follow_uid}");
|
|
|
$followStatus = $this->getFollowStatus($uid, $follow_uid);
|
|
@@ -212,42 +204,28 @@ class FeedRepositories
|
|
|
'uid' => $post['uid'],
|
|
|
'username' => $user['username'],
|
|
|
'avatar' => $user['avatar'],
|
|
|
- 'topic' => $topic,
|
|
|
+ 'topic' => $this->getTopic($post['topic_ids']),
|
|
|
'title' => $post['title'],
|
|
|
'content' => $post['content'],
|
|
|
'location' => $post['location'],
|
|
|
'img' => $post['img'],
|
|
|
- 'imgs' => $imgs,
|
|
|
+ 'imgs' => $postInfo['imgs'],
|
|
|
'video' => $post['video'],
|
|
|
- 'pv' => getNumber($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 + 3 * $post->data->pv,
|
|
|
- '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,
|
|
|
+ 'pv' => getNumber($postInfo['pv']),
|
|
|
+ 'praise_count' => $postInfo['praise_count'],
|
|
|
+ 'comment_count' => $postInfo['comment_count'],
|
|
|
+ 'available_bean' => $postInfo['available_bean'],
|
|
|
+ 'will_collect_bean' => $postInfo['will_collect_bean'],
|
|
|
+ 'post_comment' => $this->getNewComment($post['id']),
|
|
|
+ 'is_like' => Redis::SISMEMBER('post_like_'.$post['id'], $uid),
|
|
|
+ 'is_dislike' => Redis::SISMEMBER('post_unlike_'.$post['id'], $uid),
|
|
|
+ 'is_collect' => Redis::SISMEMBER('post_collect_'.$post['id'], $uid),
|
|
|
'follow_status' => $isFollow,
|
|
|
'h5url' => config('customer.share_post_h5url') . "?post_id={$post['id']}&invite_code={$userInfo['invite_code']}",
|
|
|
'desc_url' => $post['type'] == 'html' ? config('customer.app_service_url') . '/community/fragment/detail/' . $post['id'] : '',
|
|
|
];
|
|
|
}
|
|
|
|
|
|
- public function getPostComment($post_id)
|
|
|
- {
|
|
|
- $comments = $this->postComment->where(['post_id' => $post_id, 'parent_id' => 0])->select('id', 'uid', 'content', 'is_delete')->orderBy('is_delete', 'asc')->orderBy('id', 'desc')->take(2)->get();
|
|
|
- foreach ($comments as &$comment) {
|
|
|
- if ($comment->is_delete) {
|
|
|
- $comment->content = '该评论已被删除';
|
|
|
- }
|
|
|
- unset($comment->is_delete);
|
|
|
- $user = $this->userInfo($comment->uid);
|
|
|
- $comment->username = $user['username'];
|
|
|
- }
|
|
|
- return $comments;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 取消关注删除对应feed
|
|
|
* @param $data
|