From 2d3a9b5ef94b61fa51812b150337bfc79e3e51ad Mon Sep 17 00:00:00 2001 From: Anyon Date: Mon, 17 Nov 2025 12:36:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=B8=85=E7=90=86=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/think-plugs-admin/src/controller/File.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugin/think-plugs-admin/src/controller/File.php b/plugin/think-plugs-admin/src/controller/File.php index 87202286a..9c44143e5 100644 --- a/plugin/think-plugs-admin/src/controller/File.php +++ b/plugin/think-plugs-admin/src/controller/File.php @@ -109,8 +109,12 @@ class File extends Controller public function distinct() { $map = ['issafe' => 0, 'uuid' => AdminService::getUserId()]; - $subQuery = SystemFile::mk()->fieldRaw('MAX(id) AS id')->where($map)->group('type, xkey')->buildSql(); - SystemFile::mk()->where($map)->whereRaw("id NOT IN ({$subQuery})")->delete(); + // 使用派生表包装子查询,避免直接引用同一表 + $keepSubQuery = SystemFile::mk()->fieldRaw('MAX(id) AS id')->where($map)->group('type, xkey')->buildSql(); + // 使用 whereNotExists 配合派生表子查询删除,避免 1093 错误和 whereIn + SystemFile::mk()->where($map)->whereNotExists(function ($query) use ($keepSubQuery) { + $query->table("({$keepSubQuery})")->alias('f2')->whereRaw('f2.id = system_file.id'); + })->delete(); $this->success('清理重复文件成功!'); } } \ No newline at end of file