Files
superlink/api/channel/list.php
T
nanguaboss 71c6e8d9c1 v1.0.10
2026-08-03 00:07:01 +08:00

51 lines
1.7 KiB
PHP

<?php
/**
* 渠道列表接口 GET/POST /api/channel/list.php
* 参数:page / limit / keyword / channel_type / is_active
* 数据源:channels 表(见 sql/system_tables.sql 第5节)
*/
require_once __DIR__ . '/../common/db.php';
require_once __DIR__ . '/../common/response.php';
require_once __DIR__ . '/../common/auth.php';
checkPermission('channel');
[$page, $limit] = pageParams();
$keyword = trim($_REQUEST['keyword'] ?? '');
$type = trim($_REQUEST['channel_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[] = '(channel_name LIKE ? OR contact_person LIKE ? OR contact_phone LIKE ? OR contact_email LIKE ?)';
$like = "%$keyword%";
array_push($params, $like, $like, $like, $like);
}
if ($type !== '') { $where[] = 'channel_type = ?'; $params[] = $type; }
$whereSql = implode(' AND ', $where);
$pdo = DB::getInstance()->getPdo();
$stmt = $pdo->prepare("SELECT COUNT(*) FROM channels WHERE $whereSql");
$stmt->execute($params);
$total = (int)$stmt->fetchColumn();
$offset = ($page - 1) * $limit;
$stmt = $pdo->prepare(
"SELECT id, channel_name, channel_type, contact_person, contact_phone, contact_email,
efficiency_score, remark, is_active, created_at, updated_at
FROM channels
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]);