v1.0.35: 重复校验支持多字段同时提示 - 校验引擎改收集模式返回全部重复,Response::duplicates单弹窗列出,前端遍历展示所有重复项
This commit is contained in:
@@ -177,16 +177,17 @@ function findDuplicate(PDO $pdo, $type, $value, $excludeIds = [], $platform = nu
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验单条账号(媒体模块扁平字段)
|
* 校验单条账号(媒体模块扁平字段),返回所有重复项数组(空=无重复)
|
||||||
* @param PDO $pdo
|
* @param PDO $pdo
|
||||||
* @param string $platform
|
* @param string $platform
|
||||||
* @param string $accountId
|
* @param string $accountId
|
||||||
* @param string $profileUrl
|
* @param string $profileUrl
|
||||||
* @param array $excludeIds
|
* @param array $excludeIds
|
||||||
* @return array|null
|
* @return array
|
||||||
*/
|
*/
|
||||||
function checkSingleAccountDuplicate(PDO $pdo, $platform, $accountId, $profileUrl = '', $excludeIds = [])
|
function checkSingleAccountDuplicate(PDO $pdo, $platform, $accountId, $profileUrl = '', $excludeIds = [])
|
||||||
{
|
{
|
||||||
|
$dups = [];
|
||||||
$platform = trim((string)$platform);
|
$platform = trim((string)$platform);
|
||||||
$accountId = trim((string)$accountId);
|
$accountId = trim((string)$accountId);
|
||||||
if ($platform !== '' && $accountId !== '') {
|
if ($platform !== '' && $accountId !== '') {
|
||||||
@@ -196,45 +197,43 @@ function checkSingleAccountDuplicate(PDO $pdo, $platform, $accountId, $profileUr
|
|||||||
$dup = findDuplicate($pdo, 'account_id', $accountId, $excludeIds, $platform);
|
$dup = findDuplicate($pdo, 'account_id', $accountId, $excludeIds, $platform);
|
||||||
}
|
}
|
||||||
if ($dup) {
|
if ($dup) {
|
||||||
return $dup;
|
$dups[] = $dup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$profileUrl = trim((string)$profileUrl);
|
$profileUrl = trim((string)$profileUrl);
|
||||||
if ($profileUrl !== '') {
|
if ($profileUrl !== '') {
|
||||||
$dup = findDuplicate($pdo, 'profile_url', $profileUrl, $excludeIds);
|
$dup = findDuplicate($pdo, 'profile_url', $profileUrl, $excludeIds);
|
||||||
if ($dup) {
|
if ($dup) {
|
||||||
return $dup;
|
$dups[] = $dup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return $dups;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验联系方式数组(persons/companies 的 contacts/accounts JSON)
|
* 校验联系方式数组(persons/companies 的 contacts/accounts JSON),返回所有重复项数组(空=无重复)
|
||||||
* @param PDO $pdo
|
* @param PDO $pdo
|
||||||
* @param array $accounts [{platform,account_id,profile_url,...}]
|
* @param array $accounts [{platform,account_id,profile_url,...}]
|
||||||
* @param array $excludeIds 整表替换时排除自身既有账号ID
|
* @param array $excludeIds 整表替换时排除自身既有账号ID
|
||||||
* @return array|null
|
* @return array
|
||||||
*/
|
*/
|
||||||
function checkAccountsDuplicates(PDO $pdo, $accounts, $excludeIds = [])
|
function checkAccountsDuplicates(PDO $pdo, $accounts, $excludeIds = [])
|
||||||
{
|
{
|
||||||
|
$dups = [];
|
||||||
if (!is_array($accounts)) {
|
if (!is_array($accounts)) {
|
||||||
return null;
|
return $dups;
|
||||||
}
|
}
|
||||||
foreach ($accounts as $a) {
|
foreach ($accounts as $a) {
|
||||||
if (!is_array($a)) {
|
if (!is_array($a)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$dup = checkSingleAccountDuplicate(
|
$dups = array_merge($dups, checkSingleAccountDuplicate(
|
||||||
$pdo,
|
$pdo,
|
||||||
$a['platform'] ?? '',
|
$a['platform'] ?? '',
|
||||||
$a['account_id'] ?? '',
|
$a['account_id'] ?? '',
|
||||||
$a['profile_url'] ?? '',
|
$a['profile_url'] ?? '',
|
||||||
$excludeIds
|
$excludeIds
|
||||||
);
|
));
|
||||||
if ($dup) {
|
|
||||||
return $dup;
|
|
||||||
}
|
}
|
||||||
}
|
return $dups;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-2
@@ -31,10 +31,20 @@ class Response
|
|||||||
*/
|
*/
|
||||||
public static function duplicate($dup)
|
public static function duplicate($dup)
|
||||||
{
|
{
|
||||||
|
self::duplicates([$dup]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 多条重复数据错误(一次录入多个字段均重复时,单弹窗全部列出)
|
||||||
|
* @param array $dups 重复记录数组
|
||||||
|
*/
|
||||||
|
public static function duplicates($dups)
|
||||||
|
{
|
||||||
|
$dups = array_values((array)$dups);
|
||||||
self::json([
|
self::json([
|
||||||
'code' => 1001,
|
'code' => 1001,
|
||||||
'msg' => ($dup['label'] ?? '字段') . '「' . ($dup['value'] ?? '') . '」出现重复',
|
'msg' => count($dups) . ' 个字段出现重复',
|
||||||
'data' => $dup,
|
'data' => $dups,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-5
@@ -30,21 +30,22 @@ if ((int)($data['is_listed'] ?? 0) !== 1) {
|
|||||||
|
|
||||||
$pdo = DB::getInstance()->getPdo();
|
$pdo = DB::getInstance()->getPdo();
|
||||||
|
|
||||||
// 唯一性校验:企业名称 / 注册号 / 联系方式(手机/邮箱/社媒账号/主页链接)
|
// 唯一性校验:企业名称 / 注册号 / 联系方式,收集全部重复
|
||||||
|
$dups = [];
|
||||||
$dup = findDuplicate($pdo, 'company_name', $data['name_zh'] ?? $data['display_name'] ?? '');
|
$dup = findDuplicate($pdo, 'company_name', $data['name_zh'] ?? $data['display_name'] ?? '');
|
||||||
if ($dup) Response::duplicate($dup);
|
if ($dup) $dups[] = $dup;
|
||||||
if (!empty($data['registration_number'])) {
|
if (!empty($data['registration_number'])) {
|
||||||
$dup = findDuplicate($pdo, 'registration_number', $data['registration_number']);
|
$dup = findDuplicate($pdo, 'registration_number', $data['registration_number']);
|
||||||
if ($dup) Response::duplicate($dup);
|
if ($dup) $dups[] = $dup;
|
||||||
}
|
}
|
||||||
if (isset($_POST['accounts'])) {
|
if (isset($_POST['accounts'])) {
|
||||||
$accounts = json_decode($_POST['accounts'], true);
|
$accounts = json_decode($_POST['accounts'], true);
|
||||||
if (!is_array($accounts)) {
|
if (!is_array($accounts)) {
|
||||||
Response::error('联系方式格式错误', 400);
|
Response::error('联系方式格式错误', 400);
|
||||||
}
|
}
|
||||||
$dup = checkAccountsDuplicates($pdo, $accounts);
|
$dups = array_merge($dups, checkAccountsDuplicates($pdo, $accounts));
|
||||||
if ($dup) Response::duplicate($dup);
|
|
||||||
}
|
}
|
||||||
|
if (!empty($dups)) Response::duplicates($dups);
|
||||||
|
|
||||||
[$sql, $params] = buildInsert($data);
|
[$sql, $params] = buildInsert($data);
|
||||||
$pdo->prepare("INSERT INTO companies $sql")->execute($params);
|
$pdo->prepare("INSERT INTO companies $sql")->execute($params);
|
||||||
|
|||||||
@@ -31,9 +31,9 @@ if ((int)$chk->fetchColumn() === 0) {
|
|||||||
Response::error('企业不存在');
|
Response::error('企业不存在');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 唯一性校验:社媒账号ID(同平台)/ 手机 / 邮箱 / 主页链接
|
// 唯一性校验:社媒账号ID(同平台)/ 手机 / 邮箱 / 主页链接,收集全部重复
|
||||||
$dup = checkSingleAccountDuplicate($pdo, $platform, $accountId, $_POST['profile_url'] ?? '');
|
$dups = checkSingleAccountDuplicate($pdo, $platform, $accountId, $_POST['profile_url'] ?? '');
|
||||||
if ($dup) Response::duplicate($dup);
|
if (!empty($dups)) Response::duplicates($dups);
|
||||||
|
|
||||||
$ins = $pdo->prepare(
|
$ins = $pdo->prepare(
|
||||||
"INSERT INTO social_accounts (owner_type, owner_id, platform, account_id, profile_url, remark, is_primary, is_defult, is_active)
|
"INSERT INTO social_accounts (owner_type, owner_id, platform, account_id, profile_url, remark, is_primary, is_defult, is_active)
|
||||||
|
|||||||
@@ -41,12 +41,13 @@ if (!$old) {
|
|||||||
Response::error('企业不存在');
|
Response::error('企业不存在');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 唯一性校验(排除自身):企业名称 / 注册号 / 联系方式
|
// 唯一性校验(排除自身):企业名称 / 注册号 / 联系方式,收集全部重复
|
||||||
|
$dups = [];
|
||||||
$dup = findDuplicate($pdo, 'company_name', $data['name_zh'] ?? $old['display_name'] ?? '', [$id]);
|
$dup = findDuplicate($pdo, 'company_name', $data['name_zh'] ?? $old['display_name'] ?? '', [$id]);
|
||||||
if ($dup) Response::duplicate($dup);
|
if ($dup) $dups[] = $dup;
|
||||||
if (!empty($data['registration_number'])) {
|
if (!empty($data['registration_number'])) {
|
||||||
$dup = findDuplicate($pdo, 'registration_number', $data['registration_number'], [$id]);
|
$dup = findDuplicate($pdo, 'registration_number', $data['registration_number'], [$id]);
|
||||||
if ($dup) Response::duplicate($dup);
|
if ($dup) $dups[] = $dup;
|
||||||
}
|
}
|
||||||
$accounts = null;
|
$accounts = null;
|
||||||
if ($hasAccounts) {
|
if ($hasAccounts) {
|
||||||
@@ -56,9 +57,9 @@ if ($hasAccounts) {
|
|||||||
}
|
}
|
||||||
// 整表替换:排除企业自身既有联系方式ID
|
// 整表替换:排除企业自身既有联系方式ID
|
||||||
$ownIds = $pdo->query("SELECT id FROM social_accounts WHERE owner_type = 'company' AND owner_id = $id")->fetchAll(PDO::FETCH_COLUMN);
|
$ownIds = $pdo->query("SELECT id FROM social_accounts WHERE owner_type = 'company' AND owner_id = $id")->fetchAll(PDO::FETCH_COLUMN);
|
||||||
$dup = checkAccountsDuplicates($pdo, $accounts, $ownIds);
|
$dups = array_merge($dups, checkAccountsDuplicates($pdo, $accounts, $ownIds));
|
||||||
if ($dup) Response::duplicate($dup);
|
|
||||||
}
|
}
|
||||||
|
if (!empty($dups)) Response::duplicates($dups);
|
||||||
|
|
||||||
if (!empty($data)) {
|
if (!empty($data)) {
|
||||||
[$sets, $params] = buildUpdate($data);
|
[$sets, $params] = buildUpdate($data);
|
||||||
|
|||||||
@@ -45,17 +45,17 @@ $sourceChannel = $frag['source_channel'] ?? null;
|
|||||||
|
|
||||||
$convertedId = 0;
|
$convertedId = 0;
|
||||||
|
|
||||||
// 唯一性校验:按目标类型
|
// 唯一性校验:按目标类型,收集全部重复
|
||||||
|
$dups = [];
|
||||||
if ($targetType === 'company' && $companyName !== '') {
|
if ($targetType === 'company' && $companyName !== '') {
|
||||||
$dup = findDuplicate($pdo, 'company_name', $companyName);
|
$dup = findDuplicate($pdo, 'company_name', $companyName);
|
||||||
if ($dup) Response::duplicate($dup);
|
if ($dup) $dups[] = $dup;
|
||||||
}
|
}
|
||||||
if (in_array($targetType, ['person', 'company'], true)) {
|
if (in_array($targetType, ['person', 'company'], true)) {
|
||||||
$dup = checkSingleAccountDuplicate($pdo, $phone !== '' ? 'phone' : '', $phone, '');
|
$dups = array_merge($dups, checkSingleAccountDuplicate($pdo, $phone !== '' ? 'phone' : '', $phone, ''));
|
||||||
if ($dup) Response::duplicate($dup);
|
$dups = array_merge($dups, checkSingleAccountDuplicate($pdo, $email !== '' ? 'email' : '', $email, ''));
|
||||||
$dup = checkSingleAccountDuplicate($pdo, $email !== '' ? 'email' : '', $email, '');
|
|
||||||
if ($dup) Response::duplicate($dup);
|
|
||||||
}
|
}
|
||||||
|
if (!empty($dups)) Response::duplicates($dups);
|
||||||
|
|
||||||
/** 创建 social_accounts(phone/email,常用) */
|
/** 创建 social_accounts(phone/email,常用) */
|
||||||
$saveContacts = function ($ownerType, $ownerId) use ($pdo, $phone, $email) {
|
$saveContacts = function ($ownerType, $ownerId) use ($pdo, $phone, $email) {
|
||||||
|
|||||||
+3
-3
@@ -43,9 +43,9 @@ if ((int)$chk->fetchColumn() > 0) {
|
|||||||
Response::error('该平台账号已存在', 400);
|
Response::error('该平台账号已存在', 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 唯一性校验:社媒账号ID(同平台)/ 手机 / 邮箱 / 主页链接
|
// 唯一性校验:社媒账号ID(同平台)/ 手机 / 邮箱 / 主页链接,收集全部重复
|
||||||
$dup = checkSingleAccountDuplicate($pdo, $data['platform'] ?? '', $data['account_id'] ?? '', $data['profile_url'] ?? '');
|
$dups = checkSingleAccountDuplicate($pdo, $data['platform'] ?? '', $data['account_id'] ?? '', $data['profile_url'] ?? '');
|
||||||
if ($dup) Response::duplicate($dup);
|
if (!empty($dups)) Response::duplicates($dups);
|
||||||
|
|
||||||
[$sql, $params] = buildInsert($data);
|
[$sql, $params] = buildInsert($data);
|
||||||
$pdo->prepare("INSERT INTO social_accounts $sql")->execute($params);
|
$pdo->prepare("INSERT INTO social_accounts $sql")->execute($params);
|
||||||
|
|||||||
@@ -30,16 +30,16 @@ if (!$old) {
|
|||||||
$data = extractFields(MEDIA_FIELDS);
|
$data = extractFields(MEDIA_FIELDS);
|
||||||
unset($data['owner_type'], $data['owner_id']); // 归属关系不允许改
|
unset($data['owner_type'], $data['owner_id']); // 归属关系不允许改
|
||||||
|
|
||||||
// 唯一性校验(排除自身):社媒账号ID(同平台)/ 手机 / 邮箱 / 主页链接
|
// 唯一性校验(排除自身):社媒账号ID(同平台)/ 手机 / 邮箱 / 主页链接,收集全部重复
|
||||||
if (isset($_POST['platform']) || isset($_POST['account_id']) || isset($_POST['profile_url'])) {
|
if (isset($_POST['platform']) || isset($_POST['account_id']) || isset($_POST['profile_url'])) {
|
||||||
$dup = checkSingleAccountDuplicate(
|
$dups = checkSingleAccountDuplicate(
|
||||||
$pdo,
|
$pdo,
|
||||||
$_POST['platform'] ?? ($old['platform'] ?? ''),
|
$_POST['platform'] ?? ($old['platform'] ?? ''),
|
||||||
$_POST['account_id'] ?? ($old['account_id'] ?? ''),
|
$_POST['account_id'] ?? ($old['account_id'] ?? ''),
|
||||||
$_POST['profile_url'] ?? ($old['profile_url'] ?? ''),
|
$_POST['profile_url'] ?? ($old['profile_url'] ?? ''),
|
||||||
[$id]
|
[$id]
|
||||||
);
|
);
|
||||||
if ($dup) Response::duplicate($dup);
|
if (!empty($dups)) Response::duplicates($dups);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($data)) {
|
if (!empty($data)) {
|
||||||
|
|||||||
+5
-4
@@ -32,17 +32,18 @@ if ((int)$chk->fetchColumn() > 0) {
|
|||||||
Response::error('union_id 已存在,请更换');
|
Response::error('union_id 已存在,请更换');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 唯一性校验:身份证号码 / 联系方式(手机/邮箱/社媒账号/主页链接)
|
// 唯一性校验:身份证号码 / 联系方式(手机/邮箱/社媒账号/主页链接),收集全部重复
|
||||||
|
$dups = [];
|
||||||
if (!empty($data['id_number'])) {
|
if (!empty($data['id_number'])) {
|
||||||
$dup = findDuplicate($pdo, 'id_number', $data['id_number']);
|
$dup = findDuplicate($pdo, 'id_number', $data['id_number']);
|
||||||
if ($dup) Response::duplicate($dup);
|
if ($dup) $dups[] = $dup;
|
||||||
}
|
}
|
||||||
$contacts = json_decode($_POST['contacts'] ?? '[]', true);
|
$contacts = json_decode($_POST['contacts'] ?? '[]', true);
|
||||||
if (!is_array($contacts)) {
|
if (!is_array($contacts)) {
|
||||||
$contacts = [];
|
$contacts = [];
|
||||||
}
|
}
|
||||||
$dup = checkAccountsDuplicates($pdo, $contacts);
|
$dups = array_merge($dups, checkAccountsDuplicates($pdo, $contacts));
|
||||||
if ($dup) Response::duplicate($dup);
|
if (!empty($dups)) Response::duplicates($dups);
|
||||||
|
|
||||||
[$sql, $params] = buildInsert($data);
|
[$sql, $params] = buildInsert($data);
|
||||||
$pdo->prepare("INSERT INTO persons $sql")->execute($params);
|
$pdo->prepare("INSERT INTO persons $sql")->execute($params);
|
||||||
|
|||||||
@@ -30,10 +30,11 @@ if (!$old) {
|
|||||||
Response::error('人员不存在');
|
Response::error('人员不存在');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 唯一性校验(排除自身):身份证号码 / 联系方式
|
// 唯一性校验(排除自身):身份证号码 / 联系方式,收集全部重复
|
||||||
|
$dups = [];
|
||||||
if (!empty($data['id_number'])) {
|
if (!empty($data['id_number'])) {
|
||||||
$dup = findDuplicate($pdo, 'id_number', $data['id_number'], [$id]);
|
$dup = findDuplicate($pdo, 'id_number', $data['id_number'], [$id]);
|
||||||
if ($dup) Response::duplicate($dup);
|
if ($dup) $dups[] = $dup;
|
||||||
}
|
}
|
||||||
$contacts = null;
|
$contacts = null;
|
||||||
if (isset($_POST['contacts'])) {
|
if (isset($_POST['contacts'])) {
|
||||||
@@ -43,9 +44,9 @@ if (isset($_POST['contacts'])) {
|
|||||||
}
|
}
|
||||||
// 整体替换:排除人员自身既有联系方式ID
|
// 整体替换:排除人员自身既有联系方式ID
|
||||||
$ownIds = $pdo->query("SELECT id FROM social_accounts WHERE owner_type = 'person' AND owner_id = $id")->fetchAll(PDO::FETCH_COLUMN);
|
$ownIds = $pdo->query("SELECT id FROM social_accounts WHERE owner_type = 'person' AND owner_id = $id")->fetchAll(PDO::FETCH_COLUMN);
|
||||||
$dup = checkAccountsDuplicates($pdo, $contacts, $ownIds);
|
$dups = array_merge($dups, checkAccountsDuplicates($pdo, $contacts, $ownIds));
|
||||||
if ($dup) Response::duplicate($dup);
|
|
||||||
}
|
}
|
||||||
|
if (!empty($dups)) Response::duplicates($dups);
|
||||||
|
|
||||||
$contactsChanged = false;
|
$contactsChanged = false;
|
||||||
if ($contacts !== null) {
|
if ($contacts !== null) {
|
||||||
|
|||||||
+9
-7
@@ -49,17 +49,19 @@ function handleResp(resp) {
|
|||||||
location.href = 'index.html';
|
location.href = 'index.html';
|
||||||
return $.Deferred().reject(resp).promise();
|
return $.Deferred().reject(resp).promise();
|
||||||
}
|
}
|
||||||
// 重复数据:弹窗提示字段 + 重复记录的表名与 id
|
// 重复数据:单弹窗列出所有重复字段 + 重复记录的表名与 id
|
||||||
if (resp && resp.code === 1001 && resp.data) {
|
if (resp && resp.code === 1001 && resp.data) {
|
||||||
var d = resp.data;
|
var list = $.isArray(resp.data) ? resp.data : [resp.data];
|
||||||
|
var items = '';
|
||||||
|
(list || []).forEach(function (x) {
|
||||||
|
items += '<div style="font-size:14px;color:#e74c3c;margin-bottom:4px;">' + escHtml(x.label) + '「' + escHtml(x.value) + '」出现重复</div>' +
|
||||||
|
'<div style="font-size:13px;color:#5a6472;margin-bottom:10px;">重复数据:' + escHtml(x.table) + ' 表,id=' + x.id + '</div>';
|
||||||
|
});
|
||||||
layer.open({
|
layer.open({
|
||||||
type: 1,
|
type: 1,
|
||||||
title: '数据重复提示',
|
title: '数据重复提示',
|
||||||
area: ['420px', 'auto'],
|
area: ['440px', 'auto'],
|
||||||
content: '<div style="padding:20px 24px;">' +
|
content: '<div style="padding:20px 24px;">' + items + '</div>',
|
||||||
'<div style="font-size:14px;color:#e74c3c;margin-bottom:10px;">' + escHtml(d.label) + '「' + escHtml(d.value) + '」出现重复</div>' +
|
|
||||||
'<div style="font-size:13px;color:#5a6472;">重复数据:' + escHtml(d.table) + ' 表,id=' + d.id + '</div>' +
|
|
||||||
'</div>',
|
|
||||||
btn: ['知道了']
|
btn: ['知道了']
|
||||||
});
|
});
|
||||||
return $.Deferred().reject(resp).promise();
|
return $.Deferred().reject(resp).promise();
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@ var BASE_URL = '/api/';
|
|||||||
var PAGE_SIZE = 20;
|
var PAGE_SIZE = 20;
|
||||||
|
|
||||||
/** 系统版本号(logo旁展示):修改代码后运行 tools/bump_version.php 自动递增 */
|
/** 系统版本号(logo旁展示):修改代码后运行 tools/bump_version.php 自动递增 */
|
||||||
var APP_VERSION = 'v1.0.34';
|
var APP_VERSION = 'v1.0.35';
|
||||||
|
|
||||||
/** 页脚版权/备案信息(在 config.js 中修改) */
|
/** 页脚版权/备案信息(在 config.js 中修改) */
|
||||||
var FOOTER_TEXT = '© 2026 SuperLink 管理系统 版权所有 | 备案号:请替换为真实备案号';
|
var FOOTER_TEXT = '© 2026 SuperLink 管理系统 版权所有 | 备案号:请替换为真实备案号';
|
||||||
|
|||||||
Reference in New Issue
Block a user