0) $idList[] = $id; if ($ids !== '') { foreach (explode(',', $ids) as $v) { $v = (int)trim($v); if ($v > 0) $idList[] = $v; } } $idList = array_unique($idList); if (!$idList) { Response::error('参数错误', 400); } $pdo = DB::getInstance()->getPdo(); $in = implode(',', array_fill(0, count($idList), '?')); // 取出物理路径 $stmt = $pdo->prepare("SELECT id, storage_path FROM company_documents WHERE id IN ($in)"); $stmt->execute($idList); $docs = $stmt->fetchAll(); // 删除物理文件(仅限本站上传目录内的文件) foreach ($docs as $doc) { $path = $doc['storage_path']; if (strpos($path, 'static/uploads/documents/') === 0) { $full = __DIR__ . '/../../' . $path; if (is_file($full)) { @unlink($full); } } } // 删除记录(document_links 级联删除) $del = $pdo->prepare("DELETE FROM company_documents WHERE id IN ($in)"); $del->execute($idList); $affected = $del->rowCount(); logCurrent('delete', 'document', 'company_documents', null, ['ids' => $idList]); Response::success(['affected' => $affected], "已删除 $affected 个文件(含物理文件)");