|
@@ -329,342 +329,342 @@ if ($allowedit != 1) {
|
|
"\\n高度类似,未能保存,请联系管理员核实!');history.back();</script>";
|
|
"\\n高度类似,未能保存,请联系管理员核实!');history.back();</script>";
|
|
exit;
|
|
exit;
|
|
}
|
|
}
|
|
- else
|
|
+
|
|
- {
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
- $duplicateFound = false;
|
|
+
|
|
- $matchDetails = '';
|
|
+
|
|
- $matchScore = 0;
|
|
+
|
|
- $matchCustomerId = 0;
|
|
+
|
|
- $matchCustomerCode = '';
|
|
+
|
|
- $matchOwner = '';
|
|
+
|
|
- $matchAddTime = '';
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
- $excludeId = ($act === 'editSave' && is_numeric($id)) ? intval($id) : 0;
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
- $emailTerms = [];
|
|
+
|
|
- foreach ($contacts as $contact) {
|
|
+
|
|
- for ($i = 1; $i <= 3; $i++) {
|
|
+
|
|
- $field = 'email_' . $i;
|
|
+
|
|
- if (!empty($contact[$field])) {
|
|
+
|
|
- $email = strtolower(trim($contact[$field]));
|
|
+
|
|
- if (strpos($email, '@') !== false) {
|
|
+
|
|
- $emailTerms[] = $email;
|
|
+
|
|
- }
|
|
+
|
|
- }
|
|
+
|
|
- }
|
|
+
|
|
- }
|
|
+
|
|
-
|
|
+
|
|
- if (!empty($emailTerms)) {
|
|
+
|
|
- $emailQuery = "SELECT c.id, c.cs_code, c.cs_belong, c.cs_addtime, cc.email_1, cc.email_2, cc.email_3
|
|
+
|
|
- FROM customer c
|
|
+
|
|
- JOIN customer_contact cc ON c.id = cc.customer_id
|
|
+
|
|
- WHERE c.cs_belong != " . $_SESSION['employee_id'] . "
|
|
+
|
|
- AND c.id != " . $excludeId . " AND (";
|
|
+
|
|
-
|
|
+
|
|
- $emailConditions = [];
|
|
+
|
|
- foreach ($emailTerms as $email) {
|
|
+
|
|
- $emailConditions[] = "cc.email_1 = '" . $conn->real_escape_string($email) . "'";
|
|
+
|
|
- $emailConditions[] = "cc.email_2 = '" . $conn->real_escape_string($email) . "'";
|
|
+
|
|
- $emailConditions[] = "cc.email_3 = '" . $conn->real_escape_string($email) . "'";
|
|
+
|
|
- }
|
|
+
|
|
-
|
|
+
|
|
- $emailQuery .= implode(" OR ", $emailConditions) . ") LIMIT 1";
|
|
+
|
|
- $emailResult = $conn->query($emailQuery);
|
|
+
|
|
-
|
|
+
|
|
- if ($emailResult && $emailResult->num_rows > 0) {
|
|
+
|
|
- $row = $emailResult->fetch_assoc();
|
|
+
|
|
- $matchCustomerId = $row['id'];
|
|
+
|
|
- $matchCustomerCode = $row['cs_code'];
|
|
+
|
|
- $matchOwner = $row['cs_belong'];
|
|
+
|
|
- $matchAddTime = $row['cs_addtime'];
|
|
+
|
|
- $matchDetails = "邮箱完全匹配";
|
|
+
|
|
- $matchScore = 0.95;
|
|
+
|
|
- $duplicateFound = true;
|
|
+
|
|
- }
|
|
+
|
|
- }
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
- if (!$duplicateFound) {
|
|
+
|
|
- $phoneTerms = [];
|
|
+
|
|
- foreach ($contacts as $contact) {
|
|
+
|
|
-
|
|
+
|
|
- for ($i = 1; $i <= 3; $i++) {
|
|
+
|
|
- $fields = ['tel_' . $i, 'whatsapp_' . $i];
|
|
+
|
|
- foreach ($fields as $field) {
|
|
+
|
|
- if (!empty($contact[$field])) {
|
|
+
|
|
- $cleaned = preg_replace('/[^0-9]/', '', $contact[$field]);
|
|
+
|
|
- if (strlen($cleaned) > 7) {
|
|
+
|
|
- $phoneTerms[] = $cleaned;
|
|
+
|
|
- }
|
|
+
|
|
- }
|
|
+
|
|
- }
|
|
+
|
|
- }
|
|
+
|
|
- }
|
|
+
|
|
-
|
|
+
|
|
- if (!empty($phoneTerms)) {
|
|
+
|
|
- $phoneQuery = "SELECT c.id, c.cs_code, c.cs_belong, c.cs_addtime,
|
|
+
|
|
- cc.tel_1_format, cc.tel_2_format, cc.tel_3_format,
|
|
+
|
|
- cc.whatsapp_1_format, cc.whatsapp_2_format, cc.whatsapp_3_format
|
|
+
|
|
- FROM customer c
|
|
+
|
|
- JOIN customer_contact cc ON c.id = cc.customer_id
|
|
+
|
|
- WHERE c.cs_belong != " . $_SESSION['employee_id'] . "
|
|
+
|
|
- AND c.id != " . $excludeId . " AND (";
|
|
+
|
|
-
|
|
+
|
|
- $phoneConditions = [];
|
|
+
|
|
- foreach ($phoneTerms as $phone) {
|
|
+
|
|
-
|
|
+
|
|
- $suffix = substr($phone, -8);
|
|
+
|
|
- if (strlen($suffix) == 8) {
|
|
+
|
|
- $phoneConditions[] = "cc.tel_1_format LIKE '%" . $conn->real_escape_string($suffix) . "'";
|
|
+
|
|
- $phoneConditions[] = "cc.tel_2_format LIKE '%" . $conn->real_escape_string($suffix) . "'";
|
|
+
|
|
- $phoneConditions[] = "cc.tel_3_format LIKE '%" . $conn->real_escape_string($suffix) . "'";
|
|
+
|
|
- $phoneConditions[] = "cc.whatsapp_1_format LIKE '%" . $conn->real_escape_string($suffix) . "'";
|
|
+
|
|
- $phoneConditions[] = "cc.whatsapp_2_format LIKE '%" . $conn->real_escape_string($suffix) . "'";
|
|
+
|
|
- $phoneConditions[] = "cc.whatsapp_3_format LIKE '%" . $conn->real_escape_string($suffix) . "'";
|
|
+
|
|
- }
|
|
+
|
|
- }
|
|
+
|
|
-
|
|
+
|
|
- if (!empty($phoneConditions)) {
|
|
+
|
|
- $phoneQuery .= implode(" OR ", $phoneConditions) . ") LIMIT 1";
|
|
+
|
|
- $phoneResult = $conn->query($phoneQuery);
|
|
+
|
|
-
|
|
+
|
|
- if ($phoneResult && $phoneResult->num_rows > 0) {
|
|
+
|
|
- $row = $phoneResult->fetch_assoc();
|
|
+
|
|
- $matchCustomerId = $row['id'];
|
|
+
|
|
- $matchCustomerCode = $row['cs_code'];
|
|
+
|
|
- $matchOwner = $row['cs_belong'];
|
|
+
|
|
- $matchAddTime = $row['cs_addtime'];
|
|
+
|
|
- $matchDetails = "电话号码后8位匹配";
|
|
+
|
|
- $matchScore = 0.90;
|
|
+
|
|
- $duplicateFound = true;
|
|
+
|
|
- }
|
|
+
|
|
- }
|
|
+
|
|
- }
|
|
+
|
|
- }
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
- if (!$duplicateFound) {
|
|
+
|
|
- $socialTerms = [];
|
|
+
|
|
- $socialFields = [
|
|
+
|
|
- 'alibaba' => '阿里旺旺',
|
|
+
|
|
- 'wechat' => '微信',
|
|
+
|
|
- 'facebook' => 'Facebook',
|
|
+
|
|
- 'linkedin' => 'LinkedIn'
|
|
+
|
|
- ];
|
|
+
|
|
-
|
|
+
|
|
- foreach ($contacts as $contact) {
|
|
+
|
|
- foreach ($socialFields as $field => $label) {
|
|
+
|
|
- for ($i = 1; $i <= 3; $i++) {
|
|
+
|
|
- $fieldName = $field . '_' . $i;
|
|
+
|
|
- if (!empty($contact[$fieldName])) {
|
|
+
|
|
- $value = trim($contact[$fieldName]);
|
|
+
|
|
- if (strlen($value) > 3) {
|
|
+
|
|
- $socialTerms[] = [
|
|
+
|
|
- 'type' => $field,
|
|
+
|
|
- 'label' => $label,
|
|
+
|
|
- 'value' => $value
|
|
+
|
|
- ];
|
|
+
|
|
- }
|
|
+
|
|
- }
|
|
+
|
|
- }
|
|
+
|
|
- }
|
|
+
|
|
- }
|
|
+
|
|
-
|
|
+
|
|
- if (!empty($socialTerms)) {
|
|
+
|
|
- foreach ($socialTerms as $term) {
|
|
+
|
|
- $field = $term['type'];
|
|
+
|
|
- $value = $term['value'];
|
|
+
|
|
- $label = $term['label'];
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
- $socialQuery = "SELECT c.id, c.cs_code, c.cs_belong, c.cs_addtime FROM customer c
|
|
+
|
|
- JOIN customer_contact cc ON c.id = cc.customer_id
|
|
+
|
|
- WHERE c.cs_belong != " . $_SESSION['employee_id'] . "
|
|
+
|
|
- AND c.id != " . $excludeId . " AND (";
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
- if ($field == 'alibaba' || $field == 'wechat') {
|
|
+
|
|
-
|
|
+
|
|
- $socialQuery .=
|
|
+
|
|
- "cc.{$field}_1 = '" . $conn->real_escape_string($value) . "' OR " .
|
|
+
|
|
- "cc.{$field}_2 = '" . $conn->real_escape_string($value) . "' OR " .
|
|
+
|
|
- "cc.{$field}_3 = '" . $conn->real_escape_string($value) . "'";
|
|
+
|
|
- } else {
|
|
+
|
|
-
|
|
+
|
|
- $socialQuery .=
|
|
+
|
|
- "cc.{$field}_1 LIKE '%" . $conn->real_escape_string($value) . "%' OR " .
|
|
+
|
|
- "cc.{$field}_2 LIKE '%" . $conn->real_escape_string($value) . "%' OR " .
|
|
+
|
|
- "cc.{$field}_3 LIKE '%" . $conn->real_escape_string($value) . "%'";
|
|
+
|
|
- }
|
|
+
|
|
-
|
|
+
|
|
- $socialQuery .= ") LIMIT 1";
|
|
+
|
|
- $socialResult = $conn->query($socialQuery);
|
|
+
|
|
-
|
|
+
|
|
- if ($socialResult && $socialResult->num_rows > 0) {
|
|
+
|
|
- $row = $socialResult->fetch_assoc();
|
|
+
|
|
- $matchCustomerId = $row['id'];
|
|
+
|
|
- $matchCustomerCode = $row['cs_code'];
|
|
+
|
|
- $matchOwner = $row['cs_belong'];
|
|
+
|
|
- $matchAddTime = $row['cs_addtime'];
|
|
+
|
|
- $matchDetails = $label . "账号匹配";
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
- switch ($field) {
|
|
+
|
|
- case 'alibaba':
|
|
+
|
|
- $matchScore = 0.85;
|
|
+
|
|
- break;
|
|
+
|
|
- case 'wechat':
|
|
+
|
|
- $matchScore = 0.85;
|
|
+
|
|
- break;
|
|
+
|
|
- case 'facebook':
|
|
+
|
|
- $matchScore = 0.80;
|
|
+
|
|
- break;
|
|
+
|
|
- case 'linkedin':
|
|
+
|
|
- $matchScore = 0.80;
|
|
+
|
|
- break;
|
|
+
|
|
- default:
|
|
+
|
|
- $matchScore = 0.75;
|
|
+
|
|
- }
|
|
+
|
|
-
|
|
+
|
|
- $duplicateFound = true;
|
|
+
|
|
- break;
|
|
+
|
|
- }
|
|
+
|
|
- }
|
|
+
|
|
- }
|
|
+
|
|
- }
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
- if (!$duplicateFound) {
|
|
+
|
|
-
|
|
+
|
|
- $searchTerms = [];
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
- foreach ($contacts as $contact) {
|
|
+
|
|
-
|
|
+
|
|
- if (!empty($contact['contact_name'])) {
|
|
+
|
|
- $searchTerms[] = textUncode($contact['contact_name']);
|
|
+
|
|
- }
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
- $contactFields = [
|
|
+
|
|
- 'tel', 'email', 'whatsapp', 'wechat',
|
|
+
|
|
- 'linkedin', 'facebook', 'alibaba'
|
|
+
|
|
- ];
|
|
+
|
|
-
|
|
+
|
|
- foreach ($contactFields as $fieldType) {
|
|
+
|
|
- for ($i = 1; $i <= 3; $i++) {
|
|
+
|
|
- $field = $fieldType . '_' . $i;
|
|
+
|
|
- if (!empty($contact[$field])) {
|
|
+
|
|
-
|
|
+
|
|
- if ($fieldType == 'tel' || $fieldType == 'whatsapp') {
|
|
+
|
|
- $cleaned = preg_replace('/[^0-9]/', '', $contact[$field]);
|
|
+
|
|
- if (strlen($cleaned) > 5) {
|
|
+
|
|
- $searchTerms[] = $cleaned;
|
|
+
|
|
- }
|
|
+
|
|
- } else if ($fieldType == 'email') {
|
|
+
|
|
- $cleaned = strtolower(trim($contact[$field]));
|
|
+
|
|
- if (strpos($cleaned, '@') !== false) {
|
|
+
|
|
- $searchTerms[] = $cleaned;
|
|
+
|
|
- }
|
|
+
|
|
- } else {
|
|
+
|
|
- $searchTerms[] = trim($contact[$field]);
|
|
+
|
|
- }
|
|
+
|
|
- }
|
|
+
|
|
- }
|
|
+
|
|
- }
|
|
+
|
|
- }
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
- if (!empty($searchTerms)) {
|
|
+
|
|
-
|
|
+
|
|
- $searchStr = implode(' ', array_unique(array_filter($searchTerms)));
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
- if (!empty($searchStr)) {
|
|
+
|
|
-
|
|
+
|
|
- $ftQuery = "SELECT c.id, c.cs_code, c.cs_belong, c.cs_addtime,
|
|
+
|
|
- MATCH( cc.tel_1, cc.tel_2, cc.tel_3,
|
|
+
|
|
- cc.email_1, cc.email_2, cc.email_3,
|
|
+
|
|
- cc.whatsapp_1, cc.whatsapp_2, cc.whatsapp_3,
|
|
+
|
|
- cc.wechat_1, cc.wechat_2, cc.wechat_3
|
|
+
|
|
- )
|
|
+
|
|
- AGAINST('" . $conn->real_escape_string($searchStr) . "' IN NATURAL LANGUAGE MODE) AS score
|
|
+
|
|
- FROM customer c
|
|
+
|
|
- JOIN customer_contact cc ON c.id = cc.customer_id
|
|
+
|
|
- WHERE c.id != " . $excludeId . "
|
|
+
|
|
- HAVING score > 0.7
|
|
+
|
|
- ORDER BY score DESC
|
|
+
|
|
- LIMIT 1";
|
|
+
|
|
- $ftResult = $conn->query($ftQuery);
|
|
+
|
|
-
|
|
+
|
|
- if(!($ftResult && $ftResult->num_rows > 0 ))
|
|
+
|
|
- {
|
|
+
|
|
-
|
|
+
|
|
- $ftQuery = "SELECT c.id, c.cs_code, c.cs_belong, c.cs_addtime,
|
|
+
|
|
- MATCH( cc.alibaba_1, cc.alibaba_2, cc.alibaba_3,
|
|
+
|
|
- cc.facebook_1, cc.facebook_2, cc.facebook_3,
|
|
+
|
|
- cc.linkedin_1, cc.linkedin_2, cc.linkedin_3)
|
|
+
|
|
- AGAINST('" . $conn->real_escape_string($searchStr) . "' IN NATURAL LANGUAGE MODE) AS score
|
|
+
|
|
- FROM customer c
|
|
+
|
|
- JOIN customer_contact cc ON c.id = cc.customer_id
|
|
+
|
|
- WHERE c.id != " . $excludeId . "
|
|
+
|
|
- HAVING score > 0.7
|
|
+
|
|
- ORDER BY score DESC
|
|
+
|
|
- LIMIT 1";
|
|
+
|
|
- $ftResult = $conn->query($ftQuery);
|
|
+
|
|
- }
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
- if ($ftResult && $ftResult->num_rows > 0) {
|
|
+
|
|
- $row = $ftResult->fetch_assoc();
|
|
+
|
|
- $matchCustomerId = $row['id'];
|
|
+
|
|
- $matchCustomerCode = $row['cs_code'];
|
|
+
|
|
- $matchOwner = $row['cs_belong'];
|
|
+
|
|
- $matchAddTime = $row['cs_addtime'];
|
|
+
|
|
- $matchDetails = "全文检索相似度" . number_format($row['score'] * 100, 1) . "%";
|
|
+
|
|
- $matchScore = $row['score'];
|
|
+
|
|
- $duplicateFound = true;
|
|
+
|
|
- }
|
|
+
|
|
- }
|
|
+
|
|
- }
|
|
+
|
|
- }
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
- if ($duplicateFound) {
|
|
+
|
|
-
|
|
+
|
|
- $ownerResult = $conn->query("SELECT em_user FROM employee WHERE id = " . $matchOwner);
|
|
+
|
|
- $ownerRow = $ownerResult->fetch_assoc();
|
|
+
|
|
- $owner = textUncode($ownerRow['em_user']);
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
- if (strtotime($cs_addtime) > strtotime($matchAddTime)) {
|
|
+
|
|
- $tstr = "INSERT INTO logrecord (loginName, loginIp, loginTime, loginAct) VALUES ('" .
|
|
+
|
|
- $_SESSION['employee_name'] . "', '" . getIp() . "', '" . date('Y-m-d H:i:s') . "', '" .
|
|
+
|
|
- $_SESSION['employee_name'] . "编辑客户\"" . $cs_code . "\",该客户与\"" .
|
|
+
|
|
- textUncode($matchCustomerCode) . "\"存在重复,<br>匹配类型:" . $matchDetails .
|
|
+
|
|
- "<br>客户由:" . $owner . $matchAddTime . "首次录入')";
|
|
+
|
|
- } else {
|
|
+
|
|
- $tstr = "INSERT INTO logrecord (loginName, loginIp, loginTime, loginAct) VALUES ('" .
|
|
+
|
|
- $_SESSION['employee_name'] . "', '" . getIp() . "', '" . date('Y-m-d H:i:s') . "', '" .
|
|
+
|
|
- $_SESSION['employee_name'] . "编辑客户\"" . $cs_code . "\",该客户与\"" .
|
|
+
|
|
- textUncode($matchCustomerCode) . "\"存在重复,<br>匹配类型:" . $matchDetails .
|
|
+
|
|
- "<br>客户由:" . $_SESSION['employee_name'] . $cs_addtime . "首次录入')";
|
|
+
|
|
- }
|
|
+
|
|
-
|
|
+
|
|
- $conn->query($tstr);
|
|
+
|
|
- echo "<script>alert('warning.2.录入信息\\n与" . $owner . "客户编号:" . textUncode($matchCustomerCode) .
|
|
+
|
|
- "\\存在重复(" . $matchDetails . "),未能保存\\n请联系管理员核实!');history.back();</script>";
|
|
+
|
|
- exit;
|
|
+
|
|
- }
|
|
+
|
|
- }
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|