diff --git a/api/fragment/hard_update.php b/api/fragment/hard_update.php new file mode 100644 index 0000000..562cb74 --- /dev/null +++ b/api/fragment/hard_update.php @@ -0,0 +1,116 @@ +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, '已保存,点击「转软碎片」完成转换'); diff --git a/static/js/config.js b/static/js/config.js index 48f1b41..79ada9b 100644 --- a/static/js/config.js +++ b/static/js/config.js @@ -5,7 +5,7 @@ var BASE_URL = '/api/'; var PAGE_SIZE = 20; /** 系统版本号(logo旁展示):修改代码后运行 tools/bump_version.php 自动递增 */ -var APP_VERSION = 'v1.0.43'; +var APP_VERSION = 'v1.0.44'; /** 页脚版权/备案信息(在 config.js 中修改) */ var FOOTER_TEXT = '© 2026 SuperLink 管理系统 版权所有 | 备案号:请替换为真实备案号'; diff --git a/static/js/fragment.js b/static/js/fragment.js index be2ff1e..656c944 100644 --- a/static/js/fragment.js +++ b/static/js/fragment.js @@ -298,44 +298,47 @@ $(function () { /* ================= 硬碎片:补全录入(转换) ================= */ window.convertHard = function (id) { httpGet('fragment/hard_detail.php', { id: id }).then(function (d) { + var ex = d.extra_info || {}; + if (typeof ex === 'string') { try { ex = JSON.parse(ex); } catch (e) { ex = {}; } } var typeSel = ''; + '' + + ''; var content = '
'; var idx = Dialog.open({ - title: '硬碎片补全录入', + title: '硬数据继续补全', area: ['640px', 'auto'], content: content, btn: false }); + $('#cv-platform').val(ex.platform || ''); function syncFields() { var t = $('#cv-type').val(); $('#cv-f-company_name').toggle(t !== 'person'); - $('#cv-f-person_name').toggle(t === 'person'); - $('#cv-f-category').toggle(t === 'product' || t === 'need'); - $('#cv-f-industry').toggle(t === 'company'); - $('#cv-f-needcat').toggle(t === 'need'); - $('#cv-f-scenario').toggle(t === 'need'); + $('#cv-f-person_name').toggle(t === 'person' || t === 'mixed'); } $('#cv-type').on('change', syncFields); syncFields(); @@ -344,21 +347,23 @@ $(function () { $('#cv-form').on('submit', function (e) { e.preventDefault(); var fd = {}; - $(this).find('input, select, textarea').each(function () { + $(this).find('input, select').each(function () { var name = $(this).attr('name'); if (name) fd[name] = $(this).val(); }); fd.id = id; - fd.target_type = $('#cv-type').val(); - // 格式校验:手机 / 邮箱 + // 类型标准校验 + if (fd.source_type !== 'person' && fd.source_type !== 'mixed' && !$.trim(fd.company_name)) { Dialog.error('企业类型硬数据:企业名称为必填项'); return; } + if (fd.source_type === 'person' && !$.trim(fd.contact_phone) && !$.trim(fd.contact_email)) { Dialog.error('人员类型硬数据:手机号码、邮箱至少填写一项'); return; } + // 格式校验:手机 / 邮箱 / 身份证 / 主页链接 if (fd.contact_phone && !validatePhoneCN(fd.contact_phone)) { Dialog.error('手机号码格式不正确(应为国内 11 位手机号,如 13812345678)'); return; } if (fd.contact_email && !validateEmail(fd.contact_email)) { Dialog.error('邮箱格式不正确'); return; } - httpPost('fragment/hard_convert.php', fd).then(function () { - Dialog.success('转换成功', function () { + if (fd.id_number && !validateIdCard(fd.id_number)) { Dialog.error('身份证号码格式不正确(应为 15 或 18 位)'); return; } + if (fd.profile_url && !/^https?:\/\//.test(fd.profile_url)) { Dialog.error('主页链接格式不正确(应以 http:// 或 https:// 开头)'); return; } + httpPost('fragment/hard_update.php', fd).then(function () { + Dialog.success('已保存,点击「转软碎片」完成转换', function () { Dialog.close(idx); - loadStats(); loadHardList(hardPage); - loadSoftList(1); }); }); });