..
This commit is contained in:
58
app/JsonRpc/Service/CampusService.php
Normal file
58
app/JsonRpc/Service/CampusService.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\JsonRpc\Service;
|
||||
|
||||
use Aether\AetherCrudService;
|
||||
use Aether\AetherModel;
|
||||
use Aether\AetherValidator;
|
||||
use Aether\Exception\BusinessException;
|
||||
use App\Exception\CampusNotFound;
|
||||
use App\Exception\TeacherNotFound;
|
||||
@@ -31,12 +34,18 @@ class DataService implements DataServiceInterface
|
||||
#[Inject]
|
||||
protected TeacherValidator $teacherValidator;
|
||||
|
||||
#[Inject]
|
||||
protected CampusService $campusService;
|
||||
|
||||
#[Inject]
|
||||
protected TeacherService $teacherService;
|
||||
|
||||
/**
|
||||
* 获取校区列表.
|
||||
*/
|
||||
public function getCampuses(array $data): array
|
||||
{
|
||||
return $this->campusModel->list($data);
|
||||
return $this->campusService->list($data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,12 +117,25 @@ class DataService implements DataServiceInterface
|
||||
->toArray();
|
||||
}
|
||||
|
||||
public function getCampusByIds(array $ids): array
|
||||
{
|
||||
if (empty($ids)) {
|
||||
return [];
|
||||
}
|
||||
return $this->campusModel
|
||||
->whereIn('id', $ids)
|
||||
->where('status', 1)
|
||||
->get()
|
||||
->keyBy('id')
|
||||
->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取教师列表.
|
||||
*/
|
||||
public function getTeachers(array $data): array
|
||||
{
|
||||
return $this->teacherModel->list($data);
|
||||
return $this->teacherService->list($data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,4 +180,14 @@ class DataService implements DataServiceInterface
|
||||
{
|
||||
return $this->teacherModel->deleteById($id);
|
||||
}
|
||||
|
||||
protected function getModel(): AetherModel
|
||||
{
|
||||
return $this->campusModel;
|
||||
}
|
||||
|
||||
protected function getValidator(): AetherValidator
|
||||
{
|
||||
return $this->teacherValidator;
|
||||
}
|
||||
}
|
||||
|
||||
28
app/JsonRpc/Service/TeacherService.php
Normal file
28
app/JsonRpc/Service/TeacherService.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\JsonRpc\Service;
|
||||
|
||||
use Aether\AetherCrudService;
|
||||
use Aether\AetherModel;
|
||||
use Aether\AetherValidator;
|
||||
use App\Model\Teacher;
|
||||
use App\Validator\TeacherValidator;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class TeacherService extends AetherCrudService
|
||||
{
|
||||
#[Inject]
|
||||
protected Teacher $teacherModel;
|
||||
#[Inject]
|
||||
protected TeacherValidator $teacherValidator;
|
||||
|
||||
protected function getModel(): AetherModel
|
||||
{
|
||||
return $this->teacherModel;
|
||||
}
|
||||
|
||||
protected function getValidator(): AetherValidator
|
||||
{
|
||||
return $this->teacherValidator;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user