From 71334e5641acb5a103eee1f421ef67d66cc8b7fd Mon Sep 17 00:00:00 2001 From: "zhangf@suq.cn" Date: Wed, 10 Dec 2025 15:20:44 +0800 Subject: [PATCH] =?UTF-8?q?feat(controller):=20=E6=94=AF=E6=8C=81=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E5=88=A0=E9=99=A4=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改控制器中的 delete 方法,将单个 ID 删除改为支持多个 IDs 删除 - 更新服务层方法签名,接收数组参数用于批量操作 - 数据库更新逻辑调整为使用 in 条件匹配多个 ID - 返回结果结构保持一致,返回被删除的 ID 列表 --- app/controller/AiCommandController.php | 4 ++-- app/controller/ArticleCategoryController.php | 4 ++-- app/controller/CreationTaskController.php | 4 ++-- app/controller/DistillationQuestionsController.php | 4 ++-- app/controller/DistillationWordController.php | 4 ++-- app/controller/EnterprisePortraitCategoryController.php | 4 ++-- app/controller/EnterprisePortraitLibraryController.php | 4 ++-- app/controller/KnowledgeLibraryController.php | 4 ++-- app/service/AiCommandService.php | 6 +++--- app/service/ArticleCategoryService.php | 6 +++--- app/service/CreationTaskService.php | 6 +++--- app/service/DistillationQuestionsService.php | 10 +++------- app/service/DistillationWordService.php | 16 ++++++---------- app/service/EnterprisePortraitCategoryService.php | 8 ++++---- app/service/EnterprisePortraitLibraryService.php | 6 +++--- app/service/KnowledgeLibraryService.php | 6 +++--- 16 files changed, 44 insertions(+), 52 deletions(-) diff --git a/app/controller/AiCommandController.php b/app/controller/AiCommandController.php index d7b2d25..30e2d51 100644 --- a/app/controller/AiCommandController.php +++ b/app/controller/AiCommandController.php @@ -51,8 +51,8 @@ class AiCommandController public function delete(AiCommandService $service): Response { - $id = input('id'); - return success($service->deleteData($id)); + $ids = input('ids'); + return success($service->deleteData($ids)); } public function pureIndex(AiCommandService $service) diff --git a/app/controller/ArticleCategoryController.php b/app/controller/ArticleCategoryController.php index 07e8a09..b4f9f08 100644 --- a/app/controller/ArticleCategoryController.php +++ b/app/controller/ArticleCategoryController.php @@ -45,8 +45,8 @@ class ArticleCategoryController public function delete(ArticleCategoryService $service): Response { - $id = input('id'); - return success($service->deleteData($id)); + $ids = input('ids'); + return success($service->deleteData($ids)); } diff --git a/app/controller/CreationTaskController.php b/app/controller/CreationTaskController.php index 9e5fe57..768047c 100644 --- a/app/controller/CreationTaskController.php +++ b/app/controller/CreationTaskController.php @@ -62,8 +62,8 @@ class CreationTaskController public function delete(CreationTaskService $service): Response { - $id = input('id'); - return success($service->deleteData($id)); + $ids = input('ids'); + return success($service->deleteData($ids)); } diff --git a/app/controller/DistillationQuestionsController.php b/app/controller/DistillationQuestionsController.php index 6c559e4..aea94d2 100644 --- a/app/controller/DistillationQuestionsController.php +++ b/app/controller/DistillationQuestionsController.php @@ -47,8 +47,8 @@ class DistillationQuestionsController public function delete(DistillationQuestionsService $service): Response { - $id = input('id'); - return success($service->deleteData($id)); + $ids = input('ids'); + return success($service->deleteData($ids)); } } \ No newline at end of file diff --git a/app/controller/DistillationWordController.php b/app/controller/DistillationWordController.php index 3108815..6311516 100644 --- a/app/controller/DistillationWordController.php +++ b/app/controller/DistillationWordController.php @@ -52,8 +52,8 @@ class DistillationWordController public function delete(DistillationWordService $service): Response { - $id = input('id'); - return success($service->deleteData($id)); + $ids = input('ids'); + return success($service->deleteData($ids)); } public function pureIndex(DistillationWordService $service) diff --git a/app/controller/EnterprisePortraitCategoryController.php b/app/controller/EnterprisePortraitCategoryController.php index ad08d6c..30a1339 100644 --- a/app/controller/EnterprisePortraitCategoryController.php +++ b/app/controller/EnterprisePortraitCategoryController.php @@ -45,8 +45,8 @@ class EnterprisePortraitCategoryController public function delete(EnterprisePortraitCategoryService $service): Response { - $id = input('id'); - return success($service->deleteData($id)); + $ids = input('ids'); + return success($service->deleteData($ids)); } public function pureIndex(EnterprisePortraitCategoryService $service) diff --git a/app/controller/EnterprisePortraitLibraryController.php b/app/controller/EnterprisePortraitLibraryController.php index e484f93..b64ec2f 100644 --- a/app/controller/EnterprisePortraitLibraryController.php +++ b/app/controller/EnterprisePortraitLibraryController.php @@ -31,8 +31,8 @@ class EnterprisePortraitLibraryController public function delete(EnterprisePortraitLibraryService $service): Response { - $id = input('id'); - return success($service->deleteData($id)); + $ids = input('ids'); + return success($service->deleteData($ids)); } diff --git a/app/controller/KnowledgeLibraryController.php b/app/controller/KnowledgeLibraryController.php index 0d7a087..ca832fe 100644 --- a/app/controller/KnowledgeLibraryController.php +++ b/app/controller/KnowledgeLibraryController.php @@ -29,8 +29,8 @@ class KnowledgeLibraryController public function delete(KnowledgeLibraryService $service): Response { - $id = input('id'); - return success($service->deleteData($id)); + $ids = input('ids'); + return success($service->deleteData($ids)); } public function pureIndex(KnowledgeLibraryService $service) diff --git a/app/service/AiCommandService.php b/app/service/AiCommandService.php index 711b8c0..2f44acb 100644 --- a/app/service/AiCommandService.php +++ b/app/service/AiCommandService.php @@ -100,18 +100,18 @@ class AiCommandService extends BaseService * @param mixed $id * @return array */ - public function deleteData(mixed $id): array + public function deleteData(array $ids): array { // 落库 Db::startTrans(); try { - $this->dao->update($id, ['delete_time' => time()]); + $this->dao->update([['id', 'in', $ids]], ['delete_time' => time()]); Db::commit(); } catch (\Exception $exception) { Db::rollback(); throw new ApiException($exception->getMessage()); } - return ['id' => $id]; + return ['id' => $ids]; } public function selectData($type) diff --git a/app/service/ArticleCategoryService.php b/app/service/ArticleCategoryService.php index 23e41c1..abe0b60 100644 --- a/app/service/ArticleCategoryService.php +++ b/app/service/ArticleCategoryService.php @@ -97,18 +97,18 @@ class ArticleCategoryService extends BaseService * @param mixed $id * @return array */ - public function deleteData(mixed $id): array + public function deleteData(array $ids): array { // 落库 Db::startTrans(); try { - $this->dao->update($id, ['delete_time' => time()]); + $this->dao->update([['id', 'in', $ids]], ['delete_time' => time()]); Db::commit(); } catch (\Exception $exception) { Db::rollback(); throw new ApiException($exception->getMessage()); } - return ['id' => $id]; + return ['id' => $ids]; } } \ No newline at end of file diff --git a/app/service/CreationTaskService.php b/app/service/CreationTaskService.php index 57ab7b8..10f8283 100644 --- a/app/service/CreationTaskService.php +++ b/app/service/CreationTaskService.php @@ -127,18 +127,18 @@ class CreationTaskService extends BaseService * @param mixed $id * @return array */ - public function deleteData(mixed $id): array + public function deleteData(array $ids): array { // 落库 Db::startTrans(); try { - $this->dao->update($id, ['delete_time' => time()]); + $this->dao->update([['id', 'in', $ids]], ['delete_time' => time()]); Db::commit(); } catch (\Exception $exception) { Db::rollback(); throw new ApiException($exception->getMessage()); } - return ['id' => $id]; + return ['id' => $ids]; } } \ No newline at end of file diff --git a/app/service/DistillationQuestionsService.php b/app/service/DistillationQuestionsService.php index 24afc17..352f590 100644 --- a/app/service/DistillationQuestionsService.php +++ b/app/service/DistillationQuestionsService.php @@ -111,22 +111,18 @@ class DistillationQuestionsService extends BaseService * @param mixed $id * @return array */ - public function deleteData(mixed $id): array + public function deleteData(array $ids): array { - $data = $this->dao->get(['id' => $id]); - if (empty($data)) { - return []; - } // 落库 Db::startTrans(); try { - $this->dao->update($id, ['delete_time' => time()]); + $this->dao->update([['id', 'in', $ids]], ['delete_time' => time()]); Db::commit(); } catch (\Exception $exception) { Db::rollback(); throw new ApiException($exception->getMessage()); } - return ['id' => $id]; + return ['id' => $ids]; } } \ No newline at end of file diff --git a/app/service/DistillationWordService.php b/app/service/DistillationWordService.php index 19b7e54..0cfa193 100644 --- a/app/service/DistillationWordService.php +++ b/app/service/DistillationWordService.php @@ -153,27 +153,23 @@ class DistillationWordService extends BaseService * @param mixed $id * @return array */ - public function deleteData(mixed $id): array + public function deleteData(array $ids): array { - $data = $this->dao->get(['id' => $id]); - if (empty($data)) { - return []; - } // 落库 Db::startTrans(); try { //删主表 - $this->dao->update($id, ['delete_time' => time()]); + $this->dao->update([['id', 'in', $ids]], ['delete_time' => time()]); //删子表 - $this->transDao->update(['distillation_id' => $id], ['delete_time' => time()]); - $this->expandDao->update(['distillation_id' => $id], ['delete_time' => time()]); - $this->questionsDao->update(['distillation_id' => $id], ['delete_time' => time()]); + $this->transDao->update([['distillation_id', 'in', $ids]], ['delete_time' => time()]); + $this->expandDao->update([['distillation_id', 'in', $ids]], ['delete_time' => time()]); + $this->questionsDao->update([['distillation_id', 'in', $ids]], ['delete_time' => time()]); Db::commit(); } catch (\Exception $exception) { Db::rollback(); throw new ApiException($exception->getMessage()); } - return ['id' => $id]; + return ['id' => $ids]; } public function selectData() diff --git a/app/service/EnterprisePortraitCategoryService.php b/app/service/EnterprisePortraitCategoryService.php index 2fd9dba..81cd847 100644 --- a/app/service/EnterprisePortraitCategoryService.php +++ b/app/service/EnterprisePortraitCategoryService.php @@ -100,21 +100,21 @@ class EnterprisePortraitCategoryService extends BaseService * @param mixed $id * @return array */ - public function deleteData(mixed $id): array + public function deleteData(array $ids): array { // 落库 Db::startTrans(); try { //删除表 - $this->dao->update($id, ['delete_time' => time()]); + $this->dao->update([['id', 'in', $ids]], ['delete_time' => time()]); //删图库 - $this->libraryDao->update(['category_id' => $id], ['delete_time' => time()]); + $this->libraryDao->update([['category_id', 'in', $ids]], ['delete_time' => time()]); Db::commit(); } catch (\Exception $exception) { Db::rollback(); throw new ApiException($exception->getMessage()); } - return ['id' => $id]; + return ['id' => $ids]; } public function selectData() diff --git a/app/service/EnterprisePortraitLibraryService.php b/app/service/EnterprisePortraitLibraryService.php index 955b3a7..fb0327c 100644 --- a/app/service/EnterprisePortraitLibraryService.php +++ b/app/service/EnterprisePortraitLibraryService.php @@ -75,18 +75,18 @@ class EnterprisePortraitLibraryService extends BaseService * @param mixed $id * @return array */ - public function deleteData(mixed $id): array + public function deleteData(array $ids): array { // 落库 Db::startTrans(); try { - $this->dao->update($id, ['delete_time' => time()]); + $this->dao->update([['id', 'in', $ids]], ['delete_time' => time()]); Db::commit(); } catch (\Exception $exception) { Db::rollback(); throw new ApiException($exception->getMessage()); } - return ['id' => $id]; + return ['id' => $ids]; } } \ No newline at end of file diff --git a/app/service/KnowledgeLibraryService.php b/app/service/KnowledgeLibraryService.php index 18a5e45..7581039 100644 --- a/app/service/KnowledgeLibraryService.php +++ b/app/service/KnowledgeLibraryService.php @@ -64,18 +64,18 @@ class KnowledgeLibraryService extends BaseService * @param mixed $id * @return array */ - public function deleteData(mixed $id): array + public function deleteData(array $ids): array { // 落库 Db::startTrans(); try { - $this->dao->update($id, ['delete_time' => time()]); + $this->dao->update([['id', 'in', $ids]], ['delete_time' => time()]); Db::commit(); } catch (\Exception $exception) { Db::rollback(); throw new ApiException($exception->getMessage()); } - return ['id' => $id]; + return ['id' => $ids]; } public function selectData()