Files
superlink/api/fragment/hard_common.php
T

57 lines
2.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* 硬碎片公共逻辑:字段分层 / 完整度计算 / 内容摘要
* 被 hard_list.php 与 hard_detail.php 共用
*/
/** 硬碎片字段分层(按 source_type) */
const HARD_LAYERS = [
'company' => ['core' => ['company_name', 'contact_phone'], 'important' => ['contact_email'], 'supplementary' => ['person_name', 'description', 'target_product_category']],
'person' => ['core' => ['person_name', 'contact_phone'], 'important' => ['contact_email'], 'supplementary' => ['company_name', 'description', 'target_product_category']],
'product' => ['core' => ['company_name', 'target_product_category'], 'important' => ['contact_phone', 'contact_email'], 'supplementary' => ['person_name', 'description']],
'need' => ['core' => ['company_name', 'target_product_category'], 'important' => ['contact_phone', 'contact_email'], 'supplementary' => ['person_name', 'description']],
'mixed' => ['core' => ['company_name', 'person_name'], 'important' => ['contact_phone', 'contact_email'], 'supplementary' => ['description', 'target_product_category']],
];
const HARD_LABELS = [
'company_name' => '公司名称', 'person_name' => '联系人', 'contact_phone' => '电话',
'contact_email' => '邮箱', 'target_product_category' => '产品品类', 'description' => '描述',
];
/** 计算硬碎片完整度与缺失层级 */
function hardCompleteness($row)
{
$layers = HARD_LAYERS[$row['source_type']] ?? HARD_LAYERS['mixed'];
$missing = ['core' => [], 'important' => [], 'supplementary' => []];
foreach (['core', 'important', 'supplementary'] as $layer) {
foreach ($layers[$layer] as $field) {
if ($row[$field] === null || trim((string)$row[$field]) === '') {
$missing[$layer][] = $field;
}
}
}
$score = 100 - count($missing['core']) * 20 - count($missing['important']) * 8 - count($missing['supplementary']) * 2;
$score = max(0, $score);
$level = 'complete';
if (!empty($missing['core'])) {
$level = 'core';
} elseif (!empty($missing['important'])) {
$level = 'important';
} elseif (!empty($missing['supplementary'])) {
$level = 'supplementary';
}
return ['score' => $score, 'level' => $level, 'missing' => $missing];
}
/** 内容摘要:拼接已有关键信息 */
function hardSummary($row)
{
$parts = [];
if (!empty($row['company_name'])) $parts[] = '公司:' . $row['company_name'];
if (!empty($row['person_name'])) $parts[] = '联系人:' . $row['person_name'];
if (!empty($row['contact_phone'])) $parts[] = '手机:' . $row['contact_phone'];
if (!empty($row['contact_email'])) $parts[] = '邮箱:' . $row['contact_email'];
if (!empty($row['target_product_category'])) $parts[] = '品类:' . $row['target_product_category'];
if (empty($parts) && !empty($row['description'])) $parts[] = '描述:' . mb_substr($row['description'], 0, 20);
return implode(' ', $parts);
}