FloorRepository.php 2.6 KB

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