ts
This commit is contained in:
@@ -91,18 +91,35 @@ class FbFileImportService
|
|||||||
case 'is_organic':
|
case 'is_organic':
|
||||||
$item['is_organic'] = $this->normalizeIsOrganic($raw);
|
$item['is_organic'] = $this->normalizeIsOrganic($raw);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'fb_created_time':
|
case 'fb_created_time':
|
||||||
// ✅ 方案B:写入 DATETIME 字符串
|
$item['fb_created_time'] = $this->normalizeCreatedTime($raw); // 你方案B的datetime
|
||||||
$item['fb_created_time'] = $this->normalizeCreatedTime($raw);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// ✅ 这些是数值ID字段:可能出现 ag:/as:/c:/f:/l: 前缀
|
||||||
|
case 'ad_id':
|
||||||
|
case 'adset_id':
|
||||||
|
case 'campaign_id':
|
||||||
|
case 'form_id':
|
||||||
|
$item[$field] = $this->normalizeNumericId($raw);
|
||||||
|
break;
|
||||||
|
|
||||||
|
// ✅ lead id 也经常是 l:xxxx
|
||||||
|
case 'fb_lead_id':
|
||||||
|
$item['fb_lead_id'] = $this->normalizeNumericId($raw);
|
||||||
|
break;
|
||||||
|
|
||||||
|
// ✅ 电话可能是 p:+233xxxx
|
||||||
|
case 'phone':
|
||||||
|
$item['phone'] = $this->normalizePhone($raw);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// 小增强:字符串统一 trim(避免 " xxx ")
|
if (is_string($raw)) $raw = trim($raw);
|
||||||
if (is_string($raw)) {
|
|
||||||
$raw = trim($raw);
|
|
||||||
}
|
|
||||||
$item[$field] = $raw;
|
$item[$field] = $raw;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 未知列收集到 extra_data(宽松模式)
|
// 未知列收集到 extra_data(宽松模式)
|
||||||
@@ -131,6 +148,51 @@ class FbFileImportService
|
|||||||
return count($insertData);
|
return count($insertData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 把 "ag:120..." / "l:831..." / "120..." 这种值清洗成纯数字(int 或 string数字)
|
||||||
|
* - 如果你的 DB 字段是 BIGINT UNSIGNED,PHP int 在 64 位环境下是够用的
|
||||||
|
* - 解析失败返回 0(避免 insert 失败)
|
||||||
|
*/
|
||||||
|
protected function normalizeNumericId($raw)
|
||||||
|
{
|
||||||
|
if ($raw === null || $raw === '') return 0;
|
||||||
|
|
||||||
|
// 数字直接返回
|
||||||
|
if (is_int($raw)) return $raw;
|
||||||
|
if (is_float($raw)) return (int)$raw;
|
||||||
|
|
||||||
|
$s = trim((string)$raw);
|
||||||
|
if ($s === '') return 0;
|
||||||
|
|
||||||
|
// 取出所有数字拼成一段(ag:120... -> 120..., l:xxx -> xxx)
|
||||||
|
$digits = preg_replace('/\D+/', '', $s);
|
||||||
|
if ($digits === '') return 0;
|
||||||
|
|
||||||
|
// 这里返回字符串数字也可以,MySQL 会转;返回 int 在 64 位一般没问题
|
||||||
|
// 若你担心超出 int,可直接 return $digits;
|
||||||
|
return $digits;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 电话清洗:去掉 "p:" 前缀,保留 + 和数字
|
||||||
|
*/
|
||||||
|
protected function normalizePhone($raw): string
|
||||||
|
{
|
||||||
|
if ($raw === null) return '';
|
||||||
|
|
||||||
|
$s = trim((string)$raw);
|
||||||
|
if ($s === '') return '';
|
||||||
|
|
||||||
|
// 去掉类似 "p:" "tel:" 等前缀
|
||||||
|
$s = preg_replace('/^[a-zA-Z]+:\s*/', '', $s);
|
||||||
|
|
||||||
|
// 保留 + 和数字
|
||||||
|
$s = preg_replace('/[^\d\+]+/', '', $s);
|
||||||
|
|
||||||
|
return $s;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 规范化 is_organic 字段为 0/1
|
* 规范化 is_organic 字段为 0/1
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user