FloorRepository.php 4.5 KB

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