|
@@ -5,7 +5,8 @@
|
|
|
* Date: 2019/6/17
|
|
|
* Time: 19:26
|
|
|
*/
|
|
|
-namespace App\Transformers\Topic;
|
|
|
+
|
|
|
+namespace App\Transformers\Topic;
|
|
|
|
|
|
use App\Models\Post;
|
|
|
use App\Models\PostCollect;
|
|
@@ -21,27 +22,29 @@ class TopicPostTransformer extends TransformerAbstract
|
|
|
{
|
|
|
use UserTrait;
|
|
|
use PostTrait;
|
|
|
+
|
|
|
public function __construct($uid, $invite_code)
|
|
|
{
|
|
|
$this->uid = $uid;
|
|
|
$this->invite_code = $invite_code;
|
|
|
}
|
|
|
+
|
|
|
public function transform(Post $post)
|
|
|
{
|
|
|
$imgs = [];
|
|
|
- foreach($post->imgs as $img){
|
|
|
+ foreach ($post->imgs as $img) {
|
|
|
$imgs[] = $img['img'];
|
|
|
}
|
|
|
$isLike = 0;
|
|
|
$isDislike = 0;
|
|
|
$isCollect = 0;
|
|
|
$isFollow = 0;
|
|
|
- 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;
|
|
|
+ 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){
|
|
|
+ if ($followStatus) {
|
|
|
$isFollow = $followStatus;
|
|
|
}
|
|
|
}
|
|
@@ -56,7 +59,7 @@ class TopicPostTransformer extends TransformerAbstract
|
|
|
'topic' => $this->getTopic($post['topic_ids']),
|
|
|
'is_fine' => $post['is_fine'],
|
|
|
'title' => $post['title'],
|
|
|
- 'content' => $post['content'],
|
|
|
+ 'content' => subtext($post['content'], 100),
|
|
|
'location' => $post['location'],
|
|
|
'img' => $post['img'],
|
|
|
'imgs' => $imgs,
|
|
@@ -70,8 +73,8 @@ class TopicPostTransformer extends TransformerAbstract
|
|
|
'is_collect' => $isCollect,
|
|
|
'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']:'',
|
|
|
+ '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'] : '',
|
|
|
];
|
|
|
}
|
|
|
}
|