|
@@ -140,6 +140,26 @@ $checkStr = "SELECT c.*, cc.*
|
|
|
|
|
|
$Dupli = "";
|
|
|
|
|
|
+// Company name similarity check
|
|
|
+if (!empty($cs_company)) {
|
|
|
+ $companyWords = explode(' ', strtolower($cs_company));
|
|
|
+ foreach ($companyWords as $word) {
|
|
|
+ if (strlen($word) > 3) { // Only check words longer than 3 characters
|
|
|
+ $checkStr .= " OR LOWER(c.cs_company) LIKE '%" . $conn->real_escape_string($word) . "%'";
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// Address similarity check
|
|
|
+if (!empty($cs_address)) {
|
|
|
+ $addressWords = explode(' ', strtolower($cs_address));
|
|
|
+ foreach ($addressWords as $word) {
|
|
|
+ if (strlen($word) > 3) { // Only check words longer than 3 characters
|
|
|
+ $checkStr .= " OR LOWER(c.cs_address) LIKE '%" . $conn->real_escape_string($word) . "%'";
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
// Check all contacts for duplicates
|
|
|
foreach ($contacts as $contact) {
|
|
|
// Check all phone numbers
|
|
@@ -147,12 +167,14 @@ foreach ($contacts as $contact) {
|
|
|
$tel_field = 'tel_' . $i;
|
|
|
if (!empty($contact[$tel_field])) {
|
|
|
$tel_format = numFormat($contact[$tel_field]);
|
|
|
- $checkStr .= " OR cc.tel_1_format LIKE '%" . substr($tel_format, 3, 9) . "%'" .
|
|
|
- " OR cc.tel_2_format LIKE '%" . substr($tel_format, 3, 9) . "%'" .
|
|
|
- " OR cc.tel_3_format LIKE '%" . substr($tel_format, 3, 9) . "%'" .
|
|
|
- " OR cc.wechat_1 LIKE '%" . substr($tel_format, 3, 9) . "%'" .
|
|
|
- " OR cc.wechat_2 LIKE '%" . substr($tel_format, 3, 9) . "%'" .
|
|
|
- " OR cc.wechat_3 LIKE '%" . substr($tel_format, 3, 9) . "%'";
|
|
|
+ // Remove country code and spaces for better matching
|
|
|
+ $tel_clean = preg_replace('/[^0-9]/', '', $tel_format);
|
|
|
+ $checkStr .= " OR cc.tel_1_format LIKE '%" . substr($tel_clean, -9) . "%'" .
|
|
|
+ " OR cc.tel_2_format LIKE '%" . substr($tel_clean, -9) . "%'" .
|
|
|
+ " OR cc.tel_3_format LIKE '%" . substr($tel_clean, -9) . "%'" .
|
|
|
+ " OR cc.wechat_1 LIKE '%" . substr($tel_clean, -9) . "%'" .
|
|
|
+ " OR cc.wechat_2 LIKE '%" . substr($tel_clean, -9) . "%'" .
|
|
|
+ " OR cc.wechat_3 LIKE '%" . substr($tel_clean, -9) . "%'";
|
|
|
$Dupli .= "电话" . $i . ":" . $contact[$tel_field] . " ";
|
|
|
}
|
|
|
}
|
|
@@ -161,9 +183,10 @@ foreach ($contacts as $contact) {
|
|
|
for ($i = 1; $i <= 3; $i++) {
|
|
|
$email_field = 'email_' . $i;
|
|
|
if (!empty($contact[$email_field])) {
|
|
|
- $checkStr .= " OR cc.email_1 = '" . $conn->real_escape_string($contact[$email_field]) . "'" .
|
|
|
- " OR cc.email_2 = '" . $conn->real_escape_string($contact[$email_field]) . "'" .
|
|
|
- " OR cc.email_3 = '" . $conn->real_escape_string($contact[$email_field]) . "'";
|
|
|
+ $email = strtolower($contact[$email_field]);
|
|
|
+ $checkStr .= " OR LOWER(cc.email_1) = '" . $conn->real_escape_string($email) . "'" .
|
|
|
+ " OR LOWER(cc.email_2) = '" . $conn->real_escape_string($email) . "'" .
|
|
|
+ " OR LOWER(cc.email_3) = '" . $conn->real_escape_string($email) . "'";
|
|
|
$Dupli .= "邮箱" . $i . ":" . $contact[$email_field] . " ";
|
|
|
}
|
|
|
}
|
|
@@ -173,12 +196,13 @@ foreach ($contacts as $contact) {
|
|
|
$whatsapp_field = 'whatsapp_' . $i;
|
|
|
if (!empty($contact[$whatsapp_field])) {
|
|
|
$whatsapp_format = numFormat($contact[$whatsapp_field]);
|
|
|
- $checkStr .= " OR cc.whatsapp_1_format LIKE '%" . substr($whatsapp_format, 3, 9) . "%'" .
|
|
|
- " OR cc.whatsapp_2_format LIKE '%" . substr($whatsapp_format, 3, 9) . "%'" .
|
|
|
- " OR cc.whatsapp_3_format LIKE '%" . substr($whatsapp_format, 3, 9) . "%'" .
|
|
|
- " OR cc.tel_1_format LIKE '%" . substr($whatsapp_format, 3, 9) . "%'" .
|
|
|
- " OR cc.tel_2_format LIKE '%" . substr($whatsapp_format, 3, 9) . "%'" .
|
|
|
- " OR cc.tel_3_format LIKE '%" . substr($whatsapp_format, 3, 9) . "%'";
|
|
|
+ $whatsapp_clean = preg_replace('/[^0-9]/', '', $whatsapp_format);
|
|
|
+ $checkStr .= " OR cc.whatsapp_1_format LIKE '%" . substr($whatsapp_clean, -9) . "%'" .
|
|
|
+ " OR cc.whatsapp_2_format LIKE '%" . substr($whatsapp_clean, -9) . "%'" .
|
|
|
+ " OR cc.whatsapp_3_format LIKE '%" . substr($whatsapp_clean, -9) . "%'" .
|
|
|
+ " OR cc.tel_1_format LIKE '%" . substr($whatsapp_clean, -9) . "%'" .
|
|
|
+ " OR cc.tel_2_format LIKE '%" . substr($whatsapp_clean, -9) . "%'" .
|
|
|
+ " OR cc.tel_3_format LIKE '%" . substr($whatsapp_clean, -9) . "%'";
|
|
|
$Dupli .= "WhatsApp" . $i . ":" . $contact[$whatsapp_field] . " ";
|
|
|
}
|
|
|
}
|
|
@@ -187,20 +211,22 @@ foreach ($contacts as $contact) {
|
|
|
for ($i = 1; $i <= 3; $i++) {
|
|
|
$wechat_field = 'wechat_' . $i;
|
|
|
if (!empty($contact[$wechat_field])) {
|
|
|
- if (strlen($contact[$wechat_field]) < 10) {
|
|
|
- $checkStr .= " OR cc.wechat_1 LIKE '%" . $conn->real_escape_string($contact[$wechat_field]) . "%'" .
|
|
|
- " OR cc.wechat_2 LIKE '%" . $conn->real_escape_string($contact[$wechat_field]) . "%'" .
|
|
|
- " OR cc.wechat_3 LIKE '%" . $conn->real_escape_string($contact[$wechat_field]) . "%'" .
|
|
|
- " OR cc.tel_1_format LIKE '%" . $conn->real_escape_string($contact[$wechat_field]) . "%'" .
|
|
|
- " OR cc.tel_2_format LIKE '%" . $conn->real_escape_string($contact[$wechat_field]) . "%'" .
|
|
|
- " OR cc.tel_3_format LIKE '%" . $conn->real_escape_string($contact[$wechat_field]) . "%'";
|
|
|
+ $wechat = $contact[$wechat_field];
|
|
|
+ if (strlen($wechat) < 10) {
|
|
|
+ $checkStr .= " OR cc.wechat_1 LIKE '%" . $conn->real_escape_string($wechat) . "%'" .
|
|
|
+ " OR cc.wechat_2 LIKE '%" . $conn->real_escape_string($wechat) . "%'" .
|
|
|
+ " OR cc.wechat_3 LIKE '%" . $conn->real_escape_string($wechat) . "%'" .
|
|
|
+ " OR cc.tel_1_format LIKE '%" . $conn->real_escape_string($wechat) . "%'" .
|
|
|
+ " OR cc.tel_2_format LIKE '%" . $conn->real_escape_string($wechat) . "%'" .
|
|
|
+ " OR cc.tel_3_format LIKE '%" . $conn->real_escape_string($wechat) . "%'";
|
|
|
} else {
|
|
|
- $checkStr .= " OR cc.wechat_1 LIKE '%" . substr($contact[$wechat_field], 2, 12) . "%'" .
|
|
|
- " OR cc.wechat_2 LIKE '%" . substr($contact[$wechat_field], 2, 12) . "%'" .
|
|
|
- " OR cc.wechat_3 LIKE '%" . substr($contact[$wechat_field], 2, 12) . "%'" .
|
|
|
- " OR cc.tel_1_format LIKE '%" . substr($contact[$wechat_field], 2, 12) . "%'" .
|
|
|
- " OR cc.tel_2_format LIKE '%" . substr($contact[$wechat_field], 2, 12) . "%'" .
|
|
|
- " OR cc.tel_3_format LIKE '%" . substr($contact[$wechat_field], 2, 12) . "%'";
|
|
|
+ $wechat_clean = preg_replace('/[^0-9]/', '', $wechat);
|
|
|
+ $checkStr .= " OR cc.wechat_1 LIKE '%" . substr($wechat_clean, -9) . "%'" .
|
|
|
+ " OR cc.wechat_2 LIKE '%" . substr($wechat_clean, -9) . "%'" .
|
|
|
+ " OR cc.wechat_3 LIKE '%" . substr($wechat_clean, -9) . "%'" .
|
|
|
+ " OR cc.tel_1_format LIKE '%" . substr($wechat_clean, -9) . "%'" .
|
|
|
+ " OR cc.tel_2_format LIKE '%" . substr($wechat_clean, -9) . "%'" .
|
|
|
+ " OR cc.tel_3_format LIKE '%" . substr($wechat_clean, -9) . "%'";
|
|
|
}
|
|
|
$Dupli .= "微信" . $i . ":" . $contact[$wechat_field] . " ";
|
|
|
}
|
|
@@ -210,9 +236,10 @@ foreach ($contacts as $contact) {
|
|
|
for ($i = 1; $i <= 3; $i++) {
|
|
|
$linkedin_field = 'linkedin_' . $i;
|
|
|
if (!empty($contact[$linkedin_field])) {
|
|
|
- $checkStr .= " OR cc.linkedin_1 LIKE '%" . $conn->real_escape_string($contact[$linkedin_field]) . "%'" .
|
|
|
- " OR cc.linkedin_2 LIKE '%" . $conn->real_escape_string($contact[$linkedin_field]) . "%'" .
|
|
|
- " OR cc.linkedin_3 LIKE '%" . $conn->real_escape_string($contact[$linkedin_field]) . "%'";
|
|
|
+ $linkedin = strtolower($contact[$linkedin_field]);
|
|
|
+ $checkStr .= " OR LOWER(cc.linkedin_1) LIKE '%" . $conn->real_escape_string($linkedin) . "%'" .
|
|
|
+ " OR LOWER(cc.linkedin_2) LIKE '%" . $conn->real_escape_string($linkedin) . "%'" .
|
|
|
+ " OR LOWER(cc.linkedin_3) LIKE '%" . $conn->real_escape_string($linkedin) . "%'";
|
|
|
$Dupli .= "LinkedIn" . $i . ":" . $contact[$linkedin_field] . " ";
|
|
|
}
|
|
|
}
|
|
@@ -221,9 +248,10 @@ foreach ($contacts as $contact) {
|
|
|
for ($i = 1; $i <= 3; $i++) {
|
|
|
$facebook_field = 'facebook_' . $i;
|
|
|
if (!empty($contact[$facebook_field])) {
|
|
|
- $checkStr .= " OR cc.facebook_1 LIKE '%" . $conn->real_escape_string($contact[$facebook_field]) . "%'" .
|
|
|
- " OR cc.facebook_2 LIKE '%" . $conn->real_escape_string($contact[$facebook_field]) . "%'" .
|
|
|
- " OR cc.facebook_3 LIKE '%" . $conn->real_escape_string($contact[$facebook_field]) . "%'";
|
|
|
+ $facebook = strtolower($contact[$facebook_field]);
|
|
|
+ $checkStr .= " OR LOWER(cc.facebook_1) LIKE '%" . $conn->real_escape_string($facebook) . "%'" .
|
|
|
+ " OR LOWER(cc.facebook_2) LIKE '%" . $conn->real_escape_string($facebook) . "%'" .
|
|
|
+ " OR LOWER(cc.facebook_3) LIKE '%" . $conn->real_escape_string($facebook) . "%'";
|
|
|
$Dupli .= "Facebook" . $i . ":" . $contact[$facebook_field] . " ";
|
|
|
}
|
|
|
}
|
|
@@ -232,14 +260,16 @@ foreach ($contacts as $contact) {
|
|
|
for ($i = 1; $i <= 3; $i++) {
|
|
|
$alibaba_field = 'alibaba_' . $i;
|
|
|
if (!empty($contact[$alibaba_field])) {
|
|
|
- if (strlen($contact[$alibaba_field]) < 10) {
|
|
|
- $checkStr .= " OR cc.alibaba_1 LIKE '" . $conn->real_escape_string($contact[$alibaba_field]) . "'" .
|
|
|
- " OR cc.alibaba_2 LIKE '" . $conn->real_escape_string($contact[$alibaba_field]) . "'" .
|
|
|
- " OR cc.alibaba_3 LIKE '" . $conn->real_escape_string($contact[$alibaba_field]) . "'";
|
|
|
+ $alibaba = strtolower($contact[$alibaba_field]);
|
|
|
+ if (strlen($alibaba) < 10) {
|
|
|
+ $checkStr .= " OR LOWER(cc.alibaba_1) LIKE '" . $conn->real_escape_string($alibaba) . "'" .
|
|
|
+ " OR LOWER(cc.alibaba_2) LIKE '" . $conn->real_escape_string($alibaba) . "'" .
|
|
|
+ " OR LOWER(cc.alibaba_3) LIKE '" . $conn->real_escape_string($alibaba) . "'";
|
|
|
} else {
|
|
|
- $checkStr .= " OR cc.alibaba_1 LIKE '%" . substr($contact[$alibaba_field], 3, 12) . "%'" .
|
|
|
- " OR cc.alibaba_2 LIKE '%" . substr($contact[$alibaba_field], 3, 12) . "%'" .
|
|
|
- " OR cc.alibaba_3 LIKE '%" . substr($contact[$alibaba_field], 3, 12) . "%'";
|
|
|
+ $alibaba_clean = preg_replace('/[^0-9a-zA-Z]/', '', $alibaba);
|
|
|
+ $checkStr .= " OR LOWER(cc.alibaba_1) LIKE '%" . substr($alibaba_clean, -9) . "%'" .
|
|
|
+ " OR LOWER(cc.alibaba_2) LIKE '%" . substr($alibaba_clean, -9) . "%'" .
|
|
|
+ " OR LOWER(cc.alibaba_3) LIKE '%" . substr($alibaba_clean, -9) . "%'";
|
|
|
}
|
|
|
$Dupli .= "阿里旺旺" . $i . ":" . $contact[$alibaba_field] . " ";
|
|
|
}
|