v1.0.44: 继续补全不再直接转换 - 新增hard_update.php仅保存硬碎片字段(含extra身份证/平台/账号/主页,标准+格式+唯一性校验),前端继续补全弹窗改为保存表单,转换仅由转软碎片触发
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
/**
|
||||
* 硬碎片补全保存接口 POST /api/fragment/hard_update.php
|
||||
* 仅更新硬碎片字段(企业名/联系人/手机/邮箱/身份证/社媒账号/主页链接),不执行转换。
|
||||
* 转换请走 hard_convert.php(前端「转软碎片」按钮)。
|
||||
*/
|
||||
require_once __DIR__ . '/../common/db.php';
|
||||
require_once __DIR__ . '/../common/response.php';
|
||||
require_once __DIR__ . '/../common/auth.php';
|
||||
require_once __DIR__ . '/../common/logger.php';
|
||||
require_once __DIR__ . '/../common/validate.php';
|
||||
require_once __DIR__ . '/../common/duplicate_check.php';
|
||||
|
||||
checkAjax();
|
||||
checkPermission('preliminary');
|
||||
|
||||
$id = (int)($_POST['id'] ?? 0);
|
||||
if ($id <= 0) {
|
||||
Response::error('参数错误', 400);
|
||||
}
|
||||
|
||||
$pdo = DB::getInstance()->getPdo();
|
||||
$stmt = $pdo->prepare("SELECT * FROM preliminary_data WHERE id = ? AND is_active = 1");
|
||||
$stmt->execute([$id]);
|
||||
$frag = $stmt->fetch();
|
||||
if (!$frag) {
|
||||
Response::error('碎片不存在');
|
||||
}
|
||||
if (in_array($frag['status'], ['已转换', '已废弃'], true)) {
|
||||
Response::error('该碎片已处理(' . $frag['status'] . ')');
|
||||
}
|
||||
|
||||
$sourceType = trim($_POST['source_type'] ?? ($frag['source_type'] ?? ''));
|
||||
$companyName = trim($_POST['company_name'] ?? '');
|
||||
$personName = trim($_POST['person_name'] ?? '');
|
||||
$phone = trim($_POST['contact_phone'] ?? '');
|
||||
$email = trim($_POST['contact_email'] ?? '');
|
||||
$idNumber = trim($_POST['id_number'] ?? '');
|
||||
$platform = trim($_POST['platform'] ?? '');
|
||||
$accountId = trim($_POST['account_id'] ?? '');
|
||||
$profileUrl = trim($_POST['profile_url'] ?? '');
|
||||
if (!in_array($sourceType, ['company', 'person', 'product', 'need', 'mixed'], true)) {
|
||||
Response::error('碎片类型不合法', 400);
|
||||
}
|
||||
|
||||
// 硬数据标准校验:企业/产品/需求 → 企业名称必填;人员 → 手机、邮箱至少一项
|
||||
if (in_array($sourceType, ['company', 'product', 'need'], true) && $companyName === '') {
|
||||
Response::error('企业类型硬数据:企业名称为必填项', 400);
|
||||
}
|
||||
if ($sourceType === 'person' && $phone === '' && $email === '') {
|
||||
Response::error('人员类型硬数据:手机号码、邮箱至少填写一项', 400);
|
||||
}
|
||||
|
||||
// 格式校验
|
||||
checkFieldFormat('phone', $phone);
|
||||
checkFieldFormat('email', $email);
|
||||
checkFieldFormat('id_number', $idNumber);
|
||||
if ($profileUrl !== '' && !preg_match('/^https?:\/\//i', $profileUrl)) {
|
||||
Response::error('主页链接格式不正确(应以 http:// 或 https:// 开头)', 400);
|
||||
}
|
||||
|
||||
// 唯一性校验(收集全部重复)
|
||||
$dups = [];
|
||||
if ($companyName !== '') {
|
||||
$dup = findDuplicate($pdo, 'company_name', $companyName);
|
||||
if ($dup) $dups[] = $dup;
|
||||
}
|
||||
$dups = array_merge($dups, checkSingleAccountDuplicate($pdo, $phone !== '' ? 'phone' : '', $phone, $profileUrl));
|
||||
if ($email !== '') {
|
||||
$dup = findDuplicate($pdo, 'email', $email);
|
||||
if ($dup) $dups[] = $dup;
|
||||
}
|
||||
if ($idNumber !== '') {
|
||||
$dup = findDuplicate($pdo, 'id_number', $idNumber);
|
||||
if ($dup) $dups[] = $dup;
|
||||
}
|
||||
if ($accountId !== '' && $platform !== '') {
|
||||
$dup = findDuplicate($pdo, 'account_id', $accountId, [], $platform);
|
||||
if ($dup) $dups[] = $dup;
|
||||
}
|
||||
if (!empty($dups)) Response::duplicates($dups);
|
||||
|
||||
// extra_info 合并更新(身份证/平台/账号ID/主页链接)
|
||||
$extra = json_decode($frag['extra_info'] ?? 'null', true);
|
||||
if (!is_array($extra)) {
|
||||
$extra = [];
|
||||
}
|
||||
if ($idNumber !== '') $extra['id_number'] = $idNumber; else unset($extra['id_number']);
|
||||
if ($platform !== '') $extra['platform'] = $platform; else unset($extra['platform']);
|
||||
if ($accountId !== '') $extra['account_id'] = $accountId; else unset($extra['account_id']);
|
||||
if ($profileUrl !== '') $extra['profile_url'] = $profileUrl; else unset($extra['profile_url']);
|
||||
|
||||
$pdo->prepare(
|
||||
"UPDATE preliminary_data
|
||||
SET source_type = ?, company_name = ?, person_name = ?, contact_phone = ?, contact_email = ?, extra_info = ?
|
||||
WHERE id = ?"
|
||||
)->execute([
|
||||
$sourceType,
|
||||
$companyName !== '' ? $companyName : null,
|
||||
$personName !== '' ? $personName : null,
|
||||
$phone !== '' ? $phone : null,
|
||||
$email !== '' ? $email : null,
|
||||
$extra ? json_encode($extra, JSON_UNESCAPED_UNICODE) : null,
|
||||
$id,
|
||||
]);
|
||||
|
||||
logCurrent('update', 'fragment', 'preliminary_data', $id, [
|
||||
'source_type' => $sourceType,
|
||||
'company_name' => $companyName,
|
||||
'person_name' => $personName,
|
||||
'phone' => $phone,
|
||||
'email' => $email,
|
||||
'extra' => $extra,
|
||||
]);
|
||||
|
||||
Response::success(null, '已保存,点击「转软碎片」完成转换');
|
||||
Reference in New Issue
Block a user