96 lines
3.7 KiB
PHP
96 lines
3.7 KiB
PHP
<?php
|
|
/**
|
|
* 企业详情接口 GET /api/company/detail.php?id=1
|
|
* 返回企业主表信息 + 关联数据(产品品类/文档/财务/资质/联系方式)
|
|
*/
|
|
require_once __DIR__ . '/../common/db.php';
|
|
require_once __DIR__ . '/../common/response.php';
|
|
require_once __DIR__ . '/../common/auth.php';
|
|
|
|
checkPermission('company');
|
|
|
|
$id = (int)($_REQUEST['id'] ?? 0);
|
|
if ($id <= 0) {
|
|
Response::error('参数错误', 400);
|
|
}
|
|
|
|
$pdo = DB::getInstance()->getPdo();
|
|
|
|
$stmt = $pdo->prepare("SELECT * FROM companies WHERE id = ?");
|
|
$stmt->execute([$id]);
|
|
$company = $stmt->fetch();
|
|
if (!$company) {
|
|
Response::error('企业不存在');
|
|
}
|
|
|
|
$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(
|
|
"SELECT cd.id, cd.doc_name, cd.storage_path, cd.file_type, cd.publish_date, cd.is_active
|
|
FROM company_documents cd
|
|
INNER JOIN document_links dl ON dl.document_id = cd.id
|
|
WHERE dl.owner_type = 'company' AND dl.owner_id = ? AND cd.is_active = 1"
|
|
);
|
|
$docs->execute([$id]);
|
|
|
|
$financials = $pdo->prepare("SELECT * FROM company_financials WHERE company_id = ? ORDER BY fiscal_year DESC");
|
|
$financials->execute([$id]);
|
|
|
|
$relations = $pdo->prepare(
|
|
"SELECT cr.id, cr.relation_type, cr.is_direct, cr.ownership_percentage, cr.established_date, c.display_name AS child_name
|
|
FROM company_relations cr
|
|
LEFT JOIN companies c ON c.id = cr.child_company_id
|
|
WHERE cr.parent_company_id = ?"
|
|
);
|
|
$relations->execute([$id]);
|
|
|
|
// 资质认证(瞪羚企业等,JOIN 字典表取名称;含级别/颁证机构)
|
|
$certs = $pdo->prepare(
|
|
"SELECT cc.certification_type_id, ct.name AS certification_name, cc.certificate_number,
|
|
cc.level, cc.issuing_authority, cc.issue_date, cc.expiry_date
|
|
FROM company_certifications cc
|
|
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 data_dict_certificate WHERE is_active = 1 ORDER BY sort_order, id")->fetchAll();
|
|
|
|
// 联系方式:social_accounts 中属于该公司的记录(仅展示,无修改/删除入口)
|
|
$accounts = $pdo->prepare(
|
|
"SELECT id, platform, account_id, profile_url, remark, is_primary, is_defult, is_active, created_at
|
|
FROM social_accounts
|
|
WHERE owner_type = 'company' AND owner_id = ?
|
|
ORDER BY is_defult DESC, is_primary DESC, id DESC"
|
|
);
|
|
$accounts->execute([$id]);
|
|
|
|
// 关联联系人(工作经历 + 联系方式)
|
|
$contacts = $pdo->prepare(
|
|
"SELECT p.id, p.full_name,
|
|
(SELECT GROUP_CONCAT(CONCAT_WS(' ', pwe2.position, pwe2.department) SEPARATOR ' / ')
|
|
FROM person_work_experiences pwe2
|
|
WHERE pwe2.company_id = ? AND pwe2.person_id = p.id AND pwe2.is_active = 1) AS position,
|
|
(SELECT GROUP_CONCAT(CONCAT(sa.platform, ':', sa.account_id) SEPARATOR ' | ')
|
|
FROM social_accounts sa WHERE sa.owner_type = 'person' AND sa.owner_id = p.id AND sa.is_active = 1) AS contacts
|
|
FROM person_work_experiences pwe
|
|
LEFT JOIN persons p ON p.id = pwe.person_id
|
|
WHERE pwe.company_id = ? AND pwe.is_active = 1
|
|
GROUP BY p.id, p.full_name"
|
|
);
|
|
$contacts->execute([$id, $id]);
|
|
|
|
Response::success([
|
|
'company' => $company,
|
|
'products' => $products->fetchAll(),
|
|
'documents' => $docs->fetchAll(),
|
|
'financials' => $financials->fetchAll(),
|
|
'relations' => $relations->fetchAll(),
|
|
'contacts' => $contacts->fetchAll(),
|
|
'accounts' => $accounts->fetchAll(),
|
|
'certifications' => $certs->fetchAll(),
|
|
'certification_types' => $certTypes,
|
|
]);
|