From b84018eb00d0373372c6db9192cd32966249133e Mon Sep 17 00:00:00 2001 From: panliang <1163816051@qq.com> Date: Mon, 25 Sep 2023 10:27:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20app/Admin/Services/Keyword?= =?UTF-8?q?Service.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Services/KeywordService.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/app/Admin/Services/KeywordService.php b/app/Admin/Services/KeywordService.php index 07b7e34..d257cec 100644 --- a/app/Admin/Services/KeywordService.php +++ b/app/Admin/Services/KeywordService.php @@ -31,14 +31,22 @@ class KeywordService extends BaseService return ['items' => $this->getTree(request()->all())]; } - public function delete(string $ids): mixed + /** + * 删除的前置方法 + * + * @param array $ids 主键id + * @return mixed true: 继续后续操作, string: 中断操作, 返回错误提示 + */ + public function preDelete(array $ids) { - $ids = explode(',', $ids); - if (count($ids) == 1) { - $this->query()->where('path', 'like', '%-'.$ids[0].'-%')->delete(); - } + // 删除子级 + $this->query()->where(function ($q) use ($ids) { + foreach ($ids as $id) { + $q->orWhere('path', 'like', '%-'.$id.'-%'); + } + })->delete(); - return $this->query()->whereIn('id', $ids)->delete(); + return true; } public function validate($data, $id = null)