1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2019/6/18
- * Time: 10:08
- */
- namespace App\Transformers\Post;
- use App\Models\Post;
- use App\Models\PostCollect;
- use App\Models\PostLike;
- use App\Traits\PostTrait;
- use App\Traits\UserTrait;
- use Illuminate\Support\Facades\Redis;
- use League\Fractal\TransformerAbstract;
- class VideoTransformer 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;
- $isCollect = 0;
- $isFollow = 0;
- if($this->uid){
- $isLike = Redis::SISMEMBER('post_like_'.$post['id'], $this->uid);
- $isCollect = Redis::SISMEMBER('post_collect_'.$post['id'], $this->uid);
- $followStatus = $this->getFollowStatus($this->uid, $post['uid']);
- if($followStatus){
- $isFollow = $followStatus;
- }
- }
- $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' => $post['content'],
- 'img' => $post['img'],
- 'video' => $post['video'],
- 'topic' => $this->getTopic($post['topic_ids']),
- 'praise_count' => $postInfo['praise_count'],
- 'collect_count' => $postInfo['collect_count'],
- 'comment_count' => $postInfo['comment_count'],
- 'will_collect_bean' => $postInfo['will_collect_bean'],
- 'is_like' => $isLike,
- 'is_collect' => $isCollect,
- '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']:'',
- ];
- }
- }
|