123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- namespace App\Repositories;
- use App\Models\Floor;
- use App\Models\MemberGroup;
- use App\Models\MemberGroupInfo;
- use App\Models\TopicGroup;
- use App\Models\TopicGroupInfo;
- use App\Models\VideoGroup;
- use App\Models\VideoGroupInfo;
- use App\Traits\UserTrait;
- use Illuminate\Support\Facades\Log;
- use Symfony\Component\HttpKernel\Exception\HttpException;
- use Dingo\Api\Http\Response;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Database\QueryException;
- /**
- * Created by PhpStorm.
- * User: durong
- * Date: 2019/6/15
- * Time: 下午4:36
- */
- class FloorRepository
- {
- use UserTrait;
- public function __construct(Floor $floor,
- MemberGroup $memberGroup,
- MemberGroupInfo $memberGroupInfo,
- VideoGroup $videoGroup,
- VideoGroupInfo $videoGroupInfo,
- TopicGroup $topicGroup,
- TopicGroupInfo $topicGroupInfo)
- {
- $this->floor = $floor;
- $this->memberGroup = $memberGroup;
- $this->memberGroupInfo = $memberGroupInfo;
- $this->videoGroup = $videoGroup;
- $this->videoGroupInfo = $videoGroupInfo;
- $this->topicGroup = $topicGroup;
- $this->topicGroupInfo = $topicGroupInfo;
- }
- public function index($request)
- {
- $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
- $where = [];
- $where[] = ['is_open', 1];
- return $this->floor->where($where)->orderBy('floor_location', 'asc')->paginate($perPage);
- }
- public function info()
- {
- $userInfo = $this->getUserInfo();
- if(!$userInfo){
- return jsonError('获取用户信息失败');
- }
- $floor = $this->floor
- ->where('is_open', 1)
- ->whereIn('floor_type', [0,1,2,3])
- ->whereBetween('floor_location', [1,20])
- ->get();
- $data = [];
- foreach($floor as $item){
- if($item->floor_type == 0){
- //banner
- $banner = $this->getBanner($item->group_ids);
- if($banner){
- $data[$item->floor_location] = [
- 'show_type' => 'banner',
- 'data' => $banner
- ];
- }
- }elseif($item->floor_type == 1){
- //user
- $memberIds = $this->memberGroup
- ->join('member_group_info', 'member_group_info.member_group_id', '=', 'member_group.id')
- ->where('member_group.id', $item->group_ids)
- ->limit(20)
- ->pluck('member_group_info.uid')
- ->toArray();
- if(!$memberIds) continue;
- $memberIds = implode($memberIds, ',');
- $member = $this->getMemberGroup($memberIds);
- if(!$member) continue;
- $data[$item->floor_location] = [
- 'show_type' => 'user',
- 'data' => $member
- ];
- }elseif($item->floor_type == 2){
- //video
- $videoIds = $this->videoGroup
- ->join('video_group_info', 'video_group_info.video_group_id', '=', 'video_group.id')
- ->where('video_group.id', $item->group_ids)
- ->limit(20)
- ->pluck('video_group_info.post_id')
- ->toArray();
- if(!$videoIds) continue;
- $videoIds = implode($videoIds, ',');
- $video = $this->getPostVideo($videoIds);
- if(!$video) continue;
- $data[$item->floor_location] = [
- 'show_type' => 'video',
- 'data' => $video
- ];
- }elseif($item->floor_type == 3){
- //topic
- $topicIds = $this->topicGroup
- ->join('topic_group_info', 'topic_group_info.topic_group_id', '=', 'topic_group.id')
- ->where('topic_group.id', $item->group_ids)
- ->limit(20)
- ->pluck('topic_group_info.topic_id')
- ->toArray();
- if(!$topicIds) continue;
- $topicIds = implode($topicIds, ',');
- $topic = $this->getTopic($topicIds);
- if(!$topic) continue;
- $data[$item->floor_location] = [
- 'show_type' => 'topic',
- 'data' => $topic
- ];
- }
- }
- return $data;
- }
- }
|