From 0e3e01cfa075c66d3490ca12451af922c9c1e44f Mon Sep 17 00:00:00 2001 From: zj Date: Fri, 31 Jul 2026 09:07:29 +0800 Subject: [PATCH] update --- src/Service.php | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/Service.php b/src/Service.php index d574d1b..07a05b3 100644 --- a/src/Service.php +++ b/src/Service.php @@ -97,8 +97,8 @@ abstract class Service */ public function list(array $params = []): array { - $model = $this->repository->getQuery(); - $query = $model->newQuery(); + $model = $this->repository->getModel(); + $query = $this->repository->getQuery(); // 通过模型配置自动应用所有搜索条件 $this->applySearch($query, $params); @@ -149,8 +149,7 @@ abstract class Service */ public function update(int $id, array $data): bool { - $model = $this->repository->getQuery(); - $resource = $model->findById($id); + $resource = $this->findById($id); $this->checkResourceExists($resource); // 数据验证 @@ -169,8 +168,7 @@ abstract class Service */ public function delete(int $id): bool { - $model = $this->repository->getQuery(); - $resource = $model->findById($id); + $resource = $this->findById($id); $this->checkResourceExists($resource); @@ -186,9 +184,8 @@ abstract class Service */ public function restore(int $id): bool { - $model = $this->repository->getQuery(); // 必须使用withTrashed()才能查询到已删除记录 - $resource = $model->withTrashed()->find($id); + $resource = $this->repository->getQuery()->withTrashed()->find($id); $this->checkResourceExists($resource, '恢复的资源不存在'); $result = $this->repository->getQuery()->withTrashed() @@ -206,8 +203,7 @@ abstract class Service throw new BusinessException('请选择要删除的记录', 400); } - $model = $this->repository->getQuery(); - $exists = $model->whereIn('id', $ids)->exists(); + $exists = $this->repository->getQuery()->whereIn('id', $ids)->exists(); if (! $exists) { throw new BusinessException('部分记录不存在', 404); } @@ -228,8 +224,8 @@ abstract class Service throw new BusinessException('请选择要恢复的记录', 400); } - $model = $this->repository->getQuery(); - $exists = $model->withTrashed() + $exists = $this->repository->getQuery() + ->withTrashed() ->whereIn('id', $ids) ->whereNotNull('deleted_at') ->exists(); @@ -251,8 +247,7 @@ abstract class Service */ public function forceDelete(int $id): bool { - $model = $this->repository->getQuery(); - $resource = $model->withTrashed()->find($id); + $resource = $this->repository->getQuery()->withTrashed()->find($id); $this->checkResourceExists($resource, '要删除的资源不存在'); $result = $this->repository->getQuery()->withTrashed()