Răsfoiți Sursa

fix: system admin employee updated

igb 4 zile în urmă
părinte
comite
e70ff47ab8
2 a modificat fișierele cu 337 adăugiri și 337 ștergeri
  1. 336 336
      customerSave.php
  2. 1 1
      system/employee.php

+ 336 - 336
customerSave.php

@@ -329,342 +329,342 @@ if ($allowedit != 1) {
              "\\n高度类似,未能保存,请联系管理员核实!');history.back();</script>";
         exit;
     }
-    else
-    {
-        //全文检索再检查一次
-        //先去掉联系方式中的特殊字符
-        //用联系方式进行全文fullindex检索,用相关性分数大于百分70 的进行检查
-        
-        // 根据不同联系方式类型进行专门检查
-        $duplicateFound = false;
-        $matchDetails = '';
-        $matchScore = 0;
-        $matchCustomerId = 0;
-        $matchCustomerCode = '';
-        $matchOwner = '';
-        $matchAddTime = '';
-        
-        // 编辑模式下需要排除自己的ID
-        $excludeId = ($act === 'editSave' && is_numeric($id)) ? intval($id) : 0;
-        
-        // 1. 优先检查邮箱 - 邮箱是最精确的匹配
-        $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;
-            }
-        }
-        
-        // 2. 检查电话号码与WhatsApp - 清理后进行后缀匹配
-        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) { // 至少8位有效数字
-                                $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) {
-                    // 使用后8位进行匹配,避免国家代码等差异
-                    $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;
-                    }
-                }
-            }
-        }
-        
-        // 3. 检查社交媒体账号 (alibaba/wechat/facebook/linkedin)
-        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) { // 至少4个字符
-                                $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 {
-                        // Facebook和LinkedIn用模糊匹配
-                        $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; // 找到匹配就退出循环
-                    }
-                }
-            }
-        }
-        
-        // 4. 最后尝试全文检索 - 作为补充检测手段
-        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)) {
-                // 创建MATCH AGAINST语句的词条
-                $searchStr = implode(' ', array_unique(array_filter($searchTerms)));
-                
-                // 确保搜索字符串不为空
-                if (!empty($searchStr)) {
-                    // 构建全文检索SQL
-                    $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;
-        }
-    }
+//    else
+//    {
+//        //全文检索再检查一次
+//        //先去掉联系方式中的特殊字符
+//        //用联系方式进行全文fullindex检索,用相关性分数大于百分70 的进行检查
+//
+//        // 根据不同联系方式类型进行专门检查
+//        $duplicateFound = false;
+//        $matchDetails = '';
+//        $matchScore = 0;
+//        $matchCustomerId = 0;
+//        $matchCustomerCode = '';
+//        $matchOwner = '';
+//        $matchAddTime = '';
+//
+//        // 编辑模式下需要排除自己的ID
+//        $excludeId = ($act === 'editSave' && is_numeric($id)) ? intval($id) : 0;
+//
+//        // 1. 优先检查邮箱 - 邮箱是最精确的匹配
+//        $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;
+//            }
+//        }
+//
+//        // 2. 检查电话号码与WhatsApp - 清理后进行后缀匹配
+//        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) { // 至少8位有效数字
+//                                $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) {
+//                    // 使用后8位进行匹配,避免国家代码等差异
+//                    $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;
+//                    }
+//                }
+//            }
+//        }
+//
+//        // 3. 检查社交媒体账号 (alibaba/wechat/facebook/linkedin)
+//        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) { // 至少4个字符
+//                                $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 {
+//                        // Facebook和LinkedIn用模糊匹配
+//                        $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; // 找到匹配就退出循环
+//                    }
+//                }
+//            }
+//        }
+//
+//        // 4. 最后尝试全文检索 - 作为补充检测手段
+//        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)) {
+//                // 创建MATCH AGAINST语句的词条
+//                $searchStr = implode(' ', array_unique(array_filter($searchTerms)));
+//
+//                // 确保搜索字符串不为空
+//                if (!empty($searchStr)) {
+//                    // 构建全文检索SQL
+//                    $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;
+//        }
+//    }
 }
 
 // Save or update customer data

+ 1 - 1
system/employee.php

@@ -323,7 +323,7 @@ $hrefstr = "?keys=$keys";
                         <option value="0">隐藏</option>
                         <option value="-1">删除</option>
                     </select>
-                    <input type="button" value="执行" onClick="postchk(1)" class="btn1" />
+                    <input type="button" value="执行" onClick="postchk_new(1)" class="btn1" />
                     <input type="button" value="新增" onClick="location.href='?act=add'" class="btn1" />
                 </div>
             </td>