90 lines
3.5 KiB
PHP
90 lines
3.5 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, is_core, is_active FROM company_products WHERE company_id = ? AND is_active = 1");
|
|
$products->execute([$id]);
|
|
|
|
$needs = $pdo->prepare("SELECT id, contact_person, need_category, target_product_category, application_scenario, description, is_valid, created_at FROM company_needs WHERE company_id = ? ORDER BY id DESC");
|
|
$needs->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.issue_date, cc.expiry_date
|
|
FROM company_certifications cc
|
|
INNER JOIN certification_types 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 certification_types WHERE is_active = 1 ORDER BY sort_order, id")->fetchAll();
|
|
|
|
// 关联联系人(工作经历 + 联系方式)
|
|
$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(),
|
|
'needs' => $needs->fetchAll(),
|
|
'documents' => $docs->fetchAll(),
|
|
'financials' => $financials->fetchAll(),
|
|
'relations' => $relations->fetchAll(),
|
|
'contacts' => $contacts->fetchAll(),
|
|
'certifications' => $certs->fetchAll(),
|
|
'certification_types' => $certTypes,
|
|
]);
|