Files
hyperf_data/app/JsonRpc/Service/CampusService.php
Aether 9052c7069f ..
2025-10-16 20:06:23 +08:00

59 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\JsonRpc\Service;
use Aether\AetherCrudService;
use Aether\AetherModel;
use Aether\AetherValidator;
use Aether\Exception\BusinessException;
use App\Model\Campus;
use App\Validator\CampusValidator;
use Hyperf\Di\Annotation\Inject;
class CampusService extends AetherCrudService
{
#[Inject]
protected Campus $campusModel;
#[Inject]
protected CampusValidator $campusValidator;
/**
* 获取省份列表.
*/
public function getProvinces(): array
{
return $this->campusModel->level(1)
->enabled()
->orderBy('name')
->get(['id', 'name', 'province'])
->toArray();
}
/**
* 根据省份获取城市列表.
* @throws BusinessException
*/
public function getCitiesByProvince(string $province): array
{
return $this->campusModel->level(2)
->province($province)
->enabled()
->orderBy('name')
->get(['id', 'name', 'city'])
->toArray();
}
protected function getModel(): AetherModel
{
return $this->campusModel;
}
protected function getValidator(): AetherValidator
{
return $this->campusValidator;
}
}