1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2019/6/15
- * Time: 17:59
- */
- namespace App\Transformers\Post;
- use App\Models\Post;
- use App\Models\PostLike;
- use App\Traits\PostTrait;
- use App\Traits\UserTrait;
- use Illuminate\Support\Facades\Redis;
- use League\Fractal\TransformerAbstract;
- class ListTransformer 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;
- if($this->uid){
- $isLike = Redis::SISMEMBER('post_like_'.$post['id'], $this->uid);
- }
- $user = $this->userInfo($post['uid']);
- $postInfo = $this->getPostInfo($post['id']);
- return [
- 'id' => $post['id'],
- 'type' => $post['type'],
- 'uid' => $post['uid'],
- 'username' => $user['username'],
- 'avatar' => $user['avatar'],
- 'title' => $post['title'],
- 'content' => subtext($post['content'], 100),
- 'img' => $post['img'],
- 'topic' => $this->getTopic($post['topic_ids']),
- 'praise_count' => $postInfo['praise_count'],
- 'is_like' => $isLike,
- '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']:'',
- ];
- }
- }
|