v1.0.12: 企业/人员/媒体去删除入口;企业/人员加产品入口;企业详情去产品品类/关联联系人;编辑企业改Tab卡(工商信息/财务信息/资质认证)
This commit is contained in:
@@ -90,3 +90,115 @@ function buildUpdate($data)
|
||||
}
|
||||
return [implode(',', $sets), array_values($data)];
|
||||
}
|
||||
|
||||
/** 数字字符串或 null(空串转 null,避免写入空值) */
|
||||
function numOrNull($v)
|
||||
{
|
||||
$v = trim((string)$v);
|
||||
return ($v === '') ? null : $v;
|
||||
}
|
||||
|
||||
/** 字符串或 null(空串转 null) */
|
||||
function strOrNull($v)
|
||||
{
|
||||
if ($v === null) {
|
||||
return null;
|
||||
}
|
||||
$v = trim((string)$v);
|
||||
return ($v === '') ? null : $v;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存企业年度财务明细(整表替换:先删后插)
|
||||
* @param PDO $pdo
|
||||
* @param int $companyId
|
||||
* @param array $financials JSON 解码后的数组
|
||||
*/
|
||||
function saveCompanyFinancials($pdo, $companyId, $financials)
|
||||
{
|
||||
$del = $pdo->prepare("DELETE FROM company_financials WHERE company_id = ?");
|
||||
$del->execute([$companyId]);
|
||||
if (empty($financials)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$ins = $pdo->prepare(
|
||||
"INSERT INTO company_financials
|
||||
(company_id, fiscal_year, employee_count, total_revenue, net_profit, total_assets,
|
||||
total_liabilities, owner_equity, gross_margin, net_margin, debt_ratio, financial_report_url, data_source)
|
||||
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)"
|
||||
);
|
||||
$seen = [];
|
||||
foreach ($financials as $f) {
|
||||
if (!is_array($f)) {
|
||||
continue;
|
||||
}
|
||||
$year = (int)($f['fiscal_year'] ?? 0);
|
||||
if ($year < 1990 || $year > 2100) {
|
||||
continue;
|
||||
}
|
||||
if (isset($seen[$year])) {
|
||||
continue; // 同一财年只保留一条
|
||||
}
|
||||
$seen[$year] = true;
|
||||
$ins->execute([
|
||||
$companyId,
|
||||
$year,
|
||||
numOrNull($f['employee_count'] ?? null),
|
||||
numOrNull($f['total_revenue'] ?? null),
|
||||
numOrNull($f['net_profit'] ?? null),
|
||||
numOrNull($f['total_assets'] ?? null),
|
||||
numOrNull($f['total_liabilities'] ?? null),
|
||||
numOrNull($f['owner_equity'] ?? null),
|
||||
numOrNull($f['gross_margin'] ?? null),
|
||||
numOrNull($f['net_margin'] ?? null),
|
||||
numOrNull($f['debt_ratio'] ?? null),
|
||||
strOrNull($f['financial_report_url'] ?? null),
|
||||
strOrNull($f['data_source'] ?? null) ?? '手动录入',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存企业资质认证(整表替换:先删后插)
|
||||
* @param PDO $pdo
|
||||
* @param int $companyId
|
||||
* @param array $certifications JSON 解码后的数组
|
||||
*/
|
||||
function saveCompanyCertifications($pdo, $companyId, $certifications)
|
||||
{
|
||||
$del = $pdo->prepare("DELETE FROM company_certifications WHERE company_id = ?");
|
||||
$del->execute([$companyId]);
|
||||
if (empty($certifications)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$valid = $pdo->prepare("SELECT id FROM certification_types WHERE id = ?");
|
||||
$ins = $pdo->prepare(
|
||||
"INSERT INTO company_certifications
|
||||
(company_id, certification_type_id, certificate_number, issue_date, expiry_date)
|
||||
VALUES (?,?,?,?,?)"
|
||||
);
|
||||
$seen = [];
|
||||
foreach ($certifications as $ct) {
|
||||
if (!is_array($ct)) {
|
||||
continue;
|
||||
}
|
||||
$tid = (int)($ct['certification_type_id'] ?? 0);
|
||||
if ($tid <= 0 || isset($seen[$tid])) {
|
||||
continue;
|
||||
}
|
||||
$valid->execute([$tid]);
|
||||
if (!$valid->fetch()) {
|
||||
continue; // 认证类型不存在
|
||||
}
|
||||
$seen[$tid] = true;
|
||||
$ins->execute([
|
||||
$companyId,
|
||||
$tid,
|
||||
strOrNull($ct['certificate_number'] ?? null),
|
||||
strOrNull($ct['issue_date'] ?? null),
|
||||
strOrNull($ct['expiry_date'] ?? null),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user