Browse Source

fleat:update customer 2 table

igb 3 weeks ago
parent
commit
16d2972b53
8 changed files with 276 additions and 186 deletions
  1. 22 20
      highSeas.php
  2. 8 5
      nullTag.php
  3. 18 15
      searchResult.php
  4. 26 24
      silentCustomer.php
  5. 2 2
      subTagClound.php
  6. 151 75
      system/customers.php
  7. 26 26
      team.php
  8. 23 19
      teamSeas.php

+ 22 - 20
highSeas.php

@@ -41,27 +41,27 @@ $filterStr = "";
 $urlStr = "";
 
 if (!empty($filterCountry)) {
-    $filterStr .= " AND cs_country=" . (int)$filterCountry;
+    $filterStr .= " AND c.cs_country=" . (int)$filterCountry;
     $urlStr .= "&fliterCountry=" . $filterCountry;
 }
 
 if (!empty($filterQudao)) {
-    $filterStr .= " AND cs_from=" . (int)$filterQudao;
+    $filterStr .= " AND c.cs_from=" . (int)$filterQudao;
     $urlStr .= "&fliterQudao=" . $filterQudao;
 }
 
 if (!empty($filterDeal)) {
-    $filterStr .= " AND cs_deal=" . (int)$filterDeal;
+    $filterStr .= " AND c.cs_deal=" . (int)$filterDeal;
     $urlStr .= "&fliterDeal=" . $filterDeal;
 }
 
 if (!empty($filterBusiness)) {
-    $filterStr .= " AND cs_type=" . (int)$filterBusiness;
+    $filterStr .= " AND c.cs_type=" . (int)$filterBusiness;
     $urlStr .= "&fliterBusiness=" . $filterBusiness;
 }
 
 if (!empty($filterBelong)) {
-    $filterStr .= " AND cs_belong=" . (int)$filterBelong;
+    $filterStr .= " AND c.cs_belong=" . (int)$filterBelong;
     $urlStr .= "&fliterBelong=" . $filterBelong;
 }
 
@@ -147,21 +147,23 @@ $hrefstr = "?keys=" . $keys;
         </div>
 
 <?php
-$sql = "SELECT id, cs_code, cs_from, cs_country, cs_type, cs_deal, cs_addtime, cs_updatetime, cs_note, cs_claimFrom 
-        FROM customer 
-        WHERE cs_deal<>3 AND cs_deal<>0 AND cs_type<>2 AND cs_belong<>13 
-        AND cs_belong<>" . $_SESSION['employee_id'] . " 
-        AND DATEDIFF(NOW(), cs_updatetime) > 120 
-        AND cs_country NOT IN (2, 229, 13, 153) 
-        AND cs_belongclient=0 
-        AND cs_wechat NOT LIKE 'wxid%' 
-        AND (cs_code LIKE '%" . $conn->real_escape_string($keyscode) . "%' 
-        OR cs_name LIKE '%" . $conn->real_escape_string($keyscode) . "%'
-        OR cs_email LIKE '%" . $conn->real_escape_string($keyscode) . "%'
-        OR cs_wechat LIKE '%" . $conn->real_escape_string($keyscode) . "%'
-        OR cs_tel LIKE '%" . $conn->real_escape_string($keyscode) . "%'
-        OR cs_whatsapp LIKE '%" . $conn->real_escape_string($keyscode) . "%')" . 
-        $filterStr . " ORDER BY cs_state DESC, id DESC";
+$sql = "SELECT c.id, c.cs_code, c.cs_from, c.cs_country, c.cs_type, c.cs_deal, c.cs_addtime, 
+        c.cs_updatetime, c.cs_note, c.cs_claimFrom 
+        FROM customer c
+        LEFT JOIN customer_contact cc ON c.id = cc.customer_id
+        WHERE c.cs_deal<>3 AND c.cs_deal<>0 AND c.cs_type<>2 AND c.cs_belong<>13 
+        AND c.cs_belong<>" . $_SESSION['employee_id'] . " 
+        AND DATEDIFF(NOW(), c.cs_updatetime) > 120 
+        AND c.cs_country NOT IN (2, 229, 13, 153) 
+        AND c.cs_belongclient=0 
+        AND cc.wechat NOT LIKE 'wxid%' 
+        AND (c.cs_code LIKE '%" . $conn->real_escape_string($keyscode) . "%' 
+        OR cc.contact_name LIKE '%" . $conn->real_escape_string($keyscode) . "%'
+        OR cc.email LIKE '%" . $conn->real_escape_string($keyscode) . "%'
+        OR cc.wechat LIKE '%" . $conn->real_escape_string($keyscode) . "%'
+        OR cc.tel LIKE '%" . $conn->real_escape_string($keyscode) . "%'
+        OR cc.whatsapp LIKE '%" . $conn->real_escape_string($keyscode) . "%')" . 
+        $filterStr . " ORDER BY c.cs_state DESC, c.id DESC";
 
 $result = $conn->query($sql);
 

+ 8 - 5
nullTag.php

