This commit is contained in:
2026-07-30 15:08:36 +08:00
parent 18eb1e91e7
commit 310d77f9f2

View File

@@ -22,11 +22,11 @@ use Hyperf\DbConnection\Db;
/**
* @template T of Model
* @property Repository<T> $repository
* @property Validator<T> $validator
* @property Validator<T> $modelValidator
*/
abstract class Service
{
protected ?Validator $validator = null;
protected ?Validator $modelValidator = null;
protected array $search = [];
protected array $ignoreSearchFields = [];
@@ -51,7 +51,7 @@ abstract class Service
*/
public function create(array $data): mixed
{
$this->validator?->scene('create', $data)->check();
$this->modelValidator?->scene('create', $data)->check();
return $this->repository->create($data);
}
@@ -60,7 +60,7 @@ abstract class Service
*/
public function save(array $data): mixed
{
$this->validator?->scene('create', $data)->check();
$this->modelValidator?->scene('create', $data)->check();
return $this->create($data);
}
@@ -70,7 +70,7 @@ abstract class Service
public function updateById(mixed $id, array $data): mixed
{
// 数据验证
$this->validator?->scene('update', $data)->check();
$this->modelValidator?->scene('update', $data)->check();
return $this->repository->updateById($id, $data);
}
@@ -154,7 +154,7 @@ abstract class Service
$this->checkResourceExists($resource);
// 数据验证
$this->validator?->scene('update', $data)->check();
$this->modelValidator?->scene('update', $data)->check();
// 钩子:处理更新时的特殊逻辑(如禁止自身为父级)
$this->handleUpdateSpecialLogic($id, $data);