This commit is contained in:
nanguaboss
2026-08-03 00:07:01 +08:00
commit 71c6e8d9c1
112 changed files with 7815 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
<?php
/**
* 渠道删除接口 POST /api/channel/delete.php
* 入参:id(或 ids 逗号分隔批量)
*/
require_once __DIR__ . '/../common/db.php';
require_once __DIR__ . '/../common/response.php';
require_once __DIR__ . '/../common/auth.php';
require_once __DIR__ . '/../common/logger.php';
checkAjax();
checkPermission('channel');
$id = (int)($_POST['id'] ?? 0);
$ids = trim($_POST['ids'] ?? '');
$idList = [];
if ($id > 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("DELETE FROM channels WHERE id IN ($in)");
$stmt->execute($idList);
$affected = $stmt->rowCount();
logCurrent('delete', 'channel', 'channels', null, ['ids' => $idList]);
Response::success(['affected' => $affected], "已删除 $affected 个渠道");
+50
View File
@@ -0,0 +1,50 @@
<?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]);
+53
View File
@@ -0,0 +1,53 @@
<?php
/**
* 渠道新增/编辑接口 POST /api/channel/save.php
* 入参:id(编辑时必传)/ channel_name / channel_type / contact_person / contact_phone / contact_email / efficiency_score / remark
* 数据源:channels 表(见 sql/system_tables.sql 第5节)
*/
require_once __DIR__ . '/../common/db.php';
require_once __DIR__ . '/../common/response.php';
require_once __DIR__ . '/../common/auth.php';
require_once __DIR__ . '/../common/logger.php';
require_once __DIR__ . '/../common/helpers.php';
checkAjax();
checkPermission('channel');
$id = (int)($_POST['id'] ?? 0);
$channelName = trim($_POST['channel_name'] ?? '');
if ($channelName === '') {
Response::error('渠道名称为必填项', 400);
}
$fields = [
'channel_name' => $channelName,
'channel_type' => trim($_POST['channel_type'] ?? '') ?: null,
'contact_person' => trim($_POST['contact_person'] ?? '') ?: null,
'contact_phone' => trim($_POST['contact_phone'] ?? '') ?: null,
'contact_email' => trim($_POST['contact_email'] ?? '') ?: null,
'remark' => trim($_POST['remark'] ?? '') ?: null,
];
$score = (float)($_POST['efficiency_score'] ?? 0);
$fields['efficiency_score'] = max(0, min(100, $score));
$pdo = DB::getInstance()->getPdo();
if ($id > 0) {
$check = $pdo->prepare("SELECT * FROM channels WHERE id = ?");
$check->execute([$id]);
$old = $check->fetch();
if (!$old) {
Response::error('渠道不存在');
}
[$sets, $params] = buildUpdate($fields);
$params[] = $id;
$pdo->prepare("UPDATE channels SET $sets WHERE id = ?")->execute($params);
logCurrent('update', 'channel', 'channels', $id, ['before' => $old, 'after' => $fields]);
Response::success(['id' => $id], '更新成功');
}
[$sql, $params] = buildInsert($fields);
$pdo->prepare("INSERT INTO channels $sql")->execute($params);
$newId = (int)$pdo->lastInsertId();
logCurrent('add', 'channel', 'channels', $newId, $fields);
Response::success(['id' => $newId], '新增成功');
+44
View File
@@ -0,0 +1,44 @@
<?php
/**
* 渠道年度统计接口 GET /api/channel/stats.php?year=2025
* 返回:指定年度(默认今年)各渠道效率统计 + 年度汇总
*/
require_once __DIR__ . '/../common/db.php';
require_once __DIR__ . '/../common/response.php';
require_once __DIR__ . '/../common/auth.php';
checkPermission('channel');
$year = (int)($_REQUEST['year'] ?? date('Y'));
if ($year < 2000 || $year > 2100) {
$year = (int)date('Y');
}
$pdo = DB::getInstance()->getPdo();
$rows = $pdo->prepare(
"SELECT id, channel_name, channel_type, efficiency_score, created_at
FROM channels
WHERE is_active = 1 AND YEAR(created_at) = ?
ORDER BY efficiency_score DESC"
);
$rows->execute([$year]);
$list = $rows->fetchAll();
$summary = [
'channel_count' => count($list),
'avg_score' => 0,
'max_score' => 0,
'min_score' => 0,
];
if ($list) {
$scores = array_column($list, 'efficiency_score');
$summary['avg_score'] = round(array_sum($scores) / count($scores), 2);
$summary['max_score'] = (float)max($scores);
$summary['min_score'] = (float)min($scores);
}
// 可用年度(用于前端下拉)
$years = $pdo->query("SELECT DISTINCT YEAR(created_at) AS y FROM channels WHERE is_active = 1 ORDER BY y DESC")->fetchAll(PDO::FETCH_COLUMN);
Response::success(['year' => $year, 'list' => $list, 'summary' => $summary, 'years' => $years]);