v1.0.47: 新增弹窗按类型动态字段(企业:名称/行业/注册号/联系人/电话邮箱/身份证/社媒;人员:姓名/电话邮箱/身份证/社媒;产品:名称/品类;需求:名称/需求类别)+各类型转软碎片要求(企业需名称+行业+注册号,人员需姓名+联系方式,产品需品类,需求需类别,前后端双校验)+preliminary_data加行业/注册号列
This commit is contained in:
@@ -41,15 +41,63 @@ $phone = trim($_POST['contact_phone'] ?? ($frag['contact_phone'] ?? ''));
|
||||
$email = trim($_POST['contact_email'] ?? ($frag['contact_email'] ?? ''));
|
||||
$category = trim($_POST['target_product_category'] ?? ''); // 仅补全录入表单提供(表中已无该字段)
|
||||
$description = trim($_POST['description'] ?? ''); // 仅补全录入表单提供
|
||||
$industry = trim($_POST['industry'] ?? '');
|
||||
$industry = trim($_POST['industry'] ?? ($frag['industry'] ?? '')); // 企业:行业(转软碎片必填)
|
||||
$registrationNum = trim($_POST['registration_number'] ?? ($frag['registration_number'] ?? '')); // 企业:注册号(转软碎片必填)
|
||||
$sourceChannel = $frag['source_channel'] ?? null;
|
||||
|
||||
// 补全表单额外信息(extra_info)
|
||||
$fragExtra = json_decode($frag['extra_info'] ?? 'null', true);
|
||||
if (!is_array($fragExtra)) {
|
||||
$fragExtra = [];
|
||||
}
|
||||
if ($category === '') $category = trim((string)($fragExtra['category'] ?? ''));
|
||||
$needCategory = trim($_POST['need_category'] ?? ($fragExtra['need_category'] ?? ''));
|
||||
|
||||
$convertedId = 0;
|
||||
|
||||
// 格式校验:手机 / 邮箱
|
||||
checkFieldFormat('phone', $phone);
|
||||
checkFieldFormat('email', $email);
|
||||
|
||||
// 各类型转软碎片基本要求
|
||||
switch ($targetType) {
|
||||
case 'company':
|
||||
if ($companyName === '') {
|
||||
Response::error('企业类型转软碎片:企业名称为必填项,请先「继续补全」', 400);
|
||||
}
|
||||
if ($industry === '') {
|
||||
Response::error('企业类型转软碎片:行业为必填项,请先「继续补全」填写行业', 400);
|
||||
}
|
||||
if ($registrationNum === '') {
|
||||
Response::error('企业类型转软碎片:注册号为必填项,请先「继续补全」填写注册号', 400);
|
||||
}
|
||||
break;
|
||||
case 'person':
|
||||
if ($personName === '') {
|
||||
Response::error('人员类型转软碎片:姓名为必填项,请先「继续补全」', 400);
|
||||
}
|
||||
if ($phone === '' && $email === '') {
|
||||
Response::error('人员类型转软碎片:手机号码、邮箱至少填写一项,请先「继续补全」', 400);
|
||||
}
|
||||
break;
|
||||
case 'product':
|
||||
if ($companyName === '') {
|
||||
Response::error('产品类型转软碎片:公司名称为必填项,请先「继续补全」', 400);
|
||||
}
|
||||
if ($category === '') {
|
||||
Response::error('产品类型转软碎片:产品品类为必填项,请先「继续补全」填写品类', 400);
|
||||
}
|
||||
break;
|
||||
case 'need':
|
||||
if ($companyName === '') {
|
||||
Response::error('需求类型转软碎片:公司名称为必填项,请先「继续补全」', 400);
|
||||
}
|
||||
if ($needCategory === '') {
|
||||
Response::error('需求类型转软碎片:需求类别为必填项,请先「继续补全」填写需求类别', 400);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// 唯一性校验:按目标类型,收集全部重复
|
||||
$dups = [];
|
||||
if ($targetType === 'company' && $companyName !== '') {
|
||||
@@ -79,7 +127,7 @@ $saveContacts = function ($ownerType, $ownerId) use ($pdo, $phone, $email) {
|
||||
};
|
||||
|
||||
/** 按名称找公司,找不到则自动创建 */
|
||||
$resolveCompany = function () use ($pdo, $companyName, $sourceChannel, $industry) {
|
||||
$resolveCompany = function () use ($pdo, $companyName, $sourceChannel, $industry, $registrationNum) {
|
||||
$stmt = $pdo->prepare("SELECT id FROM companies WHERE display_name = ? AND is_active = 1 LIMIT 1");
|
||||
$stmt->execute([$companyName]);
|
||||
$cid = (int)$stmt->fetchColumn();
|
||||
@@ -87,22 +135,20 @@ $resolveCompany = function () use ($pdo, $companyName, $sourceChannel, $industry
|
||||
return $cid;
|
||||
}
|
||||
$pdo->prepare(
|
||||
"INSERT INTO companies (display_name, name_zh, industry, source_channel) VALUES (?, ?, ?, ?)"
|
||||
)->execute([$companyName, $companyName, $industry !== '' ? $industry : null, $sourceChannel]);
|
||||
"INSERT INTO companies (display_name, name_zh, industry, registration_number, source_channel) VALUES (?, ?, ?, ?, ?)"
|
||||
)->execute([$companyName, $companyName, $industry !== '' ? $industry : null, $registrationNum !== '' ? $registrationNum : null, $sourceChannel]);
|
||||
return (int)$pdo->lastInsertId();
|
||||
};
|
||||
|
||||
switch ($targetType) {
|
||||
case 'company':
|
||||
if ($companyName === '') {
|
||||
Response::error('公司名称为必填项', 400);
|
||||
}
|
||||
$pdo->prepare(
|
||||
"INSERT INTO companies (display_name, name_zh, industry, business_scope, source_channel, source_detail)
|
||||
VALUES (?, ?, ?, ?, ?, ?)"
|
||||
"INSERT INTO companies (display_name, name_zh, industry, registration_number, business_scope, source_channel, source_detail)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)"
|
||||
)->execute([
|
||||
$companyName, $companyName,
|
||||
$industry !== '' ? $industry : null,
|
||||
$registrationNum !== '' ? $registrationNum : null,
|
||||
$description !== '' ? $description : null,
|
||||
$sourceChannel,
|
||||
$description !== '' ? $description : null,
|
||||
@@ -149,7 +195,6 @@ switch ($targetType) {
|
||||
}
|
||||
$companyId = $resolveCompany();
|
||||
$contactPerson = trim($_POST['contact_person'] ?? ($frag['person_name'] ?? ''));
|
||||
$needCategory = trim($_POST['need_category'] ?? '');
|
||||
$scenario = trim($_POST['application_scenario'] ?? '');
|
||||
$pdo->prepare(
|
||||
"INSERT INTO company_needs (company_id, contact_person, need_category, target_product_category, application_scenario, description)
|
||||
|
||||
Reference in New Issue
Block a user