50 lines
1.5 KiB
PHP
50 lines
1.5 KiB
PHP
<?php
|
|
/**
|
|
* 文件列表接口 GET/POST /api/document/list.php
|
|
* 参数:page / limit / keyword / file_type / is_active
|
|
* 数据源:company_documents 表
|
|
*/
|
|
require_once __DIR__ . '/../common/db.php';
|
|
require_once __DIR__ . '/../common/response.php';
|
|
require_once __DIR__ . '/../common/auth.php';
|
|
|
|
checkPermission('document');
|
|
|
|
[$page, $limit] = pageParams();
|
|
$keyword = trim($_REQUEST['keyword'] ?? '');
|
|
$fileType = trim($_REQUEST['file_type'] ?? '');
|
|
$active = isset($_REQUEST['is_active']) && $_REQUEST['is_active'] !== '' ? (int)$_REQUEST['is_active'] : null;
|
|
|
|
$where = ['is_active = 1'];
|
|
$params = [];
|
|
if ($active !== null) {
|
|
$where = ['is_active = ?'];
|
|
$params = [$active];
|
|
}
|
|
if ($keyword !== '') {
|
|
$where[] = '(doc_name LIKE ? OR document_source LIKE ?)';
|
|
$like = "%$keyword%";
|
|
array_push($params, $like, $like);
|
|
}
|
|
if ($fileType !== '') { $where[] = 'file_type = ?'; $params[] = $fileType; }
|
|
$whereSql = implode(' AND ', $where);
|
|
|
|
$pdo = DB::getInstance()->getPdo();
|
|
|
|
$stmt = $pdo->prepare("SELECT COUNT(*) FROM company_documents WHERE $whereSql");
|
|
$stmt->execute($params);
|
|
$total = (int)$stmt->fetchColumn();
|
|
|
|
$offset = ($page - 1) * $limit;
|
|
$stmt = $pdo->prepare(
|
|
"SELECT id, doc_name, storage_path, file_type, is_current, publish_date, document_source, tags, is_active, created_at
|
|
FROM company_documents
|
|
WHERE $whereSql
|
|
ORDER BY id DESC
|
|
LIMIT $limit OFFSET $offset"
|
|
);
|
|
$stmt->execute($params);
|
|
$list = $stmt->fetchAll();
|
|
|
|
Response::success(['list' => $list, 'total' => $total, 'page' => $page, 'limit' => $limit]);
|