12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2019/6/15
- * Time: 11:07
- */
- namespace App\Transformers\Circle;
- use App\Models\Post;
- use App\Traits\PostTrait;
- use App\Traits\UserTrait;
- use Carbon\Carbon;
- use Illuminate\Support\Facades\Redis;
- use League\Fractal\TransformerAbstract;
- class ArticleListTransformer 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)
- {
- $isLike = 0;
- $isDislike = 0;
- $isCollect = 0;
- if($this->uid){
- $isLike = Redis::SISMEMBER('post_like_'.$post['id'], $this->uid);
- $isDislike = Redis::SISMEMBER('post_unlike_'.$post['id'], $this->uid);
- $isCollect = Redis::SISMEMBER('post_collect_'.$post['id'], $this->uid);
- }
- $user = $this->userInfo($post['uid']);
- $postInfo = $this->getPostInfo($post['id']);
- if($post['type']=='html'){
- $content = subtext($post['content'],100);
- }else{
- $content = $post['content'];
- }
- return [
- 'id' => $post['id'],
- 'type' => $post['type'],
- 'created_at' => Carbon::parse($post['created_at'])->diffForHumans(),
- 'uid' => $post['uid'],
- 'username' => $user['username'],
- 'avatar' => $user['avatar'],
- 'topic' => $this->getTopic($post['topic_ids']),
- 'is_fine' => $post['is_fine'],
- 'title' => $post['title'],
- 'content' => $content,
- 'location' => $post['location'],
- 'img' => $post['img'],
- 'imgs' => $postInfo['imgs'],
- 'video' => $post['video'],
- 'pv' => getNumber($postInfo['pv']),
- 'praise_count' => $postInfo['praise_count'],
- 'comment_count' => $postInfo['comment_count'],
- 'collect_count' => $postInfo['collect_count'],
- 'will_collect_bean' => $postInfo['will_collect_bean'],
- 'is_like' => $isLike,
- 'is_dislike' => $isDislike,
- 'is_collect' => $isCollect,
- 'comment' => $this->getNewComment($post['id'], $this->uid),
- 'is_follow' => $this->getFollowStatus($this->uid, $post['uid']),
- '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']:'',
- ];
- }
- }
|