v1.0.19: 修复人员编辑入口缺失(person.js addPerson/editPerson) + 渠道明细数量字段名(analysis.php cnt) + CDP全量验证43项PASS
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
* 渠道效能分析接口 GET /api/channel/analysis.php?year=2025
|
||||
* v1.0.18 渠道管理 - 渠道效能分析:
|
||||
* - 企业/人员两个维度,分别按 source_channel(渠道字段)分组计数、按数量降序、计算百分比
|
||||
* - 每个渠道附带 source_detail TOP10 排名(来源/数量)
|
||||
* - year 为空 = 全部年份;否则按创建年份过滤
|
||||
* 返回:{ years, company: [{channel, count, percent, details:[{source,count}]}], person: [...] }
|
||||
*/
|
||||
require_once __DIR__ . '/../common/db.php';
|
||||
require_once __DIR__ . '/../common/response.php';
|
||||
require_once __DIR__ . '/../common/auth.php';
|
||||
|
||||
checkPermission('channel');
|
||||
|
||||
$year = trim($_REQUEST['year'] ?? '');
|
||||
if ($year !== '' && (!ctype_digit($year) || (int)$year < 2000 || (int)$year > 2100)) {
|
||||
$year = '';
|
||||
}
|
||||
|
||||
$pdo = DB::getInstance()->getPdo();
|
||||
|
||||
// 可选年份(企业/人员创建年份并集)
|
||||
$years = $pdo->query(
|
||||
"SELECT DISTINCT y FROM (
|
||||
SELECT YEAR(created_at) AS y FROM companies WHERE is_active = 1 AND created_at IS NOT NULL
|
||||
UNION
|
||||
SELECT YEAR(created_at) AS y FROM persons WHERE is_active = 1 AND created_at IS NOT NULL
|
||||
) t ORDER BY y DESC"
|
||||
)->fetchAll(PDO::FETCH_COLUMN);
|
||||
|
||||
/** 单维度渠道分析 */
|
||||
function channelAnalysis($pdo, $table, $year)
|
||||
{
|
||||
$where = 'is_active = 1 AND source_channel IS NOT NULL AND source_channel <> \'\'';
|
||||
$params = [];
|
||||
if ($year !== '') {
|
||||
$where .= ' AND YEAR(created_at) = ?';
|
||||
$params[] = (int)$year;
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare(
|
||||
"SELECT source_channel AS channel, COUNT(*) AS cnt
|
||||
FROM $table WHERE $where
|
||||
GROUP BY source_channel ORDER BY cnt DESC"
|
||||
);
|
||||
$stmt->execute($params);
|
||||
$rows = $stmt->fetchAll();
|
||||
|
||||
$total = 0;
|
||||
foreach ($rows as $r) {
|
||||
$total += (int)$r['cnt'];
|
||||
}
|
||||
|
||||
$result = [];
|
||||
foreach ($rows as $r) {
|
||||
$channel = $r['channel'];
|
||||
// 该渠道 source_detail TOP10
|
||||
$detailStmt = $pdo->prepare(
|
||||
"SELECT COALESCE(NULLIF(TRIM(source_detail), ''), '(未填写)') AS source, COUNT(*) AS cnt
|
||||
FROM $table
|
||||
WHERE is_active = 1 AND source_channel = ?" . ($year !== '' ? ' AND YEAR(created_at) = ?' : '') . "
|
||||
GROUP BY source ORDER BY cnt DESC LIMIT 10"
|
||||
);
|
||||
$dParams = [$channel];
|
||||
if ($year !== '') {
|
||||
$dParams[] = (int)$year;
|
||||
}
|
||||
$detailStmt->execute($dParams);
|
||||
|
||||
$result[] = [
|
||||
'channel' => $channel,
|
||||
'count' => (int)$r['cnt'],
|
||||
'percent' => $total > 0 ? round(((int)$r['cnt'] / $total) * 100, 1) : 0,
|
||||
'details' => $detailStmt->fetchAll(),
|
||||
];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
Response::success([
|
||||
'years' => $years,
|
||||
'company' => channelAnalysis($pdo, 'companies', $year),
|
||||
'person' => channelAnalysis($pdo, 'persons', $year),
|
||||
]);
|
||||
@@ -1,36 +0,0 @@
|
||||
<?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 个渠道");
|
||||
@@ -1,50 +0,0 @@
|
||||
<?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]);
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* 渠道新增计划删除接口 POST /api/channel/plan_delete.php
|
||||
* 入参:id(必填);软删除(is_active = 0)
|
||||
*/
|
||||
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);
|
||||
if ($id <= 0) {
|
||||
Response::error('参数错误', 400);
|
||||
}
|
||||
|
||||
$pdo = DB::getInstance()->getPdo();
|
||||
$stmt = $pdo->prepare("UPDATE channel_plans SET is_active = 0 WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
if ($stmt->rowCount() === 0) {
|
||||
Response::error('计划不存在');
|
||||
}
|
||||
|
||||
logCurrent('delete', 'channel_plan', 'channel_plans', $id, ['soft_delete' => true]);
|
||||
Response::success(null, '删除成功');
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* 渠道新增计划列表接口 GET /api/channel/plan_list.php
|
||||
* v1.0.18 渠道管理 - 渠道新增计划
|
||||
* 参数:page / limit / channel_type / status / keyword
|
||||
* 返回:{ list, total, page, limit }(list 含 remaining_days 剩余天数)
|
||||
*/
|
||||
require_once __DIR__ . '/../common/db.php';
|
||||
require_once __DIR__ . '/../common/response.php';
|
||||
require_once __DIR__ . '/../common/auth.php';
|
||||
|
||||
checkPermission('channel');
|
||||
|
||||
[$page, $limit] = pageParams();
|
||||
$channelType = trim($_REQUEST['channel_type'] ?? '');
|
||||
$status = trim($_REQUEST['status'] ?? '');
|
||||
$keyword = trim($_REQUEST['keyword'] ?? '');
|
||||
|
||||
$where = ['is_active = 1'];
|
||||
$params = [];
|
||||
if ($channelType !== '') {
|
||||
$where[] = 'channel_type = ?';
|
||||
$params[] = $channelType;
|
||||
}
|
||||
if ($status !== '') {
|
||||
$where[] = 'status = ?';
|
||||
$params[] = $status;
|
||||
}
|
||||
if ($keyword !== '') {
|
||||
$where[] = '(source_detail LIKE ? OR industry LIKE ? OR remark LIKE ?)';
|
||||
$like = "%$keyword%";
|
||||
array_push($params, $like, $like, $like);
|
||||
}
|
||||
$whereSql = implode(' AND ', $where);
|
||||
|
||||
$pdo = DB::getInstance()->getPdo();
|
||||
|
||||
$stmt = $pdo->prepare("SELECT COUNT(*) FROM channel_plans WHERE $whereSql");
|
||||
$stmt->execute($params);
|
||||
$total = (int)$stmt->fetchColumn();
|
||||
|
||||
$offset = ($page - 1) * $limit;
|
||||
$stmt = $pdo->prepare(
|
||||
"SELECT id, channel_type, source_detail, industry, start_date, end_date, remark, status, created_at, updated_at
|
||||
FROM channel_plans
|
||||
WHERE $whereSql
|
||||
ORDER BY id DESC
|
||||
LIMIT $limit OFFSET $offset"
|
||||
);
|
||||
$stmt->execute($params);
|
||||
$list = $stmt->fetchAll();
|
||||
|
||||
// 剩余天数:距时间窗口结束日(end_date)的天数,已过期为 0
|
||||
$today = strtotime(date('Y-m-d'));
|
||||
foreach ($list as &$row) {
|
||||
$row['remaining_days'] = 0;
|
||||
if (!empty($row['end_date']) && strtotime($row['end_date']) !== false) {
|
||||
$diff = (int)ceil((strtotime($row['end_date']) - $today) / 86400);
|
||||
$row['remaining_days'] = max(0, $diff);
|
||||
}
|
||||
}
|
||||
unset($row);
|
||||
|
||||
Response::success(['list' => $list, 'total' => $total, 'page' => $page, 'limit' => $limit]);
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* 渠道新增计划保存接口 POST /api/channel/plan_save.php
|
||||
* 入参:id(可选,编辑时传)/ channel_type(渠道类别=source_channel 枚举,必填)/
|
||||
* source_detail / industry / start_date / end_date / remark / status(待启动|已执行|错过)
|
||||
*/
|
||||
require_once __DIR__ . '/../common/db.php';
|
||||
require_once __DIR__ . '/../common/response.php';
|
||||
require_once __DIR__ . '/../common/auth.php';
|
||||
require_once __DIR__ . '/../common/helpers.php';
|
||||
require_once __DIR__ . '/../common/logger.php';
|
||||
|
||||
checkAjax();
|
||||
checkPermission('channel');
|
||||
|
||||
$channelType = trim($_POST['channel_type'] ?? '');
|
||||
if ($channelType === '') {
|
||||
Response::error('渠道类别(channel_type)为必填项', 400);
|
||||
}
|
||||
$status = trim($_POST['status'] ?? '待启动');
|
||||
if (!in_array($status, ['待启动', '已执行', '错过'], true)) {
|
||||
$status = '待启动';
|
||||
}
|
||||
|
||||
$id = (int)($_POST['id'] ?? 0);
|
||||
$pdo = DB::getInstance()->getPdo();
|
||||
|
||||
$fields = [
|
||||
'channel_type' => $channelType,
|
||||
'source_detail' => trim($_POST['source_detail'] ?? '') !== '' ? trim($_POST['source_detail']) : null,
|
||||
'industry' => trim($_POST['industry'] ?? '') !== '' ? trim($_POST['industry']) : null,
|
||||
'start_date' => trim($_POST['start_date'] ?? '') !== '' ? $_POST['start_date'] : null,
|
||||
'end_date' => trim($_POST['end_date'] ?? '') !== '' ? $_POST['end_date'] : null,
|
||||
'remark' => trim($_POST['remark'] ?? '') !== '' ? trim($_POST['remark']) : null,
|
||||
'status' => $status,
|
||||
];
|
||||
|
||||
if ($id > 0) {
|
||||
$check = $pdo->prepare("SELECT id FROM channel_plans WHERE id = ? AND is_active = 1");
|
||||
$check->execute([$id]);
|
||||
if (!$check->fetch()) {
|
||||
Response::error('计划不存在');
|
||||
}
|
||||
[$sets, $params] = buildUpdate($fields);
|
||||
$params[] = $id;
|
||||
$pdo->prepare("UPDATE channel_plans SET $sets WHERE id = ?")->execute($params);
|
||||
logCurrent('update', 'channel_plan', 'channel_plans', $id, $fields);
|
||||
Response::success(null, '更新成功');
|
||||
}
|
||||
|
||||
[$sql, $params] = buildInsert($fields);
|
||||
$pdo->prepare("INSERT INTO channel_plans $sql")->execute($params);
|
||||
$newId = (int)$pdo->lastInsertId();
|
||||
logCurrent('add', 'channel_plan', 'channel_plans', $newId, $fields);
|
||||
Response::success(['id' => $newId], '新增成功');
|
||||
@@ -1,53 +0,0 @@
|
||||
<?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], '新增成功');
|
||||
@@ -1,44 +0,0 @@
|
||||
<?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]);
|
||||
@@ -18,22 +18,22 @@ $data = [];
|
||||
|
||||
if ($type === 'all' || $type === 'country') {
|
||||
$data['countries'] = $pdo->query(
|
||||
"SELECT id, code, name FROM date_dict_country WHERE is_active = 1 ORDER BY sort_order, id"
|
||||
"SELECT id, code, name FROM data_dict_country WHERE is_active = 1 ORDER BY sort_order, id"
|
||||
)->fetchAll();
|
||||
}
|
||||
if ($type === 'all' || $type === 'area') {
|
||||
$data['areas'] = $pdo->query(
|
||||
"SELECT id, code, name, parent_code FROM date_dict_area WHERE is_active = 1 ORDER BY sort_order, id"
|
||||
"SELECT id, code, name, parent_code FROM data_dict_area WHERE is_active = 1 ORDER BY sort_order, id"
|
||||
)->fetchAll();
|
||||
}
|
||||
if ($type === 'all' || $type === 'industry') {
|
||||
$data['industries'] = $pdo->query(
|
||||
"SELECT id, code, name, parent_code FROM date_dict_industry WHERE is_active = 1 ORDER BY sort_order, id"
|
||||
"SELECT id, code, name, parent_code FROM data_dict_industry WHERE is_active = 1 ORDER BY sort_order, id"
|
||||
)->fetchAll();
|
||||
}
|
||||
if ($type === 'all' || $type === 'certificate') {
|
||||
$data['certificates'] = $pdo->query(
|
||||
"SELECT id, code, name FROM date_dict_certificate WHERE is_active = 1 ORDER BY sort_order, id"
|
||||
"SELECT id, code, name FROM data_dict_certificate WHERE is_active = 1 ORDER BY sort_order, id"
|
||||
)->fetchAll();
|
||||
}
|
||||
if ($type === 'all' || $type === 'source_channel') {
|
||||
@@ -41,5 +41,10 @@ if ($type === 'all' || $type === 'source_channel') {
|
||||
"SELECT id, name FROM source_channels WHERE is_active = 1 ORDER BY sort_order, id"
|
||||
)->fetchAll();
|
||||
}
|
||||
if ($type === 'all' || $type === 'company_type') {
|
||||
$data['company_types'] = $pdo->query(
|
||||
"SELECT id, code, name FROM data_dict_company_type WHERE is_active = 1 ORDER BY sort_order, id"
|
||||
)->fetchAll();
|
||||
}
|
||||
|
||||
Response::success($data);
|
||||
|
||||
+86
-3
@@ -110,6 +110,87 @@ function strOrNull($v)
|
||||
return ($v === '') ? null : $v;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存人员工作履历(整表替换:先删后插)
|
||||
* @param PDO $pdo
|
||||
* @param int $personId
|
||||
* @param array $experiences JSON 解码后的数组 [{company_id,position,department,job_level,start_date,end_date,is_current}]
|
||||
*/
|
||||
function savePersonExperiences($pdo, $personId, $experiences)
|
||||
{
|
||||
$del = $pdo->prepare("DELETE FROM person_work_experiences WHERE person_id = ?");
|
||||
$del->execute([$personId]);
|
||||
if (empty($experiences)) {
|
||||
return;
|
||||
}
|
||||
$ins = $pdo->prepare(
|
||||
"INSERT INTO person_work_experiences
|
||||
(person_id, company_id, position, department, job_level, start_date, end_date, is_current)
|
||||
VALUES (?,?,?,?,?,?,?,?)"
|
||||
);
|
||||
foreach ($experiences as $e) {
|
||||
if (!is_array($e)) {
|
||||
continue;
|
||||
}
|
||||
$companyId = (int)($e['company_id'] ?? 0);
|
||||
if ($companyId <= 0) {
|
||||
continue;
|
||||
}
|
||||
$start = strOrNull($e['start_date'] ?? null);
|
||||
$end = strOrNull($e['end_date'] ?? null);
|
||||
$ins->execute([
|
||||
$personId,
|
||||
$companyId,
|
||||
strOrNull($e['position'] ?? null),
|
||||
strOrNull($e['department'] ?? null),
|
||||
strOrNull($e['job_level'] ?? null),
|
||||
$start !== null && strtotime($start) !== false ? date('Y-m-d', strtotime($start)) : null,
|
||||
$end !== null && strtotime($end) !== false ? date('Y-m-d', strtotime($end)) : null,
|
||||
!empty($e['is_current']) ? 1 : 0,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存企业联系方式(social_accounts,整表替换:先删后插)
|
||||
* 只操作 owner_type = 'company' 的记录
|
||||
* @param PDO $pdo
|
||||
* @param int $companyId
|
||||
* @param array $accounts JSON 解码后的数组 [{platform,account_id,profile_url,remark,is_active,is_defult}]
|
||||
*/
|
||||
function saveCompanyAccounts($pdo, $companyId, $accounts)
|
||||
{
|
||||
$del = $pdo->prepare("DELETE FROM social_accounts WHERE owner_type = 'company' AND owner_id = ?");
|
||||
$del->execute([$companyId]);
|
||||
if (empty($accounts)) {
|
||||
return;
|
||||
}
|
||||
$ins = $pdo->prepare(
|
||||
"INSERT INTO social_accounts
|
||||
(owner_type, owner_id, platform, account_id, profile_url, remark, is_primary, is_defult, is_active)
|
||||
VALUES ('company', ?, ?, ?, ?, ?, 0, ?, ?)"
|
||||
);
|
||||
foreach ($accounts as $a) {
|
||||
if (!is_array($a)) {
|
||||
continue;
|
||||
}
|
||||
$platform = trim($a['platform'] ?? '');
|
||||
$accountId = trim($a['account_id'] ?? '');
|
||||
if ($platform === '' || $accountId === '') {
|
||||
continue;
|
||||
}
|
||||
$ins->execute([
|
||||
$companyId,
|
||||
$platform,
|
||||
$accountId,
|
||||
strOrNull($a['profile_url'] ?? null),
|
||||
strOrNull($a['remark'] ?? null),
|
||||
!empty($a['is_defult']) ? 1 : 0,
|
||||
!empty($a['is_active']) ? 1 : 0,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存企业年度财务明细(整表替换:先删后插)
|
||||
* @param PDO $pdo
|
||||
@@ -175,11 +256,11 @@ function saveCompanyCertifications($pdo, $companyId, $certifications)
|
||||
return;
|
||||
}
|
||||
|
||||
$valid = $pdo->prepare("SELECT id FROM date_dict_certificate WHERE id = ?");
|
||||
$valid = $pdo->prepare("SELECT id FROM data_dict_certificate WHERE id = ?");
|
||||
$ins = $pdo->prepare(
|
||||
"INSERT INTO company_certifications
|
||||
(company_id, certification_type_id, certificate_number, issue_date, expiry_date)
|
||||
VALUES (?,?,?,?,?)"
|
||||
(company_id, certification_type_id, certificate_number, level, issuing_authority, issue_date, expiry_date)
|
||||
VALUES (?,?,?,?,?,?,?)"
|
||||
);
|
||||
$seen = [];
|
||||
foreach ($certifications as $ct) {
|
||||
@@ -199,6 +280,8 @@ function saveCompanyCertifications($pdo, $companyId, $certifications)
|
||||
$companyId,
|
||||
$tid,
|
||||
strOrNull($ct['certificate_number'] ?? null),
|
||||
strOrNull($ct['level'] ?? null),
|
||||
strOrNull($ct['issuing_authority'] ?? null),
|
||||
strOrNull($ct['issue_date'] ?? null),
|
||||
strOrNull($ct['expiry_date'] ?? null),
|
||||
]);
|
||||
|
||||
+10
-2
@@ -26,8 +26,8 @@ $pdo = DB::getInstance()->getPdo();
|
||||
$pdo->prepare("INSERT INTO companies $sql")->execute($params);
|
||||
$newId = (int)$pdo->lastInsertId();
|
||||
|
||||
// 财务信息 / 资质认证(可选,整表替换)
|
||||
if (array_key_exists('financials', $_POST) || array_key_exists('certifications', $_POST)) {
|
||||
// 财务信息 / 资质认证 / 联系方式(可选,整表替换)
|
||||
if (array_key_exists('financials', $_POST) || array_key_exists('certifications', $_POST) || array_key_exists('accounts', $_POST)) {
|
||||
$pdo->beginTransaction();
|
||||
try {
|
||||
if (array_key_exists('financials', $_POST)) {
|
||||
@@ -46,6 +46,14 @@ if (array_key_exists('financials', $_POST) || array_key_exists('certifications',
|
||||
}
|
||||
saveCompanyCertifications($pdo, $newId, $certs);
|
||||
}
|
||||
if (array_key_exists('accounts', $_POST)) {
|
||||
$accounts = json_decode($_POST['accounts'], true);
|
||||
if (!is_array($accounts)) {
|
||||
$pdo->rollBack();
|
||||
Response::error('联系方式格式错误', 400);
|
||||
}
|
||||
saveCompanyAccounts($pdo, $newId, $accounts);
|
||||
}
|
||||
$pdo->commit();
|
||||
} catch (Exception $e) {
|
||||
$pdo->rollBack();
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/**
|
||||
* 认证类型字典接口 GET /api/company/cert_types.php
|
||||
* 返回启用中的认证类型(如:瞪羚企业、国家高新技术企业等),供编辑弹窗下拉使用
|
||||
* 数据源:date_dict_certificate(原 certification_types,v1.0.16 改名)
|
||||
* 数据源:data_dict_certificate(原 certification_types,v1.0.16 改名,v1.0.18 再改名 data_dict_certificate)
|
||||
*/
|
||||
require_once __DIR__ . '/../common/db.php';
|
||||
require_once __DIR__ . '/../common/response.php';
|
||||
@@ -11,6 +11,6 @@ require_once __DIR__ . '/../common/auth.php';
|
||||
checkPermission('company');
|
||||
|
||||
$pdo = DB::getInstance()->getPdo();
|
||||
$types = $pdo->query("SELECT id, name FROM date_dict_certificate WHERE is_active = 1 ORDER BY sort_order, id")->fetchAll();
|
||||
$types = $pdo->query("SELECT id, name FROM data_dict_certificate WHERE is_active = 1 ORDER BY sort_order, id")->fetchAll();
|
||||
|
||||
Response::success(['types' => $types]);
|
||||
|
||||
@@ -23,7 +23,7 @@ if (!$company) {
|
||||
Response::error('企业不存在');
|
||||
}
|
||||
|
||||
$products = $pdo->prepare("SELECT id, category_name, category_description, is_core, is_active FROM company_products WHERE company_id = ? AND is_active = 1");
|
||||
$products = $pdo->prepare("SELECT id, category_name, category_description, positioning, series, is_core, is_active, created_at, updated_at FROM company_products WHERE company_id = ? AND is_active = 1");
|
||||
$products->execute([$id]);
|
||||
|
||||
$docs = $pdo->prepare(
|
||||
@@ -45,18 +45,18 @@ $relations = $pdo->prepare(
|
||||
);
|
||||
$relations->execute([$id]);
|
||||
|
||||
// 资质认证(瞪羚企业等,JOIN 字典表取名称)
|
||||
// 资质认证(瞪羚企业等,JOIN 字典表取名称;含级别/颁证机构)
|
||||
$certs = $pdo->prepare(
|
||||
"SELECT cc.certification_type_id, ct.name AS certification_name, cc.certificate_number,
|
||||
cc.issue_date, cc.expiry_date
|
||||
cc.level, cc.issuing_authority, cc.issue_date, cc.expiry_date
|
||||
FROM company_certifications cc
|
||||
INNER JOIN date_dict_certificate ct ON ct.id = cc.certification_type_id
|
||||
INNER JOIN data_dict_certificate ct ON ct.id = cc.certification_type_id
|
||||
WHERE cc.company_id = ?
|
||||
ORDER BY ct.sort_order, ct.id"
|
||||
);
|
||||
$certs->execute([$id]);
|
||||
|
||||
$certTypes = $pdo->query("SELECT id, name FROM date_dict_certificate WHERE is_active = 1 ORDER BY sort_order, id")->fetchAll();
|
||||
$certTypes = $pdo->query("SELECT id, name FROM data_dict_certificate WHERE is_active = 1 ORDER BY sort_order, id")->fetchAll();
|
||||
|
||||
// 联系方式:social_accounts 中属于该公司的记录(仅展示,无修改/删除入口)
|
||||
$accounts = $pdo->prepare(
|
||||
|
||||
+31
-20
@@ -1,7 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* 企业列表接口 GET/POST /api/company/list.php
|
||||
* 参数:page / limit / keyword(公司名/注册号)/ industry / business_role / country / is_active
|
||||
* v1.0.18 检索改造:
|
||||
* - field + keyword 联动:field=具体字段(如 name_zh/registration_number/…),keyword 只匹配该字段;field 为空=全部字段
|
||||
* - industry:行业下拉(精确匹配)
|
||||
* - company_type:企业类型(companies.legal_form,取自 data_dict_company_type)
|
||||
* 参数:page / limit / keyword / field / industry / company_type / is_active
|
||||
* 返回:{ list, total, page, limit }
|
||||
*/
|
||||
require_once __DIR__ . '/../common/db.php';
|
||||
@@ -11,36 +15,43 @@ require_once __DIR__ . '/../common/auth.php';
|
||||
checkPermission('company');
|
||||
|
||||
[$page, $limit] = pageParams();
|
||||
$keyword = trim($_REQUEST['keyword'] ?? '');
|
||||
$keyword = trim($_REQUEST['keyword'] ?? '');
|
||||
$field = trim($_REQUEST['field'] ?? '');
|
||||
$industry = trim($_REQUEST['industry'] ?? '');
|
||||
$role = trim($_REQUEST['business_role'] ?? '');
|
||||
$country = trim($_REQUEST['country'] ?? '');
|
||||
$active = isset($_REQUEST['is_active']) && $_REQUEST['is_active'] !== '' ? (int)$_REQUEST['is_active'] : null;
|
||||
$companyType = trim($_REQUEST['company_type'] ?? '');
|
||||
$active = isset($_REQUEST['is_active']) && $_REQUEST['is_active'] !== '' ? (int)$_REQUEST['is_active'] : null;
|
||||
|
||||
// 可指定筛选的字段白名单(下拉选项来自前端「筛选」)
|
||||
$searchableFields = [
|
||||
'name_zh', 'name_en', 'registration_number', 'legal_representative',
|
||||
'address', 'industry', 'industry_subdivision', 'website',
|
||||
'source_channel', 'source_detail', 'business_scope', 'stock_code',
|
||||
];
|
||||
|
||||
$where = ['is_active = 1'];
|
||||
$params = [];
|
||||
if ($active !== null) {
|
||||
$where = [];
|
||||
$params = [];
|
||||
$where[] = 'is_active = ?';
|
||||
$params[] = $active;
|
||||
$where = ['is_active = ?'];
|
||||
$params = [$active];
|
||||
}
|
||||
if ($keyword !== '') {
|
||||
$where[] = '(display_name LIKE ? OR name_zh LIKE ? OR name_en LIKE ? OR registration_number LIKE ?)';
|
||||
$like = "%$keyword%";
|
||||
array_push($params, $like, $like, $like, $like);
|
||||
if ($field !== '' && in_array($field, $searchableFields, true)) {
|
||||
$where[] = "$field LIKE ?";
|
||||
$params[] = "%$keyword%";
|
||||
} else {
|
||||
// 全部字段:匹配常用字段
|
||||
$where[] = '(name_zh LIKE ? OR name_en LIKE ? OR display_name LIKE ? OR registration_number LIKE ? OR legal_representative LIKE ? OR industry LIKE ? OR industry_subdivision LIKE ? OR website LIKE ? OR source_detail LIKE ? OR stock_code LIKE ?)';
|
||||
$like = "%$keyword%";
|
||||
array_push($params, $like, $like, $like, $like, $like, $like, $like, $like, $like, $like);
|
||||
}
|
||||
}
|
||||
if ($industry !== '') {
|
||||
$where[] = 'industry = ?';
|
||||
$params[] = $industry;
|
||||
}
|
||||
if ($role !== '') {
|
||||
$where[] = 'business_role = ?';
|
||||
$params[] = $role;
|
||||
}
|
||||
if ($country !== '') {
|
||||
$where[] = 'country = ?';
|
||||
$params[] = $country;
|
||||
if ($companyType !== '') {
|
||||
$where[] = 'legal_form = ?';
|
||||
$params[] = $companyType;
|
||||
}
|
||||
$whereSql = implode(' AND ', $where);
|
||||
|
||||
@@ -52,7 +63,7 @@ $total = (int)$stmt->fetchColumn();
|
||||
|
||||
$offset = ($page - 1) * $limit;
|
||||
$stmt = $pdo->prepare(
|
||||
"SELECT id, name_zh, name_en, display_name, business_role, country, registration_number,
|
||||
"SELECT id, name_zh, name_en, display_name, business_role, legal_form, country, registration_number,
|
||||
address, legal_representative, industry, industry_subdivision, website,
|
||||
latest_employee_count, latest_annual_revenue, is_listed, stock_code,
|
||||
source_channel, source_detail, is_active, created_at, updated_at
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* 企业官媒新增接口 POST /api/company/official_media_add.php
|
||||
* 为指定公司快速新增一条官媒记录(social_accounts owner_type=company)
|
||||
* 入参:company_id(必填)/ platform(平台)/ account_id(账号名称)/ profile_url(主页链接)/
|
||||
* remark / is_active(1启用 0停用)/ is_defult(1常用)
|
||||
*/
|
||||
require_once __DIR__ . '/../common/db.php';
|
||||
require_once __DIR__ . '/../common/response.php';
|
||||
require_once __DIR__ . '/../common/auth.php';
|
||||
require_once __DIR__ . '/../common/helpers.php';
|
||||
require_once __DIR__ . '/../common/logger.php';
|
||||
|
||||
checkAjax();
|
||||
checkPermission('company');
|
||||
|
||||
$companyId = (int)($_POST['company_id'] ?? 0);
|
||||
$platform = trim($_POST['platform'] ?? '');
|
||||
$accountId = trim($_POST['account_id'] ?? '');
|
||||
if ($companyId <= 0 || $platform === '' || $accountId === '') {
|
||||
Response::error('平台与账号名称为必填项', 400);
|
||||
}
|
||||
|
||||
$pdo = DB::getInstance()->getPdo();
|
||||
|
||||
$chk = $pdo->prepare("SELECT COUNT(*) FROM companies WHERE id = ?");
|
||||
$chk->execute([$companyId]);
|
||||
if ((int)$chk->fetchColumn() === 0) {
|
||||
Response::error('企业不存在');
|
||||
}
|
||||
|
||||
$ins = $pdo->prepare(
|
||||
"INSERT INTO social_accounts (owner_type, owner_id, platform, account_id, profile_url, remark, is_primary, is_defult, is_active)
|
||||
VALUES ('company', ?, ?, ?, ?, ?, 0, ?, ?)"
|
||||
);
|
||||
$ins->execute([
|
||||
$companyId,
|
||||
$platform,
|
||||
$accountId,
|
||||
strOrNull($_POST['profile_url'] ?? null),
|
||||
strOrNull($_POST['remark'] ?? null),
|
||||
!empty($_POST['is_defult']) ? 1 : 0,
|
||||
isset($_POST['is_active']) && (int)$_POST['is_active'] === 0 ? 0 : 1,
|
||||
]);
|
||||
$newId = (int)$pdo->lastInsertId();
|
||||
|
||||
logCurrent('add', 'official_media', 'social_accounts', $newId, ['company_id' => $companyId, 'platform' => $platform, 'account_id' => $accountId]);
|
||||
Response::success(['id' => $newId], '新增成功');
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* 企业官媒列表接口 GET /api/company/official_media_list.php
|
||||
* 归属该公司的媒体清单(social_accounts owner_type=company)
|
||||
* 字段:平台/账号名称/ID/主页链接/状态/更新日期
|
||||
* 入参:company_id(必填)/ page / limit
|
||||
*/
|
||||
require_once __DIR__ . '/../common/db.php';
|
||||
require_once __DIR__ . '/../common/response.php';
|
||||
require_once __DIR__ . '/../common/auth.php';
|
||||
|
||||
checkPermission('company');
|
||||
|
||||
$companyId = (int)($_REQUEST['company_id'] ?? 0);
|
||||
if ($companyId <= 0) {
|
||||
Response::error('参数错误', 400);
|
||||
}
|
||||
|
||||
[$page, $limit] = pageParams(5);
|
||||
|
||||
$pdo = DB::getInstance()->getPdo();
|
||||
|
||||
$chk = $pdo->prepare("SELECT COUNT(*) FROM companies WHERE id = ?");
|
||||
$chk->execute([$companyId]);
|
||||
if ((int)$chk->fetchColumn() === 0) {
|
||||
Response::error('企业不存在');
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare("SELECT COUNT(*) FROM social_accounts WHERE owner_type = 'company' AND owner_id = ? AND is_active = 1");
|
||||
$stmt->execute([$companyId]);
|
||||
$total = (int)$stmt->fetchColumn();
|
||||
|
||||
$offset = ($page - 1) * $limit;
|
||||
$stmt = $pdo->prepare(
|
||||
"SELECT id, platform, account_id, profile_url, remark, is_defult, is_active, created_at
|
||||
FROM social_accounts
|
||||
WHERE owner_type = 'company' AND owner_id = ? AND is_active = 1
|
||||
ORDER BY is_defult DESC, id DESC
|
||||
LIMIT $limit OFFSET $offset"
|
||||
);
|
||||
$stmt->execute([$companyId]);
|
||||
|
||||
Response::success(['list' => $stmt->fetchAll(), 'total' => $total, 'page' => $page, 'limit' => $limit]);
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* 企业产品新增接口 POST /api/company/product_add.php
|
||||
* 入参:company_id(必填)/ category_name(产品品类)/ positioning(产品基本定位)/ series(包含系列)/
|
||||
* is_active(1在产 0停产)/ attrs(可选 JSON:[{attr_id, value}],EAV 参数值)
|
||||
* 说明:attr_id 来自 company_products_attr(按企业所属行业定义的参数属性)
|
||||
*/
|
||||
require_once __DIR__ . '/../common/db.php';
|
||||
require_once __DIR__ . '/../common/response.php';
|
||||
require_once __DIR__ . '/../common/auth.php';
|
||||
require_once __DIR__ . '/../common/helpers.php';
|
||||
require_once __DIR__ . '/../common/logger.php';
|
||||
|
||||
checkAjax();
|
||||
checkPermission('company');
|
||||
|
||||
$companyId = (int)($_POST['company_id'] ?? 0);
|
||||
$categoryName = trim($_POST['category_name'] ?? '');
|
||||
if ($companyId <= 0 || $categoryName === '') {
|
||||
Response::error('产品品类(category_name)为必填项', 400);
|
||||
}
|
||||
|
||||
$pdo = DB::getInstance()->getPdo();
|
||||
|
||||
$chk = $pdo->prepare("SELECT id, industry FROM companies WHERE id = ?");
|
||||
$chk->execute([$companyId]);
|
||||
$company = $chk->fetch();
|
||||
if (!$company) {
|
||||
Response::error('企业不存在');
|
||||
}
|
||||
|
||||
$pdo->beginTransaction();
|
||||
try {
|
||||
$ins = $pdo->prepare(
|
||||
"INSERT INTO company_products (company_id, category_name, category_description, positioning, series, is_core, is_active)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)"
|
||||
);
|
||||
$ins->execute([
|
||||
$companyId,
|
||||
$categoryName,
|
||||
strOrNull($_POST['category_description'] ?? null),
|
||||
strOrNull($_POST['positioning'] ?? null),
|
||||
strOrNull($_POST['series'] ?? null),
|
||||
!empty($_POST['is_core']) ? 1 : 0,
|
||||
isset($_POST['is_active']) && (int)$_POST['is_active'] === 0 ? 0 : 1,
|
||||
]);
|
||||
$productId = (int)$pdo->lastInsertId();
|
||||
|
||||
// EAV 参数值
|
||||
$attrs = json_decode($_POST['attrs'] ?? '[]', true);
|
||||
if (is_array($attrs) && $attrs) {
|
||||
// 校验 attr 属于该公司行业
|
||||
$valid = $pdo->prepare("SELECT id, attr_type FROM company_products_attr WHERE id = ? AND industry = ? AND is_active = 1");
|
||||
$insV = $pdo->prepare(
|
||||
"INSERT INTO company_products_attr_value (product_id, attr_id, value_string, value_number, value_boolean, value_date)
|
||||
VALUES (?, ?, ?, ?, ?, ?)"
|
||||
);
|
||||
foreach ($attrs as $a) {
|
||||
$attrId = (int)($a['attr_id'] ?? 0);
|
||||
if ($attrId <= 0) {
|
||||
continue;
|
||||
}
|
||||
$valid->execute([$attrId, $company['industry']]);
|
||||
$def = $valid->fetch();
|
||||
if (!$def) {
|
||||
continue;
|
||||
}
|
||||
$val = trim((string)($a['value'] ?? ''));
|
||||
if ($val === '') {
|
||||
continue;
|
||||
}
|
||||
$vStr = $vNum = $vBool = $vDate = null;
|
||||
switch ($def['attr_type']) {
|
||||
case 'number':
|
||||
$vNum = is_numeric($val) ? $val : null;
|
||||
if ($vNum === null) {
|
||||
$vStr = $val;
|
||||
}
|
||||
break;
|
||||
case 'boolean':
|
||||
$vBool = (in_array($val, ['1', 'true', '是', 'yes', 'Y', 'y', '支持'], true)) ? 1 : 0;
|
||||
break;
|
||||
case 'date':
|
||||
$vDate = (strtotime($val) !== false) ? date('Y-m-d', strtotime($val)) : null;
|
||||
if ($vDate === null) {
|
||||
$vStr = $val;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$vStr = $val;
|
||||
}
|
||||
$insV->execute([$productId, $attrId, $vStr, $vNum, $vBool, $vDate]);
|
||||
}
|
||||
}
|
||||
|
||||
$pdo->commit();
|
||||
} catch (Exception $e) {
|
||||
$pdo->rollBack();
|
||||
Response::error('产品保存失败:' . $e->getMessage());
|
||||
}
|
||||
|
||||
logCurrent('add', 'product', 'company_products', $productId, ['company_id' => $companyId, 'category_name' => $categoryName]);
|
||||
Response::success(['id' => $productId], '新增成功');
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* 产品参数属性定义接口 GET /api/company/product_attrs.php?industry=汽车制造
|
||||
* 返回指定行业的参数属性定义(EAV),供新增产品弹窗动态生成参数输入项
|
||||
*/
|
||||
require_once __DIR__ . '/../common/db.php';
|
||||
require_once __DIR__ . '/../common/response.php';
|
||||
require_once __DIR__ . '/../common/auth.php';
|
||||
|
||||
checkPermission('company');
|
||||
|
||||
$industry = trim($_REQUEST['industry'] ?? '');
|
||||
if ($industry === '') {
|
||||
Response::error('参数错误', 400);
|
||||
}
|
||||
|
||||
$pdo = DB::getInstance()->getPdo();
|
||||
$attrs = $pdo->prepare(
|
||||
"SELECT id, attr_name, attr_type, unit FROM company_products_attr
|
||||
WHERE industry = ? AND is_active = 1 ORDER BY sort_order, id"
|
||||
);
|
||||
$attrs->execute([$industry]);
|
||||
|
||||
Response::success(['attrs' => $attrs->fetchAll()]);
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* 企业产品品类列表接口 GET /api/company/products.php
|
||||
* 企业产品列表接口 GET /api/company/products.php
|
||||
* v1.0.18:返回产品基础字段(产品品类/基本定位/包含系列/状态/更新日期)+ EAV 参数值(JSON)
|
||||
* 入参:company_id(必填)/ page / limit
|
||||
*/
|
||||
require_once __DIR__ . '/../common/db.php';
|
||||
@@ -30,12 +31,43 @@ $total = (int)$stmt->fetchColumn();
|
||||
|
||||
$offset = ($page - 1) * $limit;
|
||||
$stmt = $pdo->prepare(
|
||||
"SELECT id, category_name, category_description, is_core, is_active
|
||||
"SELECT id, category_name, category_description, positioning, series, is_core, is_active, created_at, updated_at
|
||||
FROM company_products
|
||||
WHERE company_id = ? AND is_active = 1
|
||||
ORDER BY is_core DESC, id DESC
|
||||
LIMIT $limit OFFSET $offset"
|
||||
);
|
||||
$stmt->execute([$companyId]);
|
||||
$list = $stmt->fetchAll();
|
||||
|
||||
Response::success(['list' => $stmt->fetchAll(), 'total' => $total, 'page' => $page, 'limit' => $limit]);
|
||||
// 批量取 EAV 参数值(每个产品一个 JSON:attr_id => 值)
|
||||
if ($list) {
|
||||
$ids = array_column($list, 'id');
|
||||
$in = implode(',', array_fill(0, count($ids), '?'));
|
||||
$valStmt = $pdo->prepare(
|
||||
"SELECT v.product_id, a.attr_name, a.attr_type, a.unit,
|
||||
v.value_string, v.value_number, v.value_boolean, v.value_date
|
||||
FROM company_products_attr_value v
|
||||
INNER JOIN company_products_attr a ON a.id = v.attr_id
|
||||
WHERE v.product_id IN ($in)"
|
||||
);
|
||||
$valStmt->execute($ids);
|
||||
$values = [];
|
||||
foreach ($valStmt as $v) {
|
||||
$values[$v['product_id']][] = [
|
||||
'attr_name' => $v['attr_name'],
|
||||
'attr_type' => $v['attr_type'],
|
||||
'unit' => $v['unit'],
|
||||
'value' => $v['value_string'] !== null ? $v['value_string']
|
||||
: ($v['value_number'] !== null ? rtrim(rtrim(sprintf('%.4f', $v['value_number']), '0'), '.')
|
||||
: ($v['value_boolean'] !== null ? ($v['value_boolean'] ? '是' : '否')
|
||||
: ($v['value_date'] ?? ''))),
|
||||
];
|
||||
}
|
||||
foreach ($list as &$row) {
|
||||
$row['attrs'] = $values[$row['id']] ?? [];
|
||||
}
|
||||
unset($row);
|
||||
}
|
||||
|
||||
Response::success(['list' => $list, 'total' => $total, 'page' => $page, 'limit' => $limit]);
|
||||
|
||||
+12
-3
@@ -21,7 +21,8 @@ $data = extractFields(COMPANY_FIELDS);
|
||||
unset($data['display_name']); // 显示名称不允许通过编辑接口置空/改名,如需改名请走完整字段
|
||||
$hasFinancials = array_key_exists('financials', $_POST);
|
||||
$hasCertifications = array_key_exists('certifications', $_POST);
|
||||
if (empty($data) && !$hasFinancials && !$hasCertifications) {
|
||||
$hasAccounts = array_key_exists('accounts', $_POST);
|
||||
if (empty($data) && !$hasFinancials && !$hasCertifications && !$hasAccounts) {
|
||||
Response::error('没有需要更新的字段', 400);
|
||||
}
|
||||
|
||||
@@ -40,8 +41,8 @@ if (!empty($data)) {
|
||||
$pdo->prepare("UPDATE companies SET $sets WHERE id = ?")->execute($params);
|
||||
}
|
||||
|
||||
// 财务信息 / 资质认证(可选,整表替换)
|
||||
if ($hasFinancials || $hasCertifications) {
|
||||
// 财务信息 / 资质认证 / 联系方式(可选,整表替换)
|
||||
if ($hasFinancials || $hasCertifications || $hasAccounts) {
|
||||
$pdo->beginTransaction();
|
||||
try {
|
||||
if ($hasFinancials) {
|
||||
@@ -60,6 +61,14 @@ if ($hasFinancials || $hasCertifications) {
|
||||
}
|
||||
saveCompanyCertifications($pdo, $id, $certs);
|
||||
}
|
||||
if ($hasAccounts) {
|
||||
$accounts = json_decode($_POST['accounts'], true);
|
||||
if (!is_array($accounts)) {
|
||||
$pdo->rollBack();
|
||||
Response::error('联系方式格式错误', 400);
|
||||
}
|
||||
saveCompanyAccounts($pdo, $id, $accounts);
|
||||
}
|
||||
$pdo->commit();
|
||||
} catch (Exception $e) {
|
||||
$pdo->rollBack();
|
||||
|
||||
@@ -49,5 +49,11 @@ if (is_array($contacts)) {
|
||||
}
|
||||
}
|
||||
|
||||
// 工作履历(v1.0.18:整表替换)
|
||||
$experiences = json_decode($_POST['experiences'] ?? '[]', true);
|
||||
if (is_array($experiences)) {
|
||||
savePersonExperiences($pdo, $newId, $experiences);
|
||||
}
|
||||
|
||||
logCurrent('add', 'person', 'persons', $newId, ['data' => $data, 'contacts' => $contacts]);
|
||||
Response::success(['id' => $newId], '新增成功');
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* 任职公司选项接口 GET /api/person/company_options.php
|
||||
* 返回启用中的企业(id + 显示名称),供人员「工作履历」行内公司下拉使用
|
||||
* 入参:keyword(可选,模糊匹配企业名称)/ limit(默认 500)
|
||||
*/
|
||||
require_once __DIR__ . '/../common/db.php';
|
||||
require_once __DIR__ . '/../common/response.php';
|
||||
require_once __DIR__ . '/../common/auth.php';
|
||||
|
||||
checkPermission('person');
|
||||
|
||||
$keyword = trim($_REQUEST['keyword'] ?? '');
|
||||
$limit = min(1000, max(1, (int)($_REQUEST['limit'] ?? 500)));
|
||||
|
||||
$pdo = DB::getInstance()->getPdo();
|
||||
|
||||
$where = 'is_active = 1';
|
||||
$params = [];
|
||||
if ($keyword !== '') {
|
||||
$where .= ' AND (name_zh LIKE ? OR name_en LIKE ? OR display_name LIKE ?)';
|
||||
$like = "%$keyword%";
|
||||
array_push($params, $like, $like, $like);
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare(
|
||||
"SELECT id, COALESCE(NULLIF(display_name,''), name_zh, name_en) AS name
|
||||
FROM companies WHERE $where ORDER BY id ASC LIMIT $limit"
|
||||
);
|
||||
$stmt->execute($params);
|
||||
|
||||
Response::success(['list' => $stmt->fetchAll()]);
|
||||
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
/**
|
||||
* 人员人脉接口 GET /api/person/connections.php?person_id=X
|
||||
* 列出与该人员相关的其他人员(交集:工作履历/家乡/毕业院校)
|
||||
* - 同事:在 person_work_experiences 中任职过同一家公司
|
||||
* - 老乡:家乡市级一致(如 湖南衡阳 vs 湖南衡阳;仅为湖南省不算)
|
||||
* - 校友:毕业院校相同
|
||||
* 亲密度(百分比):
|
||||
* 老乡/校友/同事 各 +20;同一家公司任职次数≥2 +10;同事且入职年份一致 +10;
|
||||
* 工作地点一致 +10;性别一致(均为男或均为女)+5;剩余 0~5 随机;
|
||||
* 任何两人亲密度不得超过 99%(不能达到 100%)
|
||||
* 入参:person_id(必填)/ limit(默认 50)
|
||||
* 返回:{ list: [{id, full_name, phone, tags:[老乡,校友,同事], intimacy}] }
|
||||
*/
|
||||
require_once __DIR__ . '/../common/db.php';
|
||||
require_once __DIR__ . '/../common/response.php';
|
||||
require_once __DIR__ . '/../common/auth.php';
|
||||
|
||||
checkPermission('person');
|
||||
|
||||
$personId = (int)($_REQUEST['person_id'] ?? 0);
|
||||
if ($personId <= 0) {
|
||||
Response::error('参数错误', 400);
|
||||
}
|
||||
$limit = (int)($_REQUEST['limit'] ?? 50);
|
||||
if ($limit <= 0 || $limit > 200) {
|
||||
$limit = 50;
|
||||
}
|
||||
|
||||
$pdo = DB::getInstance()->getPdo();
|
||||
|
||||
$stmt = $pdo->prepare("SELECT id, full_name, hometown, graduated_from, gender, work_location FROM persons WHERE id = ?");
|
||||
$stmt->execute([$personId]);
|
||||
$target = $stmt->fetch();
|
||||
if (!$target) {
|
||||
Response::error('人员不存在');
|
||||
}
|
||||
|
||||
/** 省-市名称归一化:湖南省衡阳市 -> 湖南衡阳;新疆维吾尔自治区乌鲁木齐市 -> 新疆乌鲁木齐;北京市 -> 北京 */
|
||||
function normalizeAreaName($s)
|
||||
{
|
||||
$s = trim((string)$s);
|
||||
if ($s === '') {
|
||||
return '';
|
||||
}
|
||||
$muni = ['北京市' => '北京', '天津市' => '天津', '上海市' => '上海', '重庆市' => '重庆'];
|
||||
if (isset($muni[$s])) {
|
||||
return $muni[$s];
|
||||
}
|
||||
// 自治区后缀(维吾尔/壮族/回族)及省后缀
|
||||
$s = preg_replace('/(维吾尔|壮族|回族)?自治区$/', '', $s);
|
||||
$s = str_replace('省', '', $s);
|
||||
// 去掉末尾「市」
|
||||
$s = preg_replace('/市$/', '', $s);
|
||||
$s = str_replace('特别行政区', '', $s);
|
||||
return $s;
|
||||
}
|
||||
|
||||
$tHometown = normalizeAreaName($target['hometown']);
|
||||
$tWorkLoc = normalizeAreaName($target['work_location']);
|
||||
$tSchool = trim((string)$target['graduated_from']);
|
||||
$tGender = $target['gender'];
|
||||
$isGenderPair = ($tGender === '男' || $tGender === '女');
|
||||
|
||||
// 目标人员的任职公司集合:company_id => 入职年份
|
||||
$expMap = []; // person_id => [ ['company_id'=>x,'sy'=>yyyy|null], ... ]
|
||||
$targetComps = []; // company_id => sy
|
||||
$stmt = $pdo->prepare(
|
||||
"SELECT person_id, company_id, YEAR(start_date) AS sy
|
||||
FROM person_work_experiences WHERE is_active = 1 AND person_id != ?"
|
||||
);
|
||||
$stmt->execute([$personId]);
|
||||
$candIds = [];
|
||||
foreach ($stmt as $row) {
|
||||
$pid = (int)$row['person_id'];
|
||||
$expMap[$pid][] = ['company_id' => (int)$row['company_id'], 'sy' => $row['sy'] !== null ? (int)$row['sy'] : null];
|
||||
$candIds[$pid] = true;
|
||||
}
|
||||
$stmt = $pdo->prepare(
|
||||
"SELECT company_id, YEAR(start_date) AS sy
|
||||
FROM person_work_experiences WHERE is_active = 1 AND person_id = ?"
|
||||
);
|
||||
$stmt->execute([$personId]);
|
||||
foreach ($stmt as $row) {
|
||||
$targetComps[(int)$row['company_id']] = $row['sy'] !== null ? (int)$row['sy'] : null;
|
||||
}
|
||||
|
||||
// 候选人员基本信息
|
||||
$candList = $pdo->query(
|
||||
"SELECT id, full_name, hometown, graduated_from, gender, work_location FROM persons WHERE id != $personId AND is_active = 1"
|
||||
)->fetchAll();
|
||||
|
||||
// 手机号(常用优先)
|
||||
$phones = [];
|
||||
foreach ($pdo->query(
|
||||
"SELECT owner_id, account_id FROM social_accounts
|
||||
WHERE owner_type = 'person' AND platform = 'phone' AND is_active = 1
|
||||
ORDER BY is_defult DESC, is_primary DESC, id DESC"
|
||||
) as $row) {
|
||||
if (!isset($phones[$row['owner_id']])) {
|
||||
$phones[$row['owner_id']] = $row['account_id'];
|
||||
}
|
||||
}
|
||||
|
||||
$result = [];
|
||||
foreach ($candList as $c) {
|
||||
$tags = [];
|
||||
$score = 0;
|
||||
|
||||
// 老乡:市级一致(归一化后整体相等即省市都一致)
|
||||
$cHometown = normalizeAreaName($c['hometown']);
|
||||
if ($tHometown !== '' && $cHometown !== '' && $tHometown === $cHometown) {
|
||||
$tags[] = '老乡';
|
||||
$score += 20;
|
||||
}
|
||||
|
||||
// 校友
|
||||
$cSchool = trim((string)$c['graduated_from']);
|
||||
if ($tSchool !== '' && $cSchool !== '' && $tSchool === $cSchool) {
|
||||
$tags[] = '校友';
|
||||
$score += 20;
|
||||
}
|
||||
|
||||
// 同事:任职公司交集
|
||||
$shared = []; // company_id => [targetSy, candSy]
|
||||
foreach (($expMap[$c['id']] ?? []) as $e) {
|
||||
if (isset($targetComps[$e['company_id']])) {
|
||||
$shared[$e['company_id']] = [$targetComps[$e['company_id']], $e['sy']];
|
||||
}
|
||||
}
|
||||
if ($shared) {
|
||||
$tags[] = '同事';
|
||||
$score += 20;
|
||||
// 同一家公司任职次数≥2(两家及以上共同任职公司)
|
||||
if (count($shared) >= 2) {
|
||||
$score += 10;
|
||||
}
|
||||
// 同事且入职年份一致
|
||||
foreach ($shared as $pair) {
|
||||
if ($pair[0] !== null && $pair[1] !== null && $pair[0] === $pair[1]) {
|
||||
$score += 10;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 工作地点一致
|
||||
$cWorkLoc = normalizeAreaName($c['work_location']);
|
||||
if ($tWorkLoc !== '' && $cWorkLoc !== '' && $tWorkLoc === $cWorkLoc) {
|
||||
$score += 10;
|
||||
}
|
||||
|
||||
// 性别一致(均为男或均为女)
|
||||
if ($isGenderPair && ($c['gender'] === '男' || $c['gender'] === '女') && $c['gender'] === $tGender) {
|
||||
$score += 5;
|
||||
}
|
||||
|
||||
// 至少有一种交集才进入人脉
|
||||
if (!$tags) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 随机 0~5(剩余百分比),总亲密上限 99(不能达到 100%)
|
||||
$score += mt_rand(0, 5);
|
||||
$score = min(99, $score);
|
||||
|
||||
$result[] = [
|
||||
'id' => (int)$c['id'],
|
||||
'full_name' => $c['full_name'],
|
||||
'phone' => $phones[$c['id']] ?? '',
|
||||
'tags' => $tags,
|
||||
'intimacy' => $score,
|
||||
];
|
||||
}
|
||||
|
||||
// 亲密度降序,其次按 id 升序
|
||||
usort($result, function ($a, $b) {
|
||||
if ($b['intimacy'] !== $a['intimacy']) {
|
||||
return $b['intimacy'] - $a['intimacy'];
|
||||
}
|
||||
return $a['id'] - $b['id'];
|
||||
});
|
||||
|
||||
$result = array_slice($result, 0, $limit);
|
||||
Response::success(['list' => $result]);
|
||||
@@ -54,5 +54,14 @@ if (!empty($data)) {
|
||||
$pdo->prepare("UPDATE persons SET $sets WHERE id = ?")->execute($params);
|
||||
}
|
||||
|
||||
// 工作履历(v1.0.18:可选,整表替换)
|
||||
if (array_key_exists('experiences', $_POST)) {
|
||||
$experiences = json_decode($_POST['experiences'], true);
|
||||
if (!is_array($experiences)) {
|
||||
Response::error('工作履历格式错误', 400);
|
||||
}
|
||||
savePersonExperiences($pdo, $id, $experiences);
|
||||
}
|
||||
|
||||
logCurrent('update', 'person', 'persons', $id, ['before' => $old, 'after' => $data, 'contacts_replaced' => $contactsChanged]);
|
||||
Response::success(null, '更新成功');
|
||||
|
||||
Reference in New Issue
Block a user