@@ -48,11 +48,14 @@ while ($row = $result->fetch_assoc()) {
         </div>
 
 <?php
-$sqlStr = "SELECT id, cs_code, cs_from, cs_country, cs_type, cs_deal, cs_addtime, cs_tel, cs_email, 
-           cs_whatsapp, cs_wechat, cs_linkedin, cs_facebook, cs_alibaba, cs_note 
-           FROM customer 
-           WHERE cs_belong=" . $_SESSION['employee_id'] . " 
-           AND id NOT IN (SELECT customerId FROM tagtable)";
+$sqlStr = "SELECT c.id, c.cs_code, c.cs_from, c.cs_country, c.cs_type, c.cs_deal, c.cs_addtime, 
+           c.cs_note, cc.tel as cs_tel, cc.email as cs_email, cc.whatsapp as cs_whatsapp, 
+           cc.wechat as cs_wechat, cc.linkedin as cs_linkedin, cc.facebook as cs_facebook, 
+           cc.alibaba as cs_alibaba 
+           FROM customer c 
+           LEFT JOIN customer_contact cc ON c.id = cc.customer_id
+           WHERE c.cs_belong=" . $_SESSION['employee_id'] . " 
+           AND c.id NOT IN (SELECT customerId FROM tagtable)";
 
 $result = $conn->query($sqlStr);
 $tempNum = 0;

+ 18 - 15
searchResult.php

@@ -11,21 +11,24 @@ if (empty($keywords) || strlen($keywords) < 4) {
     exit;
 }
 
-$searchStr = "SELECT cs_code, cs_name, cs_country, cs_tel, cs_email, cs_whatsapp, cs_wechat, cs_linkedin, 
-             cs_facebook, cs_addtime, cs_from, cs_belong, cs_deal, cs_alibaba 
-             FROM customer 
-             WHERE (cs_telformat LIKE '%" . $conn->real_escape_string($keywords) . "%' 
-             OR cs_email LIKE '%" . $conn->real_escape_string($keywords) . "%' 
-             OR cs_whatsappformat LIKE '%" . $conn->real_escape_string($keywords) . "%' 
-             OR cs_wechat LIKE '%" . $conn->real_escape_string($keywords) . "%' 
-             OR cs_alibaba LIKE '%" . $conn->real_escape_string($keywords) . "%' 
-             OR cs_linkedin LIKE '%" . $conn->real_escape_string($keywords) . "%' 
-             OR cs_facebook LIKE '%" . $conn->real_escape_string($keywords) . "%' 
-             OR cs_email LIKE '%" . $conn->real_escape_string($keywordsNative) . "%' 
-             OR cs_wechat LIKE '%" . $conn->real_escape_string($keywordsNative) . "%' 
-             OR cs_alibaba LIKE '%" . $conn->real_escape_string($keywordsNative) . "%' 
-             OR cs_linkedin LIKE '%" . $conn->real_escape_string($keywordsNative) . "%' 
-             OR cs_facebook LIKE '%" . $conn->real_escape_string($keywordsNative) . "%')";
+$searchStr = "SELECT c.cs_code, cc.contact_name as cs_name, c.cs_country, cc.tel as cs_tel, 
+             cc.email as cs_email, cc.whatsapp as cs_whatsapp, cc.wechat as cs_wechat, 
+             cc.linkedin as cs_linkedin, cc.facebook as cs_facebook, c.cs_addtime, 
+             c.cs_from, c.cs_belong, c.cs_deal, cc.alibaba as cs_alibaba 
+             FROM customer c 
+             LEFT JOIN customer_contact cc ON c.id = cc.customer_id
+             WHERE (cc.tel_format LIKE '%" . $conn->real_escape_string($keywords) . "%' 
+             OR cc.email LIKE '%" . $conn->real_escape_string($keywords) . "%' 
+             OR cc.whatsapp_format LIKE '%" . $conn->real_escape_string($keywords) . "%' 
+             OR cc.wechat LIKE '%" . $conn->real_escape_string($keywords) . "%' 
+             OR cc.alibaba LIKE '%" . $conn->real_escape_string($keywords) . "%' 
+             OR cc.linkedin LIKE '%" . $conn->real_escape_string($keywords) . "%' 
+             OR cc.facebook LIKE '%" . $conn->real_escape_string($keywords) . "%' 
+             OR cc.email LIKE '%" . $conn->real_escape_string($keywordsNative) . "%' 
+             OR cc.wechat LIKE '%" . $conn->real_escape_string($keywordsNative) . "%' 
+             OR cc.alibaba LIKE '%" . $conn->real_escape_string($keywordsNative) . "%' 
+             OR cc.linkedin LIKE '%" . $conn->real_escape_string($keywordsNative) . "%' 
+             OR cc.facebook LIKE '%" . $conn->real_escape_string($keywordsNative) . "%')";
 ?>
 <!DOCTYPE html>
 <html xmlns="http://www.w3.org/1999/xhtml">

+ 26 - 24
silentCustomer.php

@@ -47,34 +47,34 @@ $filterStr = "";
 $urlStr = "";
 
 if (!empty($filterCountry)) {
-    $filterStr .= " AND cs_country=" . (int)$filterCountry;
+    $filterStr .= " AND c.cs_country=" . (int)$filterCountry;
     $urlStr .= "&fliterCountry=" . $filterCountry;
 }
 
 if (!empty($filterQudao)) {
-    $filterStr .= " AND cs_from=" . (int)$filterQudao;
+    $filterStr .= " AND c.cs_from=" . (int)$filterQudao;
     $urlStr .= "&fliterQudao=" . $filterQudao;
 }
 
 if (!empty($filterDeal)) {
-    $filterStr .= " AND cs_deal=" . (int)$filterDeal;
+    $filterStr .= " AND c.cs_deal=" . (int)$filterDeal;
     $urlStr .= "&fliterDeal=" . $filterDeal;
 }
 
 if (!empty($filterBusiness)) {
-    $filterStr .= " AND cs_type=" . (int)$filterBusiness;
+    $filterStr .= " AND c.cs_type=" . (int)$filterBusiness;
     $urlStr .= "&fliterBusiness=" . $filterBusiness;
 }
 
 if (!empty($filterContact)) {
     switch ($filterContact) {
-        case "1": $filterStr .= " AND cs_tel<>''"; break;
-        case "2": $filterStr .= " AND cs_wechat<>''"; break;
-        case "3": $filterStr .= " AND cs_whatsapp<>''"; break;
-        case "4": $filterStr .= " AND cs_email<>''"; break;
-        case "5": $filterStr .= " AND cs_linkedin<>''"; break;
-        case "6": $filterStr .= " AND cs_facebook<>''"; break;
-        default: $filterStr .= " AND cs_alibaba<>''";
+        case "1": $filterStr .= " AND cc.tel<>''"; break;
+        case "2": $filterStr .= " AND cc.wechat<>''"; break;
+        case "3": $filterStr .= " AND cc.whatsapp<>''"; break;
+        case "4": $filterStr .= " AND cc.email<>''"; break;
+        case "5": $filterStr .= " AND cc.linkedin<>''"; break;
+        case "6": $filterStr .= " AND cc.facebook<>''"; break;
+        default: $filterStr .= " AND cc.alibaba<>''";
     }
     $urlStr .= "&fliterContact=" . $filterContact;
 }
@@ -194,19 +194,21 @@ $hrefstr = "?keys=" . $keys;
             </div>
 
 <?php
-$sqlStr = "SELECT id, cs_code, cs_from, cs_country, cs_type, cs_deal, cs_addtime, cs_tel, cs_email, 
-           cs_whatsapp, cs_wechat, cs_linkedin, cs_facebook, cs_alibaba, colortag, cs_note, cs_claimFrom, 
-           cs_belong, cs_chain 
-           FROM customer 
-           WHERE (is_silent=1 OR (cs_deal=0 AND cs_belong=" . $_SESSION['employee_id'] . ")) 
-           AND (cs_code LIKE '%" . $conn->real_escape_string($keyscode) . "%' 
-           OR cs_name LIKE '%" . $conn->real_escape_string($keyscode) . "%' 
-           OR cs_email LIKE '%" . $conn->real_escape_string($keyscode) . "%' 
-           OR cs_wechat LIKE '%" . $conn->real_escape_string($keyscode) . "%' 
-           OR cs_telformat LIKE '%" . $conn->real_escape_string($keyscode) . "%' 
-           OR cs_whatsappformat LIKE '%" . $conn->real_escape_string($keyscode) . "%' 
-           OR cs_code LIKE '%" . $conn->real_escape_string($keyscode) . "%')" . 
-           $filterStr . " ORDER BY colortag DESC, id DESC";
+$sqlStr = "SELECT c.id, c.cs_code, c.cs_from, c.cs_country, c.cs_type, c.cs_deal, c.cs_addtime, 
+           cc.tel as cs_tel, cc.email as cs_email, cc.whatsapp as cs_whatsapp, cc.wechat as cs_wechat, 
+           cc.linkedin as cs_linkedin, cc.facebook as cs_facebook, cc.alibaba as cs_alibaba, 
+           c.colortag, c.cs_note, c.cs_claimFrom, c.cs_belong, c.cs_chain 
+           FROM customer c 
+           LEFT JOIN customer_contact cc ON c.id = cc.customer_id
+           WHERE (c.is_silent=1 OR (c.cs_deal=0 AND c.cs_belong=" . $_SESSION['employee_id'] . ")) 
+           AND (c.cs_code LIKE '%" . $conn->real_escape_string($keyscode) . "%' 
+           OR cc.contact_name LIKE '%" . $conn->real_escape_string($keyscode) . "%' 
+           OR cc.email LIKE '%" . $conn->real_escape_string($keyscode) . "%' 
+           OR cc.wechat LIKE '%" . $conn->real_escape_string($keyscode) . "%' 
+           OR cc.tel_format LIKE '%" . $conn->real_escape_string($keyscode) . "%' 
+           OR cc.whatsapp_format LIKE '%" . $conn->real_escape_string($keyscode) . "%' 
+           OR c.cs_code LIKE '%" . $conn->real_escape_string($keyscode) . "%')" . 
+           $filterStr . " ORDER BY c.colortag DESC, c.id DESC";
 
 $result = $conn->query($sqlStr);
 

+ 2 - 2
subTagClound.php

@@ -29,9 +29,9 @@ checkLogin();
         <h1 class="tagCloundHead">自定义标签云</h1>
         <div class="tagArea">
         <?php
-        $result = $conn->query("SELECT tagName, COUNT(DISTINCT cs_code) as count 
+        $result = $conn->query("SELECT tagName, COUNT(DISTINCT c.cs_code) as count 
                                FROM tagtable 
-                               LEFT JOIN customer ON tagtable.customerId=customer.id 
+                               LEFT JOIN customer c ON tagtable.customerId=c.id 
                                WHERE employeeId=" . $_SESSION['employee_id'] . " 
                                GROUP BY tagName");
         

+ 151 - 75
system/customers.php

@@ -15,24 +15,28 @@ if ($act == "save") {
         $isEdit = true;
     }
 
+    // Main customer table fields
     $cs_code = textEncode($_POST['cs_code'] ?? '');
     $cs_company = textEncode($_POST['cs_company'] ?? '');
-    $cs_name = textEncode($_POST['cs_name'] ?? '');
     $cs_belong = intval($_POST['cs_belong'] ?? 0);
     $cs_country = intval($_POST['cs_country'] ?? 0);
     $cs_from = intval($_POST['cs_from'] ?? 0);
-    $cs_tel = textEncode($_POST['cs_tel'] ?? '');
-    $cs_email = textEncode($_POST['cs_email'] ?? '');
-    $cs_whatsapp = textEncode($_POST['cs_whatsapp'] ?? '');
-    $cs_wechat = textEncode($_POST['cs_wechat'] ?? '');
-    $cs_linkedin = textEncode($_POST['cs_linkedin'] ?? '');
-    $cs_facebook = textEncode($_POST['cs_facebook'] ?? '');
-    $cs_alibaba = textEncode($_POST['cs_alibaba'] ?? '');
     $cs_state = intval($_POST['cs_state'] ?? 0);
     $cs_deal = intval($_POST['cs_deal'] ?? 0);
     $no_content = htmlEncode($_POST['no_content'] ?? '');
+    $cs_address = textEncode($_POST['cs_address'] ?? '');
     $allowedit = isset($_POST['allowedit']) ? 1 : 0;
 
+    // Contact fields
+    $contact_name = textEncode($_POST['cs_name'] ?? '');
+    $tel = textEncode($_POST['cs_tel'] ?? '');
+    $email = textEncode($_POST['cs_email'] ?? '');
+    $whatsapp = textEncode($_POST['cs_whatsapp'] ?? '');
+    $wechat = textEncode($_POST['cs_wechat'] ?? '');
+    $linkedin = textEncode($_POST['cs_linkedin'] ?? '');
+    $facebook = textEncode($_POST['cs_facebook'] ?? '');
+    $alibaba = textEncode($_POST['cs_alibaba'] ?? '');
+
     if ($isEdit) {
         $sql = "SELECT cs_chain FROM customer WHERE id=" . $id;
         $result = $conn->query($sql);
@@ -46,30 +50,56 @@ if ($act == "save") {
                 $cs_chain .= ",$cs_belong";
             }
             
+            // Update customer table
             $sql = "UPDATE customer SET 
                 cs_code='$cs_code', 
                 cs_company='$cs_company', 
-                cs_name='$cs_name',
                 cs_belong=$cs_belong,
                 cs_country=$cs_country,
                 cs_from=$cs_from,
-                cs_tel='$cs_tel',
-                cs_email='$cs_email',
-                cs_whatsapp='$cs_whatsapp',
-                cs_wechat='$cs_wechat',
-                cs_linkedin='$cs_linkedin',
-                cs_facebook='$cs_facebook',
-                cs_alibaba='$cs_alibaba',
                 cs_state=$cs_state,
                 cs_deal=$cs_deal,
                 cs_note='$no_content',
+                cs_address='$cs_address',
                 allowedit=$allowedit,
                 cs_chain='$cs_chain',
                 cs_updatetime=NOW()
                 WHERE id=$id";
-
             $conn->query($sql);
 
+            // Check if contact exists for this customer
+            $sql = "SELECT id FROM customer_contact WHERE customer_id=$id";
+            $contact_result = $conn->query($sql);
+            
+            if ($contact_result->num_rows > 0) {
+                $contact_row = $contact_result->fetch_assoc();
+                $contact_id = $contact_row['id'];
+                
+                // Update existing contact
+                $sql = "UPDATE customer_contact SET 
+                    contact_name='$contact_name',
+                    tel='$tel',
+                    email='$email',
+                    whatsapp='$whatsapp',
+                    wechat='$wechat',
+                    linkedin='$linkedin',
+                    facebook='$facebook',
+                    alibaba='$alibaba',
+                    updated_at=NOW()
+                    WHERE id=$contact_id";
+                $conn->query($sql);
+            } else {
+                // Create new contact for existing customer
+                $sql = "INSERT INTO customer_contact (
+                    customer_id, contact_name, tel, email, whatsapp, wechat, 
+                    linkedin, facebook, alibaba, created_at, updated_at
+                ) VALUES (
+                    $id, '$contact_name', '$tel', '$email', '$whatsapp', '$wechat',
+                    '$linkedin', '$facebook', '$alibaba', NOW(), NOW()
+                )";
+                $conn->query($sql);
+            }
+
             $page = $_GET['Page'] ?? '';
             $keys = urlencode($_GET['Keys'] ?? '');
             header("Location: ?keys=$keys&Page=$page$urlStr");
@@ -78,21 +108,43 @@ if ($act == "save") {
             $output = "<script>alert('不存在该客户');history.back();</script>";
         }
     } else {
-        $sql = "INSERT INTO customer (
-            cs_code, cs_company, cs_name, cs_belong, cs_country, cs_from,
-            cs_tel, cs_email, cs_whatsapp, cs_wechat, cs_linkedin,
-            cs_facebook, cs_alibaba, cs_state, cs_deal, cs_note,
-            allowedit, cs_chain, cs_addtime, cs_updatetime
-        ) VALUES (
-            '$cs_code', '$cs_company', '$cs_name', $cs_belong, $cs_country, $cs_from,
-            '$cs_tel', '$cs_email', '$cs_whatsapp', '$cs_wechat', '$cs_linkedin',
-            '$cs_facebook', '$cs_alibaba', $cs_state, $cs_deal, '$no_content',
-            $allowedit, '$cs_belong', NOW(), NOW()
-        )";
+        // Begin transaction
+        $conn->begin_transaction();
         
-        $conn->query($sql);
-        header("Location: ?");
-        exit;
+        try {
+            // Insert into customer table
+            $sql = "INSERT INTO customer (
+                cs_code, cs_company, cs_belong, cs_country, cs_from,
+                cs_state, cs_deal, cs_note, cs_address,
+                allowedit, cs_chain, cs_addtime, cs_updatetime
+            ) VALUES (
+                '$cs_code', '$cs_company', $cs_belong, $cs_country, $cs_from,
+                $cs_state, $cs_deal, '$no_content', '$cs_address',
+                $allowedit, '$cs_belong', NOW(), NOW()
+            )";
+            
+            $conn->query($sql);
+            $new_customer_id = $conn->insert_id;
+            
+            // Insert into customer_contact table
+            $sql = "INSERT INTO customer_contact (
+                customer_id, contact_name, tel, email, whatsapp, wechat, 
+                linkedin, facebook, alibaba, created_at, updated_at
+            ) VALUES (
+                $new_customer_id, '$contact_name', '$tel', '$email', '$whatsapp', '$wechat',
+                '$linkedin', '$facebook', '$alibaba', NOW(), NOW()
+            )";
+            $conn->query($sql);
+            
+            // Commit transaction
+            $conn->commit();
+            header("Location: ?");
+            exit;
+        } catch (Exception $e) {
+            // Rollback on failure
+            $conn->rollback();
+            $output = "<script>alert('保存失败: " . $e->getMessage() . "');history.back();</script>";
+        }
     }
 }
 
