VideoGroupInfoTransformer.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019-06-12
  6. * Time: 14:51
  7. */
  8. namespace App\Transformers;
  9. use App\Models\VideoGroupInfo;
  10. use Illuminate\Support\Facades\Log;
  11. use League\Fractal\TransformerAbstract;
  12. use Illuminate\Support\Carbon;
  13. use Tymon\JWTAuth\Facades\JWTAuth;
  14. class VideoGroupInfoTransformer extends TransformerAbstract {
  15. public function transform(VideoGroupInfo $videoGroupInfo) {
  16. $videoInfo = $this->getVideo($videoGroupInfo['post_id']);
  17. return [
  18. 'id' => $videoGroupInfo['id'],
  19. 'video_group_id' => $videoGroupInfo['name'],
  20. 'created_at' => Carbon::parse($videoGroupInfo['created_at'])->toDateTimeString(),
  21. 'post_id' => $videoGroupInfo['post_id'],
  22. 'sort' => $videoGroupInfo['sort'],
  23. 'username' => isset($videoInfo['username']) ? $videoInfo['username'] : '',
  24. 'topic' => isset($videoInfo['topic']) ? $videoInfo['topic'] : '',
  25. 'video' => isset($videoInfo['video']) ? $videoInfo['video'] : '',
  26. 'img' => isset($videoInfo['img']) ? $videoInfo['img'] : '',
  27. 'pv' => isset($videoInfo['pv']) ? $videoInfo['pv'] : '',
  28. 'praise_count' => isset($videoInfo['praise_count'])? $videoInfo['praise_count']:'',
  29. ];
  30. }
  31. public function getVideo($id) {
  32. try {
  33. $url = config("customer.manage_service_url") . '/community/post/detail';
  34. //$url = 'https://manage.dev.caihongxingqiu.com/community/post/detail';
  35. $array = [
  36. 'json' => ['id' => $id], 'query' => [], 'http_errors' => false, 'headers' => ['Authorization' => "Bearer " . JWTAuth::getToken()]
  37. ];
  38. $res = http($url, $array, true, 'get');
  39. return $res;
  40. } catch (\Exception $e) {
  41. return [];
  42. }
  43. }
  44. }