123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- /*
- * This file is part of the Jiannei/lumen-api-starter.
- *
- * (c) Jiannei <longjian.huang@foxmail.com>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
- namespace App\Http\Controllers\Api;
- use App\Http\Controllers\Controller;
- use App\Http\Resources\CMS\BannerResource;
- use App\Repositories\Eloquent\Course\CourseRepositoryEloquent;
- use App\Repositories\Eloquent\Course\OrganizationRepositoryEloquent;
- use App\Repositories\Eloquent\Inform\InformationRepositoryEloquent;
- use App\Repositories\Eloquent\User\UserRepositoryEloquent;
- use App\Repositories\Enums\Base\BannerPositionEnum;
- use App\Repositories\Models\CMS\Banner;
- use App\Repositories\Models\Course\Category;
- use App\Repositories\Models\Course\Course;
- use App\Repositories\Models\Course\Organization;
- use App\Repositories\Models\Inform\Information;
- use App\Repositories\Models\User\User;
- use Carbon\Carbon;
- use Jiannei\Response\Laravel\Support\Facades\Response;
- class HomeController extends Controller
- {
- public function index(InformationRepositoryEloquent $informationRepositoryEloquent, CourseRepositoryEloquent $courseRepositoryEloquent, OrganizationRepositoryEloquent $organizationRepositoryEloquent, UserRepositoryEloquent $userRepositoryEloquent)
- {
- $category = Category::query()->where('parent_id', 0)->status()->select(['id', 'name'])->orderByDesc('sort')->get();
- $banners = Banner::query()->status()->active()->where('position', BannerPositionEnum::HOME)->orderBy('sort')->get();
- $banners = BannerResource::collection($banners);
- $notice = Information::query()->status()->where('organization_id', 0)->where('category_id', 1)->orderBy('sort')->orderByDesc('id')->limit(3)->get();
- $notice = $informationRepositoryEloquent->parserResult($notice)['list'];
- $news = Information::query()->status()->where('organization_id', 0)->where('category_id', 2)->orderBy('sort')->orderByDesc('id')->limit(4)->get();
- $news = $informationRepositoryEloquent->parserResult($news)['list'];
- $now = Carbon::now()->toDateTimeString();
- $courses = Course::query()->where('published_at', '<=', $now)->with(['thumb_resource'])->orderByDesc('user_count')->limit(8)->get();
- $courses = $courseRepositoryEloquent->parserResult($courses)['list'];
- $organization = Organization::query()->status()->where('is_issue', '=', 1)->limit(4)->orderByDesc('id')->get();
- $organization = $organizationRepositoryEloquent->parserResult($organization)['list'];
- $teacher = User::query()->where('role_id', 1)->inRandomOrder()->limit(8)->get();
- $teacher = $userRepositoryEloquent->parserResult($teacher)['list'];
- return Response::success(compact('category', 'banners', 'news', 'courses', 'organization', 'teacher', 'news', 'notice'));
- }
- }
|