This commit is contained in:
Aether
2025-09-26 10:41:43 +08:00
parent 26ee79b951
commit 0c7142ad46
14 changed files with 157 additions and 427 deletions

View File

@@ -1,84 +0,0 @@
<?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;
use Hyperf\RpcServer\Annotation\RpcService;
use MicroService\Contract\CampusServiceInterface;
#[RpcService(
name: 'CampusService',
server: 'jsonrpc-http',
protocol: 'jsonrpc-http',
publishTo: 'nacos'
)]
class CampusService extends AetherCrudService implements CampusServiceInterface
{
#[Inject]
protected Campus $model;
#[Inject]
protected CampusValidator $validator;
public function getCampusById(int $id): array
{
$campus = Campus::find($id);
if (! $campus || $campus->status != 1) {
throw new BusinessException('校区不存在或已禁用', 10001);
}
return $campus->toArray();
}
public function getCampusesByIds(array $ids): array
{
return Campus::whereIn('id', $ids)
->enabled()
->get()
->toArray();
}
public function getCampusesByParentId(int $parentId): array
{
return Campus::where('parent_id', $parentId)
->enabled()
->get()
->toArray();
}
public function getProvinces(): array
{
return Campus::level(1)
->enabled()
->orderBy('name')
->get(['id', 'name', 'province'])
->toArray();
}
public function getCitiesByProvince(string $province): array
{
return Campus::level(2)
->province($province)
->enabled()
->orderBy('name')
->get(['id', 'name', 'city'])
->toArray();
}
protected function getModel(): AetherModel
{
return $this->model;
}
protected function getValidator(): AetherValidator
{
return $this->validator;
}
}