This commit is contained in:
Aether
2025-10-16 20:06:23 +08:00
parent 6ab9bd6198
commit 9052c7069f
8 changed files with 153 additions and 20 deletions

View 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;
}
}

View File

@@ -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;
}
}

View 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;
}
}

View File

@@ -5,6 +5,8 @@ declare(strict_types=1);
namespace App\Model;
use Aether\AetherModel;
use Aether\Contract\TreeableInterface;
use Aether\Traits\AetherTree;
use Carbon\Carbon;
use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\Relations\BelongsTo;
@@ -26,8 +28,9 @@ use Hyperf\Database\Model\Relations\HasMany;
* @property Carbon $updated_at
* @property Carbon $deleted_at
*/
class Campus extends AetherModel
class Campus extends AetherModel implements TreeableInterface
{
use AetherTree;
protected ?string $table = 'da_campus';
protected array $fillable = [
@@ -52,10 +55,12 @@ class Campus extends AetherModel
];
protected array $search = [
'name' => 'like',
'level' => '=',
'parent_id' => '=',
'city' => 'like',
'province' => 'like',
'status' => '=',
];
protected array|bool|string $sortable = false;
@@ -119,4 +124,14 @@ class Campus extends AetherModel
->where('status', 1)
->whereNull('deleted_at');
}
protected function getParentIdField(): string
{
return 'parent_id';
}
protected function getSortField(): string
{
return '';
}
}

View File

@@ -22,7 +22,7 @@ use Hyperf\Database\Model\Relations\BelongsTo;
* @property string $introduction 教师简介
* @property int $campus_id 所属校区ID
* @property int $status 状态0-禁用1-启用
* @property int $sort_order 排序
* @property int $sort 排序
* @property Carbon $created_at
* @property Carbon $updated_at
* @property Carbon $deleted_at

View File

@@ -32,7 +32,7 @@ class CampusValidator extends AetherValidator
],
'update' => [
'rules' => [
'id' => 'required|integer|min:1',
// 'id' => 'required|integer|min:1',
'name' => 'required|string|max:255',
'parent_id' => 'nullable|integer|min:0',
'level' => 'nullable|integer|in:1,2,3',
@@ -41,7 +41,7 @@ class CampusValidator extends AetherValidator
'address' => 'nullable|string|max:500',
],
'messages' => [
'id.required' => '校区ID不能为空',
// 'id.required' => '校区ID不能为空',
'name.required' => '校区名称不能为空',
'level.in' => '层级只能是1、2、3',
],

View File

@@ -32,7 +32,7 @@ class TeacherValidator extends AetherValidator
],
'update' => [
'rules' => [
'id' => 'required|integer|min:1',
// 'id' => 'required|integer|min:1',
'name' => 'nullable|string|max:50',
'age' => 'nullable|integer|min:18|max:65',
'gender' => 'nullable|integer|in:1,2',
@@ -41,7 +41,7 @@ class TeacherValidator extends AetherValidator
'teach_subject' => 'nullable|string|max:100',
],
'messages' => [
'id.required' => '教师ID不能为空',
// 'id.required' => '教师ID不能为空',
'age.min' => '年龄不能小于18岁',
'age.max' => '年龄不能大于65岁',
'gender.in' => '性别只能是1(男)或2(女)',

24
composer.lock generated
View File

@@ -12,7 +12,7 @@
"source": {
"type": "git",
"url": "https://gitee.com/devAether666/aether-hyperf.git",
"reference": "b01e07101e6a4ee1f6f6d6e6496961c47f34d663"
"reference": "92a7f6c9a0b7b1addff990dee69a74977a1f4db2"
},
"require": {
"hyperf/db-connection": "~3.1.0",
@@ -52,7 +52,7 @@
}
],
"description": "Aether Hyperf Common Components",
"time": "2025-10-15T06:26:58+00:00"
"time": "2025-10-16T11:02:15+00:00"
},
{
"name": "carbonphp/carbon-doctrine-types",
@@ -129,7 +129,7 @@
"source": {
"type": "git",
"url": "https://gitee.com/devAether666/dhd-contract.git",
"reference": "3ea8fcdd7efd083fba689c7b191e60078a772e53"
"reference": "c95c40536f0ff311cf5e0fd6bfaefe6f752f0726"
},
"require": {
"hyperf/database": "~3.1.0",
@@ -157,7 +157,7 @@
}
],
"description": "DHD Micro Service Contract Package",
"time": "2025-10-14T01:32:08+00:00"
"time": "2025-10-16T10:15:18+00:00"
},
{
"name": "doctrine/deprecations",
@@ -3175,16 +3175,16 @@
},
{
"name": "hyperf/nacos",
"version": "v3.1.61",
"version": "v3.1.62.1",
"source": {
"type": "git",
"url": "https://github.com/hyperf/nacos.git",
"reference": "4e2833c5acc697fcacb2427649d99f85c3318de6"
"reference": "d294a20c4fb1616707d51ac68b55443d01d888de"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/hyperf/nacos/zipball/4e2833c5acc697fcacb2427649d99f85c3318de6",
"reference": "4e2833c5acc697fcacb2427649d99f85c3318de6",
"url": "https://api.github.com/repos/hyperf/nacos/zipball/d294a20c4fb1616707d51ac68b55443d01d888de",
"reference": "d294a20c4fb1616707d51ac68b55443d01d888de",
"shasum": ""
},
"require": {
@@ -3225,7 +3225,7 @@
],
"support": {
"issues": "https://github.com/hyperf/nacos/issues",
"source": "https://github.com/hyperf/nacos/tree/v3.1.61"
"source": "https://github.com/hyperf/nacos/tree/v3.1.62.1"
},
"funding": [
{
@@ -3237,7 +3237,7 @@
"type": "open_collective"
}
],
"time": "2025-09-03T05:52:19+00:00"
"time": "2025-10-14T03:31:00+00:00"
},
{
"name": "hyperf/paginator",
@@ -10851,6 +10851,6 @@
"platform": {
"php": ">=8.1"
},
"platform-dev": [],
"plugin-api-version": "2.0.0"
"platform-dev": {},
"plugin-api-version": "2.6.0"
}