|
@@ -26,24 +26,36 @@ if ($act == "save") {
|
|
|
$isedit = true;
|
|
|
}
|
|
|
|
|
|
- // 获取表单数据
|
|
|
+ // 获取表单数据 - 客户基本信息
|
|
|
$cs_code = textEncode($_POST['cs_code']);
|
|
|
$cs_company = textEncode($_POST['cs_company']);
|
|
|
- $cs_name = textEncode($_POST['cs_name']);
|
|
|
$cs_belong = $_POST['cs_belong'];
|
|
|
$cs_country = $_POST['cs_country'];
|
|
|
$cs_from = $_POST['cs_from'];
|
|
|
- $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 = $_POST['cs_state'];
|
|
|
$cs_deal = $_POST['cs_deal'];
|
|
|
$no_content = htmlEncode($_POST['no_content']);
|
|
|
$allowedit = isset($_POST['allowedit']) ? 1 : 0;
|
|
|
+ $cs_address = textEncode($_POST['cs_address'] ?? '');
|
|
|
+
|
|
|
+ // 获取表单数据 - 联系人信息
|
|
|
+ $contact_name = textEncode($_POST['cs_name']);
|
|
|
+ $tel = textEncode($_POST['cs_tel']);
|
|
|
+ $tel_format = textEncode($_POST['cs_telformat'] ?? '');
|
|
|
+ $tel_bu = textEncode($_POST['cs_telBu'] ?? '');
|
|
|
+ $email = textEncode($_POST['cs_email']);
|
|
|
+ $email_bu = textEncode($_POST['cs_emailBu'] ?? '');
|
|
|
+ $whatsapp = textEncode($_POST['cs_whatsapp']);
|
|
|
+ $whatsapp_format = textEncode($_POST['cs_whatsappformat'] ?? '');
|
|
|
+ $whatsapp_bu = textEncode($_POST['cs_whatsappBu'] ?? '');
|
|
|
+ $wechat = textEncode($_POST['cs_wechat']);
|
|
|
+ $wechat_bu = textEncode($_POST['cs_wechatBu'] ?? '');
|
|
|
+ $linkedin = textEncode($_POST['cs_linkedin']);
|
|
|
+ $linkedin_bu = textEncode($_POST['cs_linkedinBu'] ?? '');
|
|
|
+ $facebook = textEncode($_POST['cs_facebook']);
|
|
|
+ $facebook_bu = textEncode($_POST['cs_facebookBu'] ?? '');
|
|
|
+ $alibaba = textEncode($_POST['cs_alibaba']);
|
|
|
+ $alibaba_bu = textEncode($_POST['cs_alibabaBu'] ?? '');
|
|
|
|
|
|
if ($isedit) {
|
|
|
// 更新现有记录
|
|
@@ -58,20 +70,14 @@ if ($act == "save") {
|
|
|
$cs_chain .= ",$cs_belong";
|
|
|
}
|
|
|
|
|
|
+ // 更新客户基本信息
|
|
|
$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_address = '$cs_address',
|
|
|
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',
|
|
@@ -82,6 +88,85 @@ if ($act == "save") {
|
|
|
|
|
|
mysqli_query($conn, $sql);
|
|
|
|
|
|
+ // 检查是否已有联系人记录
|
|
|
+ $contact_sql = "SELECT id FROM customer_contact WHERE customer_id = $id";
|
|
|
+ $contact_result = mysqli_query($conn, $contact_sql);
|
|
|
+
|
|
|
+ if ($contact_row = mysqli_fetch_assoc($contact_result)) {
|
|
|
+ // 更新联系人信息
|
|
|
+ $contact_id = $contact_row['id'];
|
|
|
+ $sql = "UPDATE customer_contact SET
|
|
|
+ contact_name = '$contact_name',
|
|
|
+ tel = '$tel',
|
|
|
+ tel_format = '$tel_format',
|
|
|
+ tel_bu = '$tel_bu',
|
|
|
+ email = '$email',
|
|
|
+ email_bu = '$email_bu',
|
|
|
+ whatsapp = '$whatsapp',
|
|
|
+ whatsapp_format = '$whatsapp_format',
|
|
|
+ whatsapp_bu = '$whatsapp_bu',
|
|
|
+ wechat = '$wechat',
|
|
|
+ wechat_bu = '$wechat_bu',
|
|
|
+ linkedin = '$linkedin',
|
|
|
+ linkedin_bu = '$linkedin_bu',
|
|
|
+ facebook = '$facebook',
|
|
|
+ facebook_bu = '$facebook_bu',
|
|
|
+ alibaba = '$alibaba',
|
|
|
+ alibaba_bu = '$alibaba_bu',
|
|
|
+ updated_at = NOW()
|
|
|
+ WHERE id = $contact_id";
|
|
|
+ mysqli_query($conn, $sql);
|
|
|
+ } else {
|
|
|
+ // 插入新的联系人记录
|
|
|
+ $sql = "INSERT INTO customer_contact (
|
|
|
+ customer_id, contact_name, tel, tel_format, tel_bu,
|
|
|
+ email, email_bu, whatsapp, whatsapp_format, whatsapp_bu,
|
|
|
+ wechat, wechat_bu, linkedin, linkedin_bu, facebook,
|
|
|
+ facebook_bu, alibaba, alibaba_bu, created_at, updated_at
|
|
|
+ ) VALUES (
|
|
|
+ $id, '$contact_name', '$tel', '$tel_format', '$tel_bu',
|
|
|
+ '$email', '$email_bu', '$whatsapp', '$whatsapp_format', '$whatsapp_bu',
|
|
|
+ '$wechat', '$wechat_bu', '$linkedin', '$linkedin_bu', '$facebook',
|
|
|
+ '$facebook_bu', '$alibaba', '$alibaba_bu', NOW(), NOW()
|
|
|
+ )";
|
|
|
+ mysqli_query($conn, $sql);
|
|
|
+ }
|
|
|
+
|
|
|
+ $page = $_GET['Page'] ?? '';
|
|
|
+ $keys = urlencode($_GET['Keys'] ?? '');
|
|
|
+ header("Location: ?keys=$keys&Page=$page$urlStr");
|
|
|
+ exit;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 创建新记录
|
|
|
+ // 插入客户基本信息
|
|
|
+ $sql = "INSERT INTO customer (
|
|
|
+ cs_code, cs_company, cs_country, cs_address, cs_from,
|
|
|
+ cs_belong, cs_state, cs_deal, cs_note, allowedit,
|
|
|
+ cs_chain, cs_addtime, cs_updatetime
|
|
|
+ ) VALUES (
|
|
|
+ '$cs_code', '$cs_company', '$cs_country', '$cs_address', '$cs_from',
|
|
|
+ '$cs_belong', '$cs_state', '$cs_deal', '$no_content', $allowedit,
|
|
|
+ '$cs_belong', NOW(), NOW()
|
|
|
+ )";
|
|
|
+ mysqli_query($conn, $sql);
|
|
|
+ $new_customer_id = mysqli_insert_id($conn);
|
|
|
+
|
|
|
+ // 插入联系人信息
|
|
|
+ if ($new_customer_id > 0) {
|
|
|
+ $sql = "INSERT INTO customer_contact (
|
|
|
+ customer_id, contact_name, tel, tel_format, tel_bu,
|
|
|
+ email, email_bu, whatsapp, whatsapp_format, whatsapp_bu,
|
|
|
+ wechat, wechat_bu, linkedin, linkedin_bu, facebook,
|
|
|
+ facebook_bu, alibaba, alibaba_bu, created_at, updated_at
|
|
|
+ ) VALUES (
|
|
|
+ $new_customer_id, '$contact_name', '$tel', '$tel_format', '$tel_bu',
|
|
|
+ '$email', '$email_bu', '$whatsapp', '$whatsapp_format', '$whatsapp_bu',
|
|
|
+ '$wechat', '$wechat_bu', '$linkedin', '$linkedin_bu', '$facebook',
|
|
|
+ '$facebook_bu', '$alibaba', '$alibaba_bu', NOW(), NOW()
|
|
|
+ )";
|
|
|
+ mysqli_query($conn, $sql);
|
|
|
+
|
|
|
$page = $_GET['Page'] ?? '';
|
|
|
$keys = urlencode($_GET['Keys'] ?? '');
|
|
|
header("Location: ?keys=$keys&Page=$page$urlStr");
|
|
@@ -99,30 +184,35 @@ if ($act == "edit") {
|
|
|
}
|
|
|
|
|
|
if ($isedit) {
|
|
|
- $sql = "SELECT c.*, n.c_code FROM customer c
|
|
|
- LEFT JOIN mynote n ON c.cs_code = n.c_code
|
|
|
+ // 联合查询客户基本信息和联系人信息
|
|
|
+ $sql = "SELECT c.*, cc.contact_name, cc.tel, cc.tel_format, cc.tel_bu,
|
|
|
+ cc.email, cc.email_bu, cc.whatsapp, cc.whatsapp_format, cc.whatsapp_bu,
|
|
|
+ cc.wechat, cc.wechat_bu, cc.linkedin, cc.linkedin_bu, cc.facebook,
|
|
|
+ cc.facebook_bu, cc.alibaba, cc.alibaba_bu, n.c_code
|
|
|
+ FROM customer c
|
|
|
+ LEFT JOIN customer_contact cc ON c.id = cc.customer_id
|
|
|
WHERE c.id = $id";
|
|
|
$result = mysqli_query($conn, $sql);
|
|
|
if ($row = mysqli_fetch_assoc($result)) {
|
|
|
$cs_code = textDecode($row['cs_code']);
|
|
|
$cs_company = textDecode($row['cs_company']);
|
|
|
- $cs_name = textDecode($row['cs_name']);
|
|
|
+ $cs_name = textDecode($row['contact_name']);
|
|
|
$cs_country = $row['cs_country'];
|
|
|
$cs_from = $row['cs_from'];
|
|
|
- $cs_tel = textDecode($row['cs_tel']);
|
|
|
- $cs_telBu = textDecode($row['cs_telBu']);
|
|
|
- $cs_email = textDecode($row['cs_email']);
|
|
|
- $cs_emailBu = textDecode($row['cs_emailBu']);
|
|
|
- $cs_whatsapp = textDecode($row['cs_whatsapp']);
|
|
|
- $cs_whatsappBu = textDecode($row['cs_whatsappBu']);
|
|
|
- $cs_wechat = textDecode($row['cs_wechat']);
|
|
|
- $cs_wechatBu = textDecode($row['cs_wechatBu']);
|
|
|
- $cs_linkedin = textDecode($row['cs_linkedin']);
|
|
|
- $cs_linkedinBu = textDecode($row['cs_linkedinBu']);
|
|
|
- $cs_facebook = textDecode($row['cs_facebook']);
|
|
|
- $cs_facebookBu = textDecode($row['cs_facebookBu']);
|
|
|
- $cs_alibaba = textDecode($row['cs_alibaba']);
|
|
|
- $cs_alibabaBu = textDecode($row['cs_alibabaBu']);
|
|
|
+ $cs_tel = textDecode($row['tel']);
|
|
|
+ $cs_telBu = textDecode($row['tel_bu']);
|
|
|
+ $cs_email = textDecode($row['email']);
|
|
|
+ $cs_emailBu = textDecode($row['email_bu']);
|
|
|
+ $cs_whatsapp = textDecode($row['whatsapp']);
|
|
|
+ $cs_whatsappBu = textDecode($row['whatsapp_bu']);
|
|
|
+ $cs_wechat = textDecode($row['wechat']);
|
|
|
+ $cs_wechatBu = textDecode($row['wechat_bu']);
|
|
|
+ $cs_linkedin = textDecode($row['linkedin']);
|
|
|
+ $cs_linkedinBu = textDecode($row['linkedin_bu']);
|
|
|
+ $cs_facebook = textDecode($row['facebook']);
|
|
|
+ $cs_facebookBu = textDecode($row['facebook_bu']);
|
|
|
+ $cs_alibaba = textDecode($row['alibaba']);
|
|
|
+ $cs_alibabaBu = textDecode($row['alibaba_bu']);
|
|
|
$cs_address = textDecode($row['cs_address']);
|
|
|
$cs_addtime = $row['cs_addtime'];
|
|
|
$cs_updatetime = $row['cs_updatetime'];
|
|
@@ -147,6 +237,7 @@ if ($act == "postchk") {
|
|
|
$sql = "UPDATE customer SET cs_state = $chkact WHERE id IN ($ids)";
|
|
|
break;
|
|
|
case "-1":
|
|
|
+ // 删除客户记录和联系人记录(依靠外键级联删除)
|
|
|
$sql = "DELETE FROM customer WHERE id IN ($ids)";
|
|
|
break;
|
|
|
}
|
|
@@ -213,21 +304,24 @@ $ord = $_GET['Ord'] ?? '';
|
|
|
|
|
|
$ordStr = !empty($ord) ? "$ord," : "";
|
|
|
|
|
|
-// 构建查询SQL
|
|
|
-$sqlStr = "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 - 修改为联合查询
|
|
|
+$sqlStr = "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,
|
|
|
+ cc.tel_format as cs_telformat, cc.whatsapp_format as cs_whatsappformat
|
|
|
+ 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_format LIKE '%$keyscode%'
|
|
|
+ OR cc.whatsapp_format LIKE '%$keyscode%'
|
|
|
+ OR cc.email LIKE '%$keyscode%')
|
|
|
$fliterStr
|
|
|
- ORDER BY {$ordStr}cs_updatetime DESC";
|
|
|
+ ORDER BY {$ordStr}c.cs_updatetime DESC";
|
|
|
|
|
|
?>
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
@@ -400,24 +494,27 @@ $hrefstr = "?keys=" . $keys;
|
|
|
</div>
|
|
|
|
|
|
<?php
|
|
|
- $sql = "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
|
|
|
- FROM customer
|
|
|
- WHERE is_silent=0 AND cs_deal>0 AND cs_belong=" . (int)$_SESSION['employee_id'];
|
|
|
+ $sql = "SELECT c.id, c.cs_code, c.cs_from, c.cs_country, c.cs_type, c.cs_deal, c.cs_addtime,
|
|
|
+ c.colortag, c.cs_note, c.cs_claimFrom, 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, cc.tel_format as cs_telformat,
|
|
|
+ cc.whatsapp_format as cs_whatsappformat
|
|
|
+ FROM customer c
|
|
|
+ LEFT JOIN customer_contact cc ON c.id = cc.customer_id
|
|
|
+ WHERE c.is_silent=0 AND c.cs_deal>0 AND c.cs_belong=" . (int)$_SESSION['employee_id'];
|
|
|
|
|
|
$searchPattern = mysqli_real_escape_string($conn, $keyscode);
|
|
|
if(!empty($searchPattern)) {
|
|
|
- $sql .= " AND (cs_code LIKE '%$searchPattern%'
|
|
|
- OR cs_name LIKE '%$searchPattern%'
|
|
|
- OR cs_email LIKE '%$searchPattern%'
|
|
|
- OR cs_wechat LIKE '%$searchPattern%'
|
|
|
- OR cs_telformat LIKE '%$searchPattern%'
|
|
|
- OR cs_whatsappformat LIKE '%$searchPattern%'
|
|
|
- OR cs_code LIKE '%$searchPattern%')";
|
|
|
+ $sql .= " AND (c.cs_code LIKE '%$searchPattern%'
|
|
|
+ OR cc.contact_name LIKE '%$searchPattern%'
|
|
|
+ OR cc.email LIKE '%$searchPattern%'
|
|
|
+ OR cc.wechat LIKE '%$searchPattern%'
|
|
|
+ OR cc.tel_format LIKE '%$searchPattern%'
|
|
|
+ OR cc.whatsapp_format LIKE '%$searchPattern%'
|
|
|
+ OR c.cs_code LIKE '%$searchPattern%')";
|
|
|
}
|
|
|
|
|
|
- $sql .= " $filterStr ORDER BY colortag DESC, id DESC";
|
|
|
+ $sql .= " $filterStr ORDER BY c.colortag DESC, c.id DESC";
|
|
|
|
|
|
$result = mysqli_query($conn, $sql);
|
|
|
|