194 lines
6.0 KiB
PHP
194 lines
6.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Admin\Schools;
|
|
|
|
use App\Http\Requests\BaseRequest;
|
|
|
|
/**
|
|
* 学校请求验证
|
|
*/
|
|
class SchoolRequest extends BaseRequest
|
|
{
|
|
/**
|
|
* 获取特定的验证规则
|
|
*/
|
|
protected function getSpecificRules(): array
|
|
{
|
|
$action = $this->route()->getActionMethod();
|
|
|
|
return match($action) {
|
|
'list' => $this->listRules(),
|
|
'detail' => $this->detailRules(),
|
|
'create' => $this->createRules(),
|
|
'update' => $this->updateRules(),
|
|
'delete' => $this->deleteRules(),
|
|
'batchDelete' => $this->batchDeleteRules(),
|
|
'campuses' => $this->campusesRules(),
|
|
'classes' => $this->classesRules(),
|
|
'stats' => $this->statsRules(),
|
|
'simpleList', 'userSchools' => [],
|
|
default => []
|
|
};
|
|
}
|
|
|
|
/**
|
|
* 获取分页验证规则
|
|
*/
|
|
private function getPaginationRules(): array
|
|
{
|
|
return [
|
|
'page' => ['sometimes', 'integer', 'min:1'],
|
|
'page_size' => ['sometimes', 'integer', 'min:1', 'max:100'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 列表查询验证规则
|
|
*/
|
|
private function listRules(): array
|
|
{
|
|
return array_merge($this->getPaginationRules(), [
|
|
'keyword' => ['sometimes', 'string', 'max:100'],
|
|
'status' => ['sometimes', 'integer', 'in:0,1'],
|
|
'type' => ['sometimes', 'integer'],
|
|
'province_id' => ['sometimes', 'integer'],
|
|
'city_id' => ['sometimes', 'integer'],
|
|
'district_id' => ['sometimes', 'integer'],
|
|
'grade_period' => ['sometimes', 'string', 'max:16'],
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 详情查询验证规则
|
|
*/
|
|
private function detailRules(): array
|
|
{
|
|
return [
|
|
'id' => ['required', 'integer', 'exists:school,id'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 创建验证规则
|
|
*/
|
|
private function createRules(): array
|
|
{
|
|
return [
|
|
'name' => ['required', 'string', 'max:100'],
|
|
'alias' => ['sometimes', 'string', 'max:255'],
|
|
'type' => ['sometimes', 'integer'],
|
|
'province_id' => ['sometimes', 'integer'],
|
|
'city_id' => ['sometimes', 'integer'],
|
|
'district_id' => ['sometimes', 'integer'],
|
|
'grade_period' => ['sometimes', 'string', 'max:16'],
|
|
'status' => ['sometimes', 'integer', 'in:0,1'],
|
|
'code' => ['sometimes', 'string', 'max:10'],
|
|
'sno_automatic' => ['sometimes', 'integer'],
|
|
'show_order' => ['sometimes', 'integer', 'min:0'],
|
|
'is_open_user_login' => ['sometimes', 'integer', 'in:0,1'],
|
|
'max_sno' => ['sometimes', 'integer', 'min:1'],
|
|
'default_password' => ['sometimes', 'string', 'max:50'],
|
|
'school_district_id' => ['sometimes', 'integer'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 更新验证规则
|
|
*/
|
|
private function updateRules(): array
|
|
{
|
|
return [
|
|
'id' => ['required', 'integer', 'exists:school,id'],
|
|
'name' => ['required', 'string', 'max:100'],
|
|
'alias' => ['sometimes', 'string', 'max:255'],
|
|
'type' => ['sometimes', 'integer'],
|
|
'province_id' => ['sometimes', 'integer'],
|
|
'city_id' => ['sometimes', 'integer'],
|
|
'district_id' => ['sometimes', 'integer'],
|
|
'grade_period' => ['sometimes', 'string', 'max:16'],
|
|
'status' => ['sometimes', 'integer', 'in:0,1'],
|
|
'code' => ['sometimes', 'string', 'max:10'],
|
|
'sno_automatic' => ['sometimes', 'integer'],
|
|
'show_order' => ['sometimes', 'integer', 'min:0'],
|
|
'is_open_user_login' => ['sometimes', 'integer', 'in:0,1'],
|
|
'max_sno' => ['sometimes', 'integer', 'min:1'],
|
|
'default_password' => ['sometimes', 'string', 'max:50'],
|
|
'school_district_id' => ['sometimes', 'integer'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 删除验证规则
|
|
*/
|
|
private function deleteRules(): array
|
|
{
|
|
return [
|
|
'id' => ['required', 'integer', 'exists:school,id'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 批量删除验证规则
|
|
*/
|
|
private function batchDeleteRules(): array
|
|
{
|
|
return [
|
|
'ids' => ['required', 'array', 'min:1'],
|
|
'ids.*' => ['integer', 'exists:school,id'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 获取校区列表验证规则
|
|
*/
|
|
private function campusesRules(): array
|
|
{
|
|
return [
|
|
'id' => ['required', 'integer', 'exists:school,id'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 获取班级列表验证规则
|
|
*/
|
|
private function classesRules(): array
|
|
{
|
|
return [
|
|
'id' => ['required', 'integer', 'exists:school,id'],
|
|
'campus_id' => ['sometimes', 'integer', 'exists:school_campus,id'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 获取统计信息验证规则
|
|
*/
|
|
private function statsRules(): array
|
|
{
|
|
return [
|
|
'id' => ['required', 'integer', 'exists:school,id'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 获取特定的验证错误消息
|
|
*/
|
|
protected function getSpecificMessages(): array
|
|
{
|
|
return [
|
|
'name.required' => '学校名称不能为空',
|
|
'name.max' => '学校名称不能超过100个字符',
|
|
'alias.max' => '学校别名不能超过255个字符',
|
|
'code.max' => '学校编码不能超过10个字符',
|
|
'status.in' => '学校状态值无效',
|
|
'is_open_user_login.in' => '开放用户登录状态值无效',
|
|
'max_sno.min' => '最大学号必须大于0',
|
|
'show_order.min' => '显示顺序必须大于等于0',
|
|
'grade_period.max' => '学段不能超过16个字符',
|
|
'default_password.max' => '默认密码不能超过50个字符',
|
|
'ids.required' => '请选择要删除的学校',
|
|
'ids.min' => '至少选择一条记录进行删除',
|
|
'campus_id.exists' => '指定的校区不存在',
|
|
];
|
|
}
|
|
}
|