@@ -149,32 +201,36 @@ if ($act == "edit" || $act == "add") {
     if (!empty($id) && is_numeric($id)) {
         $isEdit = true;
         
-        $sql = "SELECT c.*, n.c_code 
+        // Join customer and customer_contact tables
+        $sql = "SELECT c.*, cc.contact_name, cc.tel, cc.tel_bu, cc.email, cc.email_bu,
+                cc.whatsapp, cc.whatsapp_bu, cc.wechat, cc.wechat_bu, 
+                cc.linkedin, cc.linkedin_bu, cc.facebook, cc.facebook_bu,
+                cc.alibaba, cc.alibaba_bu
                 FROM customer c 
-                LEFT JOIN mynote n ON c.cs_code = n.c_code 
+                LEFT JOIN customer_contact cc ON c.id = cc.customer_id
                 WHERE c.id=$id";
         $result = $conn->query($sql);
         
         if ($row = $result->fetch_assoc()) {
             $cs_code = textUncode($row['cs_code']);
             $cs_company = textUncode($row['cs_company']);
-            $cs_name = textUncode($row['cs_name']);
+            $cs_name = textUncode($row['contact_name']);
             $cs_country = $row['cs_country'];
             $cs_from = $row['cs_from'];
-            $cs_tel = textUncode($row['cs_tel']);
-            $cs_telBu = textUncode($row['cs_telBu']);
-            $cs_wechat = textUncode($row['cs_wechat']);
-            $cs_wechatBu = textUncode($row['cs_wechatBu']);
-            $cs_whatsapp = textUncode($row['cs_whatsapp']);
-            $cs_whatsappBu = textUncode($row['cs_whatsappBu']);
-            $cs_email = textUncode($row['cs_email']);
-            $cs_emailBu = textUncode($row['cs_emailBu']);
-            $cs_linkedin = textUncode($row['cs_linkedin']);
-            $cs_linkedinBu = textUncode($row['cs_linkedinBu']);
-            $cs_facebook = textUncode($row['cs_facebook']);
-            $cs_facebookBu = textUncode($row['cs_facebookBu']);
-            $cs_alibaba = textUncode($row['cs_alibaba']);
-            $cs_alibabaBu = textUncode($row['cs_alibabaBu']);
+            $cs_tel = textUncode($row['tel']);
+            $cs_telBu = textUncode($row['tel_bu']);
+            $cs_wechat = textUncode($row['wechat']);
+            $cs_wechatBu = textUncode($row['wechat_bu']);
+            $cs_whatsapp = textUncode($row['whatsapp']);
+            $cs_whatsappBu = textUncode($row['whatsapp_bu']);
+            $cs_email = textUncode($row['email']);
+            $cs_emailBu = textUncode($row['email_bu']);
+            $cs_linkedin = textUncode($row['linkedin']);
+            $cs_linkedinBu = textUncode($row['linkedin_bu']);
+            $cs_facebook = textUncode($row['facebook']);
+            $cs_facebookBu = textUncode($row['facebook_bu']);
+            $cs_alibaba = textUncode($row['alibaba']);
+            $cs_alibabaBu = textUncode($row['alibaba_bu']);
             $cs_address = textUncode($row['cs_address']);
             $cs_addtime = $row['cs_addtime'];
             $cs_updatetime = $row['cs_updatetime'];
@@ -366,9 +422,26 @@ if ($act == "postchk") {
                     $sql = "UPDATE customer SET cs_state=$chkact WHERE id IN ($idList)";
                     break;
                 default:
-                    $sql = "DELETE FROM customer WHERE id IN ($idList)";
+                    // In delete case, let's use transactions to ensure both tables are updated
+                    $conn->begin_transaction();
+                    try {
+                        // Delete from customer_contact first (due to foreign key constraint)
+                        $sql = "DELETE FROM customer_contact WHERE customer_id IN ($idList)";
+                        $conn->query($sql);
+                        
+                        // Then delete from customer table
+                        $sql = "DELETE FROM customer WHERE id IN ($idList)";
+                        $conn->query($sql);
+                        
+                        $conn->commit();
+                    } catch (Exception $e) {
+                        $conn->rollback();
+                        echo "<script>alert('删除失败: " . $e->getMessage() . "');</script>";
+                    }
+            }
+            if ($chkact == "0" || $chkact == "1") {
+                $conn->query($sql);
             }
-            $conn->query($sql);
         }
     }
     
@@ -387,35 +460,35 @@ $filterStr = "";
 $urlStr = "";
 
 if (!empty($fliterQudao)) {
-    $filterStr .= " AND cs_from=" . intval($fliterQudao);
+    $filterStr .= " AND c.cs_from=" . intval($fliterQudao);
     $urlStr .= "&fliterQudao=$fliterQudao";
 }
 
 if (!empty($fliterDeal)) {
-    $filterStr .= " AND cs_deal=" . intval($fliterDeal);
+    $filterStr .= " AND c.cs_deal=" . intval($fliterDeal);
     $urlStr .= "&fliterDeal=$fliterDeal";
 }
 
 if (!empty($fliterTeam)) {
-    $filterStr .= " AND (cs_belong=" . intval($fliterTeam) . 
-                 " OR cs_belong IN (SELECT id FROM employee WHERE em_role=" . intval($fliterTeam) . "))";
+    $filterStr .= " AND (c.cs_belong=" . intval($fliterTeam) . 
+                 " OR c.cs_belong IN (SELECT id FROM employee WHERE em_role=" . intval($fliterTeam) . "))";
     $urlStr .= "&fliterTeam=$fliterTeam";
 }
 
 if (!empty($fliterEmployee)) {
-    $filterStr .= " AND cs_belong=" . intval($fliterEmployee);
+    $filterStr .= " AND c.cs_belong=" . intval($fliterEmployee);
     $urlStr .= "&fliterEmployee=$fliterEmployee";
 }
 
 if (!empty($fliterContact)) {
     switch($fliterContact) {
-        case "1": $filterStr .= " AND cs_tel<>''"; break;
-        case "2": $filterStr .= " AND cs_wechat<>''"; break;
-        case "3": $filterStr .= " AND cs_whatsapp<>''"; break;
-        case "4": $filterStr .= " AND cs_email<>''"; break;
-        case "5": $filterStr .= " AND cs_linkedin<>''"; break;
-        case "6": $filterStr .= " AND cs_facebook<>''"; break;
-        default: $filterStr .= " AND cs_alibaba<>''";
+        case "1": $filterStr .= " AND cc.tel<>''"; break;
+        case "2": $filterStr .= " AND cc.wechat<>''"; break;
+        case "3": $filterStr .= " AND cc.whatsapp<>''"; break;
+        case "4": $filterStr .= " AND cc.email<>''"; break;
+        case "5": $filterStr .= " AND cc.linkedin<>''"; break;
+        case "6": $filterStr .= " AND cc.facebook<>''"; break;
+        default: $filterStr .= " AND cc.alibaba<>''";
     }
     $urlStr .= "&fliterContact=$fliterContact";
 }
@@ -425,20 +498,23 @@ $keyscode = textEncode($keys);
 $page = $_GET['Page'] ?? '';
 $ord = $_GET['Ord'] ?? '';
 
-$sql = "SELECT id, cs_code, cs_name, cs_country, cs_address, cs_tel, cs_email, 
-        cs_whatsapp, cs_wechat, cs_linkedin, cs_facebook, cs_addtime, 
-        cs_alibaba, cs_from, cs_deal, cs_updatetime, cs_belong, cs_note, 
-        cs_claimFrom, cs_chain, cs_dealdate 
-        FROM customer 
-        WHERE (cs_code LIKE '%$keyscode%' 
-        OR cs_name LIKE '%$keyscode%' 
-        OR cs_wechat LIKE '%$keyscode%'
-        OR cs_alibaba LIKE '%$keyscode%' 
-        OR cs_telformat LIKE '%$keyscode%' 
-        OR cs_whatsappformat LIKE '%$keyscode%'
-        OR cs_email LIKE '%$keyscode%') 
+$sql = "SELECT c.id, c.cs_code, c.cs_company, c.cs_country, c.cs_address, 
+        c.cs_from, c.cs_deal, c.cs_addtime, c.cs_updatetime, c.cs_belong, c.cs_note, 
+        c.cs_claimFrom, c.cs_chain, c.cs_dealdate,
+        cc.contact_name as cs_name, cc.tel as cs_tel, cc.email as cs_email, 
+        cc.whatsapp as cs_whatsapp, cc.wechat as cs_wechat, cc.linkedin as cs_linkedin, 
+        cc.facebook as cs_facebook, cc.alibaba as cs_alibaba
+        FROM customer c 
+        LEFT JOIN customer_contact cc ON c.id = cc.customer_id
+        WHERE (c.cs_code LIKE '%$keyscode%' 
+        OR cc.contact_name LIKE '%$keyscode%' 
+        OR cc.wechat LIKE '%$keyscode%'
+        OR cc.alibaba LIKE '%$keyscode%' 
+        OR cc.tel LIKE '%$keyscode%' 
+        OR cc.whatsapp LIKE '%$keyscode%'
+        OR cc.email LIKE '%$keyscode%') 
         $filterStr 
-        ORDER BY cs_updatetime DESC";
+        ORDER BY c.cs_updatetime DESC";
 
 $result = $conn->query($sql);
 ?>

+ 26 - 26
team.php

@@ -79,33 +79,33 @@ if (empty($dateend) || !strtotime($dateend)) {
                 $clstr = "";
                 
                 // Get total customer count
-                $c1Result = $conn->query("SELECT COUNT(DISTINCT cs_code) as c1 FROM customer WHERE cs_belong=" . $row['id']);
+                $c1Result = $conn->query("SELECT COUNT(DISTINCT c.cs_code) as c1 FROM customer c WHERE c.cs_belong=" . $row['id']);
                 $c1Row = $c1Result->fetch_assoc();
                 $c1 = $c1Row['c1'];
 
                 // Get customers going to public sea
-                $c2Result = $conn->query("SELECT COUNT(id) as c2 FROM customer 
-                                        WHERE cs_deal<>3 AND cs_deal<>0 AND cs_type<>2 
-                                        AND DATEDIFF(NOW(), cs_updatetime) > 90 
-                                        AND cs_belongclient=0 AND cs_belong=" . $row['id']);
+                $c2Result = $conn->query("SELECT COUNT(c.id) as c2 FROM customer c
+                                        WHERE c.cs_deal<>3 AND c.cs_deal<>0 AND c.cs_type<>2 
+                                        AND DATEDIFF(NOW(), c.cs_updatetime) > 90 
+                                        AND c.cs_belongclient=0 AND c.cs_belong=" . $row['id']);
                 $c2Row = $c2Result->fetch_assoc();
                 $c2 = $c2Row['c2'];
 
                 // Get deals in date range
-                $c3Result = $conn->query("SELECT DISTINCT cs_code FROM customer 
-                                        WHERE cs_dealdate > '" . $conn->real_escape_string($datestart) . "' 
-                                        AND cs_dealdate <= '" . $conn->real_escape_string($dateend) . "' 
-                                        AND cs_deal=3 AND cs_belong=" . $row['id']);
+                $c3Result = $conn->query("SELECT DISTINCT c.cs_code FROM customer c
+                                        WHERE c.cs_dealdate > '" . $conn->real_escape_string($datestart) . "' 
+                                        AND c.cs_dealdate <= '" . $conn->real_escape_string($dateend) . "' 
+                                        AND c.cs_deal=3 AND c.cs_belong=" . $row['id']);
                 $c3 = $c3Result->num_rows;
                 while ($c3Row = $c3Result->fetch_assoc()) {
                     $clstr .= $c3Row['cs_code'] . "<br>";
                 }
 
                 // Get claimed customers count
-                $c4Result = $conn->query("SELECT COUNT(DISTINCT cs_code) as c4 FROM customer 
-                                        WHERE cs_claimdate > '" . $conn->real_escape_string($datestart) . "' 
-                                        AND cs_claimdate <= '" . $conn->real_escape_string($dateend) . "' 
-                                        AND cs_belong=" . $row['id']);
+                $c4Result = $conn->query("SELECT COUNT(DISTINCT c.cs_code) as c4 FROM customer c
+                                        WHERE c.cs_claimdate > '" . $conn->real_escape_string($datestart) . "' 
+                                        AND c.cs_claimdate <= '" . $conn->real_escape_string($dateend) . "' 
+                                        AND c.cs_belong=" . $row['id']);
                 $c4Row = $c4Result->fetch_assoc();
                 $c4 = $c4Row['c4'];
 
@@ -129,33 +129,33 @@ if (empty($dateend) || !strtotime($dateend)) {
                     $clstr = "";
                     
                     // Get member's total customer count
-                    $mc1Result = $conn->query("SELECT COUNT(DISTINCT cs_code) as c1 FROM customer WHERE cs_belong=" . $memberRow['id']);
+                    $mc1Result = $conn->query("SELECT COUNT(DISTINCT c.cs_code) as c1 FROM customer c WHERE c.cs_belong=" . $memberRow['id']);
                     $mc1Row = $mc1Result->fetch_assoc();
                     $mc1 = $mc1Row['c1'];
 
                     // Get member's customers going to public sea
-                    $mc2Result = $conn->query("SELECT COUNT(DISTINCT cs_code) as c2 FROM customer 
-                                             WHERE cs_deal<>3 AND cs_deal<>0 AND cs_type<>2 
-                                             AND DATEDIFF(NOW(), cs_updatetime) > 90 
-                                             AND cs_belongclient=0 AND cs_belong=" . $memberRow['id']);
+                    $mc2Result = $conn->query("SELECT COUNT(DISTINCT c.cs_code) as c2 FROM customer c
+                                             WHERE c.cs_deal<>3 AND c.cs_deal<>0 AND c.cs_type<>2 
+                                             AND DATEDIFF(NOW(), c.cs_updatetime) > 90 
+                                             AND c.cs_belongclient=0 AND c.cs_belong=" . $memberRow['id']);
                     $mc2Row = $mc2Result->fetch_assoc();
                     $mc2 = $mc2Row['c2'];
 
                     // Get member's deals in date range
-                    $mc3Result = $conn->query("SELECT DISTINCT cs_code FROM customer 
-                                             WHERE cs_dealdate > '" . $conn->real_escape_string($datestart) . "' 
-                                             AND cs_dealdate <= '" . $conn->real_escape_string($dateend) . "' 
-                                             AND cs_deal=3 AND cs_belong=" . $memberRow['id']);
+                    $mc3Result = $conn->query("SELECT DISTINCT c.cs_code FROM customer c
+                                             WHERE c.cs_dealdate > '" . $conn->real_escape_string($datestart) . "' 
+                                             AND c.cs_dealdate <= '" . $conn->real_escape_string($dateend) . "' 
+                                             AND c.cs_deal=3 AND c.cs_belong=" . $memberRow['id']);
                     $mc3 = $mc3Result->num_rows;
                     while ($mc3Row = $mc3Result->fetch_assoc()) {
                         $clstr .= $mc3Row['cs_code'] . "<br>";
                     }
 
                     // Get member's claimed customers count
-                    $mc4Result = $conn->query("SELECT COUNT(id) as c4 FROM customer 
-                                             WHERE cs_claimdate > '" . $conn->real_escape_string($datestart) . "' 
-                                             AND cs_claimdate <= '" . $conn->real_escape_string($dateend) . "' 
-                                             AND cs_belong=" . $memberRow['id']);
+                    $mc4Result = $conn->query("SELECT COUNT(c.id) as c4 FROM customer c
+                                             WHERE c.cs_claimdate > '" . $conn->real_escape_string($datestart) . "' 
+                                             AND c.cs_claimdate <= '" . $conn->real_escape_string($dateend) . "' 
+                                             AND c.cs_belong=" . $memberRow['id']);
                     $mc4Row = $mc4Result->fetch_assoc();
                     $mc4 = $mc4Row['c4'];
             ?>

+ 23 - 19
teamSeas.php

@@ -17,27 +17,27 @@ $filterStr = "";
 $urlStr = "";
 
 if (!empty($filterCountry)) {
-    $filterStr .= " AND cs_country=" . (int)$filterCountry;
+    $filterStr .= " AND c.cs_country=" . (int)$filterCountry;
     $urlStr .= "&fliterCountry=" . $filterCountry;
 }
 
 if (!empty($filterQudao)) {
-    $filterStr .= " AND cs_from=" . (int)$filterQudao;
+    $filterStr .= " AND c.cs_from=" . (int)$filterQudao;
     $urlStr .= "&fliterQudao=" . $filterQudao;
 }
 
 if (!empty($filterDeal)) {
-    $filterStr .= " AND cs_deal=" . (int)$filterDeal;
+    $filterStr .= " AND c.cs_deal=" . (int)$filterDeal;
     $urlStr .= "&fliterDeal=" . $filterDeal;
 }
 
 if (!empty($filterBusiness)) {
-    $filterStr .= " AND cs_type=" . (int)$filterBusiness;
+    $filterStr .= " AND c.cs_type=" . (int)$filterBusiness;
     $urlStr .= "&fliterBusiness=" . $filterBusiness;
 }
 
 if (!empty($filterBelong)) {
-    $filterStr .= " AND cs_belong=" . (int)$filterBelong;
+    $filterStr .= " AND c.cs_belong=" . (int)$filterBelong;
     $urlStr .= "&fliterBelong=" . $filterBelong;
 }
 
@@ -154,20 +154,24 @@ if ($_SESSION['em_role'] == 0) {
             </div>
 
             <?php
-            $sqlStr = "SELECT * FROM customer 
-                      WHERE cs_deal<>3 AND cs_type<>2 
-                      AND DATEDIFF(NOW(), cs_updatetime) > 60 
-                      AND cs_wechat NOT LIKE 'wxid%' 
-                      AND cs_belongclient=0 
-                      AND cs_belong<>" . $_SESSION['employee_id'] . " 
-                      AND cs_belong IN (" . $memberStr . ") 
-                      AND (cs_code LIKE '%" . $conn->real_escape_string($keyscode) . "%' 
-                      OR cs_name LIKE '%" . $conn->real_escape_string($keyscode) . "%' 
-                      OR cs_email LIKE '%" . $conn->real_escape_string($keyscode) . "%' 
-                      OR cs_wechat LIKE '%" . $conn->real_escape_string($keyscode) . "%' 
-                      OR cs_tel LIKE '%" . $conn->real_escape_string($keyscode) . "%' 
-                      OR cs_whatsapp LIKE '%" . $conn->real_escape_string($keyscode) . "%')" . 
-                      $filterStr . " ORDER BY cs_state DESC, id DESC";
+            $sqlStr = "SELECT c.*, cc.contact_name as cs_name, cc.tel as cs_tel, cc.email as cs_email,
+                      cc.whatsapp as cs_whatsapp, cc.wechat as cs_wechat, cc.linkedin as cs_linkedin,
+                      cc.facebook as cs_facebook, cc.alibaba as cs_alibaba
+                      FROM customer c 
+                      LEFT JOIN customer_contact cc ON c.id = cc.customer_id
+                      WHERE c.cs_deal<>3 AND c.cs_type<>2 
+                      AND DATEDIFF(NOW(), c.cs_updatetime) > 60 
+                      AND cc.wechat NOT LIKE 'wxid%' 
+                      AND c.cs_belongclient=0 
+                      AND c.cs_belong<>" . $_SESSION['employee_id'] . " 
+                      AND c.cs_belong IN (" . $memberStr . ") 
+                      AND (c.cs_code LIKE '%" . $conn->real_escape_string($keyscode) . "%' 
+                      OR cc.contact_name LIKE '%" . $conn->real_escape_string($keyscode) . "%' 
+                      OR cc.email LIKE '%" . $conn->real_escape_string($keyscode) . "%' 
+                      OR cc.wechat LIKE '%" . $conn->real_escape_string($keyscode) . "%' 
+                      OR cc.tel LIKE '%" . $conn->real_escape_string($keyscode) . "%' 
+                      OR cc.whatsapp LIKE '%" . $conn->real_escape_string($keyscode) . "%')" . 
+                      $filterStr . " ORDER BY c.cs_state DESC, c.id DESC";
 
             $result = $conn->query($sqlStr);