129 lines
3.2 KiB
PHP
129 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin\Schools;
|
|
|
|
use App\Http\Controllers\BaseController;
|
|
use App\Http\Requests\Admin\Schools\SchoolRequest;
|
|
use App\Services\Schools\SchoolService;
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
/**
|
|
* 学校控制器
|
|
*/
|
|
class SchoolController extends BaseController
|
|
{
|
|
public function __construct(
|
|
private SchoolService $schoolService
|
|
) {}
|
|
|
|
/**
|
|
* 获取学校列表
|
|
*/
|
|
public function list(SchoolRequest $request): JsonResponse
|
|
{
|
|
$params = $request->validated();
|
|
$result = $this->schoolService->getList($params);
|
|
|
|
return $this->SuccessPage($result->items(), $result->total());
|
|
}
|
|
|
|
/**
|
|
* 获取简单列表
|
|
*/
|
|
public function simpleList(): JsonResponse
|
|
{
|
|
$result = $this->schoolService->getSimpleList();
|
|
return $this->Success($result);
|
|
}
|
|
|
|
/**
|
|
* 获取学校详情
|
|
*/
|
|
public function detail(SchoolRequest $request): JsonResponse
|
|
{
|
|
$params = $request->validated();
|
|
$result = $this->schoolService->detail($params['id']);
|
|
return $this->Success($result);
|
|
}
|
|
|
|
/**
|
|
* 创建学校
|
|
*/
|
|
public function create(SchoolRequest $request): JsonResponse
|
|
{
|
|
$data = $request->validated();
|
|
$result = $this->schoolService->create($data);
|
|
return $this->Success($result);
|
|
}
|
|
|
|
/**
|
|
* 更新学校
|
|
*/
|
|
public function update(SchoolRequest $request): JsonResponse
|
|
{
|
|
$params = $request->validated();
|
|
$result = $this->schoolService->update($params['id'], $params);
|
|
return $this->Success($result);
|
|
}
|
|
|
|
/**
|
|
* 删除学校
|
|
*/
|
|
public function delete(SchoolRequest $request): JsonResponse
|
|
{
|
|
$params = $request->validated();
|
|
$this->schoolService->delete($params['id']);
|
|
return $this->Success();
|
|
}
|
|
|
|
/**
|
|
* 批量删除学校
|
|
*/
|
|
public function batchDelete(SchoolRequest $request): JsonResponse
|
|
{
|
|
$params = $request->validated();
|
|
$this->schoolService->batchDelete($params['ids']);
|
|
return $this->Success();
|
|
}
|
|
|
|
/**
|
|
* 获取用户管理的学校列表
|
|
*/
|
|
public function userSchools(SchoolRequest $request): JsonResponse
|
|
{
|
|
$userId = $request->user()->id;
|
|
$result = $this->schoolService->getUserSchools($userId);
|
|
return $this->Success($result);
|
|
}
|
|
|
|
/**
|
|
* 获取学校的校区列表
|
|
*/
|
|
public function campuses(SchoolRequest $request): JsonResponse
|
|
{
|
|
$params = $request->validated();
|
|
$result = $this->schoolService->getSchoolCampuses($params['id']);
|
|
return $this->Success($result);
|
|
}
|
|
|
|
/**
|
|
* 获取学校的班级列表
|
|
*/
|
|
public function classes(SchoolRequest $request): JsonResponse
|
|
{
|
|
$params = $request->validated();
|
|
$result = $this->schoolService->getSchoolClasses($params['id'], $params['campus_id'] ?? null);
|
|
return $this->Success($result);
|
|
}
|
|
|
|
/**
|
|
* 获取学校统计信息
|
|
*/
|
|
public function stats(SchoolRequest $request): JsonResponse
|
|
{
|
|
$params = $request->validated();
|
|
$result = $this->schoolService->getSchoolStats($params['id']);
|
|
return $this->Success($result);
|
|
}
|
|
}
|