FloorRepository.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace App\Repositories;
  3. use App\Models\Floor;
  4. use App\Models\TopicGroup;
  5. use App\Models\TopicGroupInfo;
  6. use App\Models\VideoGroup;
  7. use App\Models\VideoGroupInfo;
  8. use App\Traits\UserTrait;
  9. use Illuminate\Support\Facades\Log;
  10. use Symfony\Component\HttpKernel\Exception\HttpException;
  11. use Dingo\Api\Http\Response;
  12. use Illuminate\Support\Facades\DB;
  13. use Illuminate\Database\QueryException;
  14. /**
  15. * Created by PhpStorm.
  16. * User: durong
  17. * Date: 2019/6/15
  18. * Time: 下午4:36
  19. */
  20. class FloorRepository
  21. {
  22. use UserTrait;
  23. public function __construct(Floor $floor,
  24. VideoGroup $videoGroup,
  25. VideoGroupInfo $videoGroupInfo,
  26. TopicGroup $topicGroup,
  27. TopicGroupInfo $topicGroupInfo)
  28. {
  29. $this->floor = $floor;
  30. $this->videoGroup = $videoGroup;
  31. $this->videoGroupInfo = $videoGroupInfo;
  32. $this->topicGroup = $topicGroup;
  33. $this->topicGroupInfo = $topicGroupInfo;
  34. }
  35. public function index($request)
  36. {
  37. $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
  38. $where = [];
  39. $where[] = ['is_open', 1];
  40. return $this->floor->where($where)->orderBy('floor_location', 'asc')->paginate($perPage);
  41. }
  42. public function info()
  43. {
  44. $userInfo = $this->getUserInfo();
  45. if(!$userInfo){
  46. return jsonError('获取用户信息失败');
  47. }
  48. $floor = $this->floor
  49. ->where('is_open', 1)
  50. ->whereIn('floor_type', [0,1,2,3])
  51. ->whereBetween('floor_location', [1,20])
  52. ->get();
  53. $data = [];
  54. foreach($floor as $item){
  55. if($item->floor_type == 0){
  56. //banner
  57. $banner = $this->getBanner($item->group_ids);
  58. if($banner){
  59. $data[$item->floor_location] = [
  60. 'show_type' => 'banner',
  61. 'data' => $banner
  62. ];
  63. }
  64. }elseif($item->floor_type == 1){
  65. //user
  66. }elseif($item->floor_type == 2){
  67. //video
  68. $videoIds = $this->videoGroup
  69. ->join('video_group_info', 'video_group_info.video_group_id', '=', 'video_group.id')
  70. ->where('video_group.id', $item->group_ids)
  71. ->limit(20)
  72. ->pluck('video_group_info.post_id')
  73. ->toArray();
  74. if(!$videoIds) continue;
  75. $videoIds = implode($videoIds, ',');
  76. $video = $this->getPostVideo($videoIds);
  77. if(!$video) continue;
  78. $data[$item->floor_location] = [
  79. 'show_type' => 'video',
  80. 'data' => $video
  81. ];
  82. }elseif($item->floor_type == 3){
  83. //topic
  84. $topicIds = $this->topicGroup
  85. ->join('topic_group_info', 'topic_group_info.topic_group_id', '=', 'topic_group.id')
  86. ->where('topic_group.id', $item->group_ids)
  87. ->limit(20)
  88. ->pluck('topic_group_info.topic_id')
  89. ->toArray();
  90. if(!$topicIds) continue;
  91. $topicIds = implode($topicIds, ',');
  92. $topic = $this->getTopic($topicIds);
  93. if(!$topic) continue;
  94. $data[$item->floor_location] = [
  95. 'show_type' => 'topic',
  96. 'data' => $topic
  97. ];
  98. }
  99. }
  100. return $data;
  101. }
  102. }