Files
superlink/api/fragment/hard_list.php
T

63 lines
2.4 KiB
PHP

<?php
/**
* 硬碎片列表接口 GET /api/fragment/hard_list.php
* 参数:page / limit / source_type / status / source_channel / keyword
* 返回:{ list, total, page, limit },每行含完整度 score、缺失层级、内容摘要
*/
require_once __DIR__ . '/../common/db.php';
require_once __DIR__ . '/../common/response.php';
require_once __DIR__ . '/../common/auth.php';
require_once __DIR__ . '/hard_common.php';
checkPermission('preliminary');
[$page, $limit] = pageParams();
$keyword = trim($_REQUEST['keyword'] ?? '');
$status = trim($_REQUEST['status'] ?? '');
$sourceType = trim($_REQUEST['source_type'] ?? '');
$sourceChannel = trim($_REQUEST['source_channel'] ?? '');
$where = ["is_active = 1", "status NOT IN ('已转换','已废弃')"];
$params = [];
if ($keyword !== '') {
$where[] = '(company_name LIKE ? OR person_name LIKE ? OR contact_phone LIKE ? OR contact_email LIKE ? OR description LIKE ?)';
$like = "%$keyword%";
array_push($params, $like, $like, $like, $like, $like);
}
if ($status !== '') { $where[] = 'status = ?'; $params[] = $status; }
if ($sourceType !== '') { $where[] = 'source_type = ?'; $params[] = $sourceType; }
if ($sourceChannel !== '') { $where[] = 'source_channel = ?'; $params[] = $sourceChannel; }
$whereSql = implode(' AND ', $where);
$pdo = DB::getInstance()->getPdo();
$stmt = $pdo->prepare("SELECT COUNT(*) FROM preliminary_data WHERE $whereSql");
$stmt->execute($params);
$total = (int)$stmt->fetchColumn();
$offset = ($page - 1) * $limit;
$stmt = $pdo->prepare(
"SELECT id, source_type, company_name, person_name, contact_phone, contact_email,
target_product_category, description, status, source_channel, recorded_by,
follow_person, converted_type, converted_id, created_at, updated_at
FROM preliminary_data
WHERE $whereSql
ORDER BY id DESC
LIMIT $limit OFFSET $offset"
);
$stmt->execute($params);
$rows = $stmt->fetchAll();
$list = [];
foreach ($rows as $r) {
$calc = hardCompleteness($r);
$r['completeness'] = $calc['score'];
$r['level'] = $calc['level'];
$r['missing'] = $calc['missing'];
$r['summary'] = hardSummary($r);
$r['source_type_label'] = ['company' => '企业', 'person' => '人员', 'product' => '产品', 'need' => '需求', 'mixed' => '混合'][$r['source_type']] ?? $r['source_type'];
$list[] = $r;
}
Response::success(['list' => $list, 'total' => $total, 'page' => $page, 'limit' => $limit]);