v1.0.19: 修复人员编辑入口缺失(person.js addPerson/editPerson) + 渠道明细数量字段名(analysis.php cnt) + CDP全量验证43项PASS

This commit is contained in:
nanguaboss
2026-08-08 19:29:14 +08:00
parent 2cb688ed46
commit 1c8b374a72
40 changed files with 2313 additions and 658 deletions
+10 -2
View File
@@ -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 -2
View File
@@ -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]);
+5 -5
View File
@@ -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
View File
@@ -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
+48
View File
@@ -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], '新增成功');
+43
View File
@@ -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]);
+103
View File
@@ -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], '新增成功');
+24
View File
@@ -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()]);
+35 -3
View File
@@ -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
View File
@@ -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();