|
@@ -12,6 +12,7 @@ use App\Models\PostCollect;
|
|
|
use App\Models\PostComment;
|
|
|
use App\Models\PostDislike;
|
|
|
use App\Models\PostLike;
|
|
|
+use App\Traits\PostTrait;
|
|
|
use App\Traits\UserTrait;
|
|
|
use Carbon\Carbon;
|
|
|
use League\Fractal\TransformerAbstract;
|
|
@@ -19,6 +20,7 @@ use League\Fractal\TransformerAbstract;
|
|
|
class TopicPostTransformer extends TransformerAbstract
|
|
|
{
|
|
|
use UserTrait;
|
|
|
+ use PostTrait;
|
|
|
public function __construct($uid, $invite_code)
|
|
|
{
|
|
|
$this->uid = $uid;
|
|
@@ -30,34 +32,6 @@ class TopicPostTransformer extends TransformerAbstract
|
|
|
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){
|
|
|
- $userComment = $this->userInfo($val->uid);
|
|
|
- $replyUsername = '';
|
|
|
- if($val->reply_uid){
|
|
|
- $userReply = $this->userInfo($val->reply_uid);
|
|
|
- $replyUsername = $userReply['username'];
|
|
|
- }
|
|
|
- $reply[] = [
|
|
|
- 'username' => $userComment['username'],
|
|
|
- 'reply_username' => $replyUsername,
|
|
|
- 'content' => $val->content,
|
|
|
- ];
|
|
|
- }
|
|
|
- $userComment = $this->userInfo($item->uid);
|
|
|
- $comment[] = [
|
|
|
- 'id' => $item->id,
|
|
|
- 'username' => $userComment['username'],
|
|
|
- 'content' => $item->content,
|
|
|
- 'reply_count' => $replyCount,
|
|
|
- 'reply' => $reply,
|
|
|
- ];
|
|
|
- }
|
|
|
$topic = [];
|
|
|
foreach($post->topic() as $key => $val){
|
|
|
$topic[] = [
|
|
@@ -100,7 +74,7 @@ class TopicPostTransformer extends TransformerAbstract
|
|
|
'is_like' => $isLike,
|
|
|
'is_dislike' => $isDislike,
|
|
|
'is_collect' => $isCollect,
|
|
|
- 'comment' => $comment,
|
|
|
+ 'comment' => $this->getNewComment($post['id'], $this->uid),
|
|
|
'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']:'',
|