mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-11-28 23:42:08 +08:00
fix: 修复重复文件清理处理
This commit is contained in:
parent
d00ad29f7b
commit
ed5cbd1478
@ -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('清理重复文件成功!');
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user