基础数据-校区服务

This commit is contained in:
Aether
2025-09-19 15:14:20 +08:00
parent 824510d57c
commit b69f14ded2
16 changed files with 757 additions and 300 deletions

View File

@@ -0,0 +1,69 @@
<?php
declare(strict_types=1);
namespace App\Validator;
use Hyperf\Validation\Contract\ValidatorFactoryInterface;
use Hyperf\Validation\Validator;
class CampusValidator
{
public function __construct(protected ValidatorFactoryInterface $validationFactory)
{
}
public function validateCreate(array $data): Validator
{
return $this->validationFactory->make($data, [
'name' => 'required|string|max:255',
'parent_id' => 'required|integer|min:0',
'level' => 'required|integer|in:1,2,3',
'province' => 'nullable|string|max:100',
'city' => 'nullable|string|max:100',
'address' => 'nullable|string|max:500',
'contact_phone' => 'nullable|string|max:20',
'contact_person' => 'nullable|string|max:20',
'status' => 'nullable|integer|in:0,1',
], [
'name.required' => '校区名称不能为空',
'parent_id.required' => '父级ID不能为空',
'level.required' => '层级不能为空',
'level.in' => '层级只能是1、2、3',
]);
}
public function validateUpdate(array $data): Validator
{
return $this->validationFactory->make($data, [
'id' => 'required|integer|min:1',
'name' => 'nullable|string|max:255',
'parent_id' => 'nullable|integer|min:0',
'level' => 'nullable|integer|in:1,2,3',
'province' => 'nullable|string|max:100',
'city' => 'nullable|string|max:100',
'address' => 'nullable|string|max:500',
'contact_phone' => 'nullable|string|max:20',
'contact_person' => 'nullable|string|max:20',
'status' => 'nullable|integer|in:0,1',
], [
'id.required' => '校区ID不能为空',
'level.in' => '层级只能是1、2、3',
]);
}
public function validateQuery(array $data): Validator
{
return $this->validationFactory->make($data, [
'id' => 'nullable|integer|min:1',
'name' => 'nullable|string|max:255',
'parent_id' => 'nullable|integer|min:0',
'level' => 'nullable|integer|in:1,2,3',
'province' => 'nullable|string|max:100',
'city' => 'nullable|string|max:100',
'status' => 'nullable|integer|in:0,1',
'page' => 'nullable|integer|min:1',
'size' => 'nullable|integer|min:1|max:100',
]);
}
}