You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Miniapp;
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Models\Banner;
|
|
|
|
|
use App\Support\ApiResponse;
|
|
|
|
|
use App\Support\Miniapp\MiniappPresenter;
|
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
|
|
|
|
|
|
class BannerController extends Controller
|
|
|
|
|
{
|
|
|
|
|
use ApiResponse;
|
|
|
|
|
|
|
|
|
|
public function index(): JsonResponse
|
|
|
|
|
{
|
|
|
|
|
$items = Banner::query()
|
|
|
|
|
->with([
|
|
|
|
|
'course' => fn ($query) => $query->with(['courseSystemItem', 'coverMedia'])->withCount('signups'),
|
|
|
|
|
'activity' => fn ($query) => $query->with(['activityTypeItem', 'sessions'])->withCount('signups'),
|
|
|
|
|
])
|
|
|
|
|
->where('status', 1)
|
|
|
|
|
->orderBy('sort')
|
|
|
|
|
->orderByDesc('id')
|
|
|
|
|
->get()
|
|
|
|
|
->map(fn (Banner $banner) => MiniappPresenter::serializeBanner($banner))
|
|
|
|
|
->values()
|
|
|
|
|
->all();
|
|
|
|
|
|
|
|
|
|
return $this->ok(['items' => $items]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function show(int $banner): JsonResponse
|
|
|
|
|
{
|
|
|
|
|
$model = Banner::query()
|
|
|
|
|
->where('status', 1)
|
|
|
|
|
->where('type', Banner::TYPE_CUSTOM)
|
|
|
|
|
->findOrFail($banner);
|
|
|
|
|
|
|
|
|
|
return $this->ok(MiniappPresenter::serializeBanner($model));
|
|
|
|
|
}
|
|
|
|
|
}
|