|
@@ -10,397 +10,398 @@ checkLogin();
|
|
|
$act = $_GET['act'] ?? '';
|
|
|
$urlStr = '';
|
|
|
|
|
|
-// 处理保存操作
|
|
|
-if ($act == "save") {
|
|
|
- $isedit = false;
|
|
|
- $id = $_POST['id'] ?? '';
|
|
|
- if (!empty($id) && is_numeric($id)) {
|
|
|
- $isedit = true;
|
|
|
- }
|
|
|
-
|
|
|
- // 获取表单数据 - 客户基本信息
|
|
|
- $cs_code = textEncode($_POST['cs_code']);
|
|
|
- $cs_company = textEncode($_POST['cs_company']);
|
|
|
- $cs_belong = $_POST['cs_belong'];
|
|
|
- $cs_country = $_POST['cs_country'];
|
|
|
- $cs_from = $_POST['cs_from'];
|
|
|
- $cs_state = $_POST['cs_state'];
|
|
|
- $cs_deal = $_POST['cs_deal'];
|
|
|
- $cs_type = $_POST['cs_type'] ?? 5;
|
|
|
- $cs_belongclient = $_POST['cs_belongclient'] ?? 0;
|
|
|
- $no_content = htmlEncode($_POST['no_content']);
|
|
|
- $allowedit = isset($_POST['allowedit']) ? 1 : 0;
|
|
|
- $cs_address = textEncode($_POST['cs_address'] ?? '');
|
|
|
- $mytag = textEncode($_POST['mytag'] ?? '');
|
|
|
- $mytag = str_replace(['</span><span>', '</span>', '<span>'], [',', '', ''], $mytag);
|
|
|
- $mytag = explode(',', $mytag);
|
|
|
-
|
|
|
- // 获取联系人信息
|
|
|
- $contacts = $_POST['contact'] ?? [];
|
|
|
-
|
|
|
- // 验证必填字段
|
|
|
- if (empty($cs_code)) {
|
|
|
- echo "<script>alert('客户编码不能为空');history.back();</script>";
|
|
|
- exit;
|
|
|
- }
|
|
|
-
|
|
|
- if ($cs_country == 0) {
|
|
|
- echo "<script>alert('这是哪个国家的客户?');history.back();</script>";
|
|
|
- exit;
|
|
|
- }
|
|
|
-
|
|
|
- if ($cs_from == "0") {
|
|
|
- echo "<script>alert('请填写客户来源!');history.back();</script>";
|
|
|
- exit;
|
|
|
- }
|
|
|
-
|
|
|
- // 自动检测来源
|
|
|
- if (strpos($cs_code, ';1688') !== false) {
|
|
|
- $cs_from = 1; // 1688
|
|
|
- }
|
|
|
- if (strpos($cs_code, ';阿里') !== false) {
|
|
|
- $cs_from = 2; // International station
|
|
|
- }
|
|
|
- if (strpos($cs_code, '官网') !== false) {
|
|
|
- $cs_from = 3; // Website
|
|
|
- }
|
|
|
-
|
|
|
- // 验证联系方式
|
|
|
- $primary_contact = !empty($contacts) ? current($contacts) : [];
|
|
|
-
|
|
|
- if ($allowedit != 1) {
|
|
|
- // 阿里巴巴验证
|
|
|
- if (($cs_from == 1 || $cs_from == 2) && empty($primary_contact['alibaba_1'])) {
|
|
|
- echo "<script>alert('阿里旺旺为必填项');history.back();</script>";
|
|
|
- exit;
|
|
|
- }
|
|
|
-
|
|
|
- // 官网来源验证
|
|
|
- if ($cs_from == 3) {
|
|
|
- $has_required = false;
|
|
|
- for ($i = 1; $i <= 3; $i++) {
|
|
|
- if (!empty($primary_contact['tel_' . $i]) ||
|
|
|
- !empty($primary_contact['whatsapp_' . $i]) ||
|
|
|
- !empty($primary_contact['wechat_' . $i])) {
|
|
|
- $has_required = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (!$has_required) {
|
|
|
- echo "<script>alert('电话和WhatsApp为必填项');history.back();</script>";
|
|
|
- exit;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 市场客户验证
|
|
|
- if ($cs_from == 8) {
|
|
|
- $has_wechat = false;
|
|
|
- for ($i = 1; $i <= 3; $i++) {
|
|
|
- if (!empty($primary_contact['wechat_' . $i])) {
|
|
|
- $has_wechat = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (!$has_wechat) {
|
|
|
- echo "<script>alert('微信为必填项');history.back();</script>";
|
|
|
- exit;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // Facebook验证
|
|
|
- if ($cs_from == 12) {
|
|
|
- $has_facebook = false;
|
|
|
- for ($i = 1; $i <= 3; $i++) {
|
|
|
- if (!empty($primary_contact['facebook_' . $i])) {
|
|
|
- $has_facebook = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (!$has_facebook) {
|
|
|
- echo "<script>alert('Facebook为必填项');history.back();</script>";
|
|
|
- exit;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if ($isedit) {
|
|
|
- // 验证客户所有权
|
|
|
- $sql = "SELECT cs_chain FROM customer WHERE id = $id";
|
|
|
- $result = mysqli_query($conn, $sql);
|
|
|
- if ($row = mysqli_fetch_assoc($result)) {
|
|
|
- $cs_chain = $row['cs_chain'];
|
|
|
- $chain_array = explode(',', $cs_chain);
|
|
|
- $last_item = end($chain_array);
|
|
|
-
|
|
|
- if ($last_item != $cs_belong) {
|
|
|
- $cs_chain .= ",$cs_belong";
|
|
|
- }
|
|
|
-
|
|
|
- // 更新客户基本信息
|
|
|
- $sql = "UPDATE customer SET
|
|
|
- cs_code = '$cs_code',
|
|
|
- cs_company = '$cs_company',
|
|
|
- cs_belong = '$cs_belong',
|
|
|
- cs_country = '$cs_country',
|
|
|
- cs_address = '$cs_address',
|
|
|
- cs_from = '$cs_from',
|
|
|
- cs_state = '$cs_state',
|
|
|
- cs_deal = '$cs_deal',
|
|
|
- cs_type = '$cs_type',
|
|
|
- cs_belongclient = '$cs_belongclient',
|
|
|
- cs_note = '$no_content',
|
|
|
- allowedit = $allowedit,
|
|
|
- cs_chain = '$cs_chain',
|
|
|
- cs_updatetime = NOW()";
|
|
|
-
|
|
|
- // 处理cs_dealdate
|
|
|
- if ($cs_deal == 3) {
|
|
|
- $sql .= ", cs_dealdate = CASE WHEN cs_dealdate IS NULL THEN NOW() ELSE cs_dealdate END";
|
|
|
- }
|
|
|
-
|
|
|
- $sql .= " WHERE id = $id";
|
|
|
- mysqli_query($conn, $sql);
|
|
|
-
|
|
|
- // 处理联系人信息
|
|
|
- $existingContactIds = [];
|
|
|
- foreach ($contacts as $contact) {
|
|
|
- if (!empty($contact['id'])) {
|
|
|
- $existingContactIds[] = (int)$contact['id'];
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 删除不再使用的联系人记录
|
|
|
- if (!empty($existingContactIds)) {
|
|
|
- $idsToKeep = implode(',', $existingContactIds);
|
|
|
- $deleteContactsSql = "DELETE FROM customer_contact WHERE customer_id = $id AND id NOT IN ($idsToKeep)";
|
|
|
- } else {
|
|
|
- $deleteContactsSql = "DELETE FROM customer_contact WHERE customer_id = $id";
|
|
|
- }
|
|
|
- mysqli_query($conn, $deleteContactsSql);
|
|
|
-
|
|
|
- // 更新或添加联系人信息
|
|
|
- foreach ($contacts as $contact) {
|
|
|
- $contact_id = !empty($contact['id']) ? (int)$contact['id'] : 0;
|
|
|
- $contact_name = textEncode($contact['contact_name'] ?? '');
|
|
|
-
|
|
|
- // 准备SQL字段和值
|
|
|
- $fields = ['contact_name'];
|
|
|
- $values = ["'" . mysqli_real_escape_string($conn, $contact_name) . "'"];
|
|
|
- $updates = ["contact_name = '" . mysqli_real_escape_string($conn, $contact_name) . "'"];
|
|
|
-
|
|
|
- // 处理所有联系方式类型
|
|
|
- $methodTypes = ['tel', 'email', 'whatsapp', 'wechat', 'linkedin', 'facebook', 'alibaba'];
|
|
|
- foreach ($methodTypes as $type) {
|
|
|
- for ($i = 1; $i <= 3; $i++) {
|
|
|
- $field = $type . '_' . $i;
|
|
|
- $format_field = $field . '_format';
|
|
|
- $bu_field = $field . '_bu';
|
|
|
-
|
|
|
- $value = textEncode($contact[$field] ?? '');
|
|
|
- $format_value = ($type == 'tel' || $type == 'whatsapp') ? numFormat($value) : '';
|
|
|
- $bu_value = textEncode($contact[$bu_field] ?? $value);
|
|
|
-
|
|
|
- // 添加字段名
|
|
|
- $fields[] = $field;
|
|
|
- $fields[] = $bu_field;
|
|
|
- if ($type == 'tel' || $type == 'whatsapp') {
|
|
|
- $fields[] = $format_field;
|
|
|
- }
|
|
|
-
|
|
|
- // 添加值
|
|
|
- $values[] = "'" . mysqli_real_escape_string($conn, $value) . "'";
|
|
|
- $values[] = "'" . mysqli_real_escape_string($conn, $bu_value) . "'";
|
|
|
- if ($type == 'tel' || $type == 'whatsapp') {
|
|
|
- $values[] = "'" . mysqli_real_escape_string($conn, $format_value) . "'";
|
|
|
- }
|
|
|
-
|
|
|
- // 添加更新语句
|
|
|
- $updates[] = $field . " = '" . mysqli_real_escape_string($conn, $value) . "'";
|
|
|
- $updates[] = $bu_field . " = '" . mysqli_real_escape_string($conn, $bu_value) . "'";
|
|
|
- if ($type == 'tel' || $type == 'whatsapp') {
|
|
|
- $updates[] = $format_field . " = '" . mysqli_real_escape_string($conn, $format_value) . "'";
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if ($contact_id > 0) {
|
|
|
- // 更新已有联系人
|
|
|
- $updateContactSql = "UPDATE customer_contact SET " .
|
|
|
- implode(", ", $updates) . ", updated_at = NOW() " .
|
|
|
- "WHERE id = $contact_id AND customer_id = $id";
|
|
|
- mysqli_query($conn, $updateContactSql);
|
|
|
- } else {
|
|
|
- // 添加新联系人
|
|
|
- $insertContactSql = "INSERT INTO customer_contact (" .
|
|
|
- implode(", ", $fields) . ", customer_id, created_at, updated_at) VALUES (" .
|
|
|
- implode(", ", $values) . ", $id, NOW(), NOW())";
|
|
|
- mysqli_query($conn, $insertContactSql);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 更新标签
|
|
|
- mysqli_query($conn, "DELETE FROM tagtable WHERE customerId = $id");
|
|
|
- foreach ($mytag as $tag) {
|
|
|
- if (!empty(trim($tag))) {
|
|
|
- $tagSql = "INSERT INTO tagtable (tagName, employeeId, customerId) VALUES ('" .
|
|
|
- mysqli_real_escape_string($conn, $tag) . "', " .
|
|
|
- $_SESSION['employee_id'] . ", $id)";
|
|
|
- mysqli_query($conn, $tagSql);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $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_type, cs_belongclient,
|
|
|
- cs_note, allowedit, cs_chain, cs_addtime, cs_updatetime,
|
|
|
- is_silent, cs_dealdate
|
|
|
- ) VALUES (
|
|
|
- '$cs_code', '$cs_company', '$cs_country', '$cs_address', '$cs_from',
|
|
|
- '$cs_belong', '$cs_state', '$cs_deal', '$cs_type', '$cs_belongclient',
|
|
|
- '$no_content', $allowedit, '$cs_belong', NOW(), NOW(),
|
|
|
- 0, " . ($cs_deal == 3 ? "NOW()" : "NULL") . "
|
|
|
- )";
|
|
|
- mysqli_query($conn, $sql);
|
|
|
- $new_customer_id = mysqli_insert_id($conn);
|
|
|
-
|
|
|
- // 插入联系人信息
|
|
|
- if ($new_customer_id > 0) {
|
|
|
- foreach ($contacts as $contact) {
|
|
|
- $contact_name = textEncode($contact['contact_name'] ?? '');
|
|
|
-
|
|
|
- // 准备SQL字段和值
|
|
|
- $fields = ['contact_name'];
|
|
|
- $values = ["'" . mysqli_real_escape_string($conn, $contact_name) . "'"];
|
|
|
-
|
|
|
- // 处理所有联系方式类型
|
|
|
- $methodTypes = ['tel', 'email', 'whatsapp', 'wechat', 'linkedin', 'facebook', 'alibaba'];
|
|
|
- foreach ($methodTypes as $type) {
|
|
|
- for ($i = 1; $i <= 3; $i++) {
|
|
|
- $field = $type . '_' . $i;
|
|
|
- $format_field = $field . '_format';
|
|
|
- $bu_field = $field . '_bu';
|
|
|
-
|
|
|
- $value = textEncode($contact[$field] ?? '');
|
|
|
- $format_value = ($type == 'tel' || $type == 'whatsapp') ? numFormat($value) : '';
|
|
|
- $bu_value = textEncode($contact[$bu_field] ?? $value);
|
|
|
-
|
|
|
- // 添加字段名
|
|
|
- $fields[] = $field;
|
|
|
- $fields[] = $bu_field;
|
|
|
- if ($type == 'tel' || $type == 'whatsapp') {
|
|
|
- $fields[] = $format_field;
|
|
|
- }
|
|
|
-
|
|
|
- // 添加值
|
|
|
- $values[] = "'" . mysqli_real_escape_string($conn, $value) . "'";
|
|
|
- $values[] = "'" . mysqli_real_escape_string($conn, $bu_value) . "'";
|
|
|
- if ($type == 'tel' || $type == 'whatsapp') {
|
|
|
- $values[] = "'" . mysqli_real_escape_string($conn, $format_value) . "'";
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 添加新联系人
|
|
|
- $insertContactSql = "INSERT INTO customer_contact (" .
|
|
|
- implode(", ", $fields) . ", customer_id, created_at, updated_at) VALUES (" .
|
|
|
- implode(", ", $values) . ", $new_customer_id, NOW(), NOW())";
|
|
|
- mysqli_query($conn, $insertContactSql);
|
|
|
- }
|
|
|
-
|
|
|
- // 保存标签
|
|
|
- foreach ($mytag as $tag) {
|
|
|
- if (!empty(trim($tag))) {
|
|
|
- $tagSql = "INSERT INTO tagtable (tagName, employeeId, customerId) VALUES ('" .
|
|
|
- mysqli_real_escape_string($conn, $tag) . "', " .
|
|
|
- $_SESSION['employee_id'] . ", $new_customer_id)";
|
|
|
- mysqli_query($conn, $tagSql);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $page = $_GET['Page'] ?? '';
|
|
|
- $keys = urlencode($_GET['Keys'] ?? '');
|
|
|
- header("Location: ?keys=$keys&Page=$page$urlStr");
|
|
|
- exit;
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-// 处理编辑操作
|
|
|
-if ($act == "edit") {
|
|
|
- $id = $_GET['id'] ?? '';
|
|
|
- $isedit = false;
|
|
|
- if (!empty($id) && is_numeric($id)) {
|
|
|
- $isedit = true;
|
|
|
- }
|
|
|
-
|
|
|
- if ($isedit) {
|
|
|
- // 联合查询客户基本信息和联系人信息
|
|
|
- $sql = "SELECT c.*,
|
|
|
- cc.id as contact_id, cc.contact_name,
|
|
|
- cc.tel_1, cc.tel_1_format, cc.tel_1_bu,
|
|
|
- cc.tel_2, cc.tel_2_format, cc.tel_2_bu,
|
|
|
- cc.tel_3, cc.tel_3_format, cc.tel_3_bu,
|
|
|
- cc.email_1, cc.email_1_bu,
|
|
|
- cc.email_2, cc.email_2_bu,
|
|
|
- cc.email_3, cc.email_3_bu,
|
|
|
- cc.whatsapp_1, cc.whatsapp_1_format, cc.whatsapp_1_bu,
|
|
|
- cc.whatsapp_2, cc.whatsapp_2_format, cc.whatsapp_2_bu,
|
|
|
- cc.whatsapp_3, cc.whatsapp_3_format, cc.whatsapp_3_bu,
|
|
|
- cc.wechat_1, cc.wechat_1_bu,
|
|
|
- cc.wechat_2, cc.wechat_2_bu,
|
|
|
- cc.wechat_3, cc.wechat_3_bu,
|
|
|
- cc.linkedin_1, cc.linkedin_1_bu,
|
|
|
- cc.linkedin_2, cc.linkedin_2_bu,
|
|
|
- cc.linkedin_3, cc.linkedin_3_bu,
|
|
|
- cc.facebook_1, cc.facebook_1_bu,
|
|
|
- cc.facebook_2, cc.facebook_2_bu,
|
|
|
- cc.facebook_3, cc.facebook_3_bu,
|
|
|
- cc.alibaba_1, cc.alibaba_1_bu,
|
|
|
- cc.alibaba_2, cc.alibaba_2_bu,
|
|
|
- cc.alibaba_3, cc.alibaba_3_bu
|
|
|
- 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['contact_name']);
|
|
|
- $cs_country = $row['cs_country'];
|
|
|
- $cs_from = $row['cs_from'];
|
|
|
- $cs_tel = textDecode($row['tel_1']);
|
|
|
- $cs_telBu = textDecode($row['tel_1_bu']);
|
|
|
- $cs_email = textDecode($row['email_1']);
|
|
|
- $cs_emailBu = textDecode($row['email_1_bu']);
|
|
|
- $cs_whatsapp = textDecode($row['whatsapp_1']);
|
|
|
- $cs_whatsappBu = textDecode($row['whatsapp_1_bu']);
|
|
|
- $cs_wechat = textDecode($row['wechat_1']);
|
|
|
- $cs_wechatBu = textDecode($row['wechat_1_bu']);
|
|
|
- $cs_linkedin = textDecode($row['linkedin_1']);
|
|
|
- $cs_linkedinBu = textDecode($row['linkedin_1_bu']);
|
|
|
- $cs_facebook = textDecode($row['facebook_1']);
|
|
|
- $cs_facebookBu = textDecode($row['facebook_1_bu']);
|
|
|
- $cs_alibaba = textDecode($row['alibaba_1']);
|
|
|
- $cs_alibabaBu = textDecode($row['alibaba_1_bu']);
|
|
|
- $cs_address = textDecode($row['cs_address']);
|
|
|
- $cs_addtime = $row['cs_addtime'];
|
|
|
- $cs_updatetime = $row['cs_updatetime'];
|
|
|
- $cs_belong = $row['cs_belong'];
|
|
|
- $cs_state = $row['cs_state'];
|
|
|
- $cs_deal = $row['cs_deal'];
|
|
|
- $cs_note = htmlDecode($row['cs_note']);
|
|
|
- $allowedit = $row['allowedit'];
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
+//
|
|
|
+//// 处理保存操作
|
|
|
+//if ($act == "save") {
|
|
|
+// $isedit = false;
|
|
|
+// $id = $_POST['id'] ?? '';
|
|
|
+// if (!empty($id) && is_numeric($id)) {
|
|
|
+// $isedit = true;
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 获取表单数据 - 客户基本信息
|
|
|
+// $cs_code = textEncode($_POST['cs_code']);
|
|
|
+// $cs_company = textEncode($_POST['cs_company']);
|
|
|
+// $cs_belong = $_POST['cs_belong'];
|
|
|
+// $cs_country = $_POST['cs_country'];
|
|
|
+// $cs_from = $_POST['cs_from'];
|
|
|
+// $cs_state = $_POST['cs_state'];
|
|
|
+// $cs_deal = $_POST['cs_deal'];
|
|
|
+// $cs_type = $_POST['cs_type'] ?? 5;
|
|
|
+// $cs_belongclient = $_POST['cs_belongclient'] ?? 0;
|
|
|
+// $no_content = htmlEncode($_POST['no_content']);
|
|
|
+// $allowedit = isset($_POST['allowedit']) ? 1 : 0;
|
|
|
+// $cs_address = textEncode($_POST['cs_address'] ?? '');
|
|
|
+// $mytag = textEncode($_POST['mytag'] ?? '');
|
|
|
+// $mytag = str_replace(['</span><span>', '</span>', '<span>'], [',', '', ''], $mytag);
|
|
|
+// $mytag = explode(',', $mytag);
|
|
|
+//
|
|
|
+// // 获取联系人信息
|
|
|
+// $contacts = $_POST['contact'] ?? [];
|
|
|
+//
|
|
|
+// // 验证必填字段
|
|
|
+// if (empty($cs_code)) {
|
|
|
+// echo "<script>alert('客户编码不能为空');history.back();</script>";
|
|
|
+// exit;
|
|
|
+// }
|
|
|
+//
|
|
|
+// if ($cs_country == 0) {
|
|
|
+// echo "<script>alert('这是哪个国家的客户?');history.back();</script>";
|
|
|
+// exit;
|
|
|
+// }
|
|
|
+//
|
|
|
+// if ($cs_from == "0") {
|
|
|
+// echo "<script>alert('请填写客户来源!');history.back();</script>";
|
|
|
+// exit;
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 自动检测来源
|
|
|
+// if (strpos($cs_code, ';1688') !== false) {
|
|
|
+// $cs_from = 1; // 1688
|
|
|
+// }
|
|
|
+// if (strpos($cs_code, ';阿里') !== false) {
|
|
|
+// $cs_from = 2; // International station
|
|
|
+// }
|
|
|
+// if (strpos($cs_code, '官网') !== false) {
|
|
|
+// $cs_from = 3; // Website
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 验证联系方式
|
|
|
+// $primary_contact = !empty($contacts) ? current($contacts) : [];
|
|
|
+//
|
|
|
+// if ($allowedit != 1) {
|
|
|
+// // 阿里巴巴验证
|
|
|
+// if (($cs_from == 1 || $cs_from == 2) && empty($primary_contact['alibaba_1'])) {
|
|
|
+// echo "<script>alert('阿里旺旺为必填项');history.back();</script>";
|
|
|
+// exit;
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 官网来源验证
|
|
|
+// if ($cs_from == 3) {
|
|
|
+// $has_required = false;
|
|
|
+// for ($i = 1; $i <= 3; $i++) {
|
|
|
+// if (!empty($primary_contact['tel_' . $i]) ||
|
|
|
+// !empty($primary_contact['whatsapp_' . $i]) ||
|
|
|
+// !empty($primary_contact['wechat_' . $i])) {
|
|
|
+// $has_required = true;
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if (!$has_required) {
|
|
|
+// echo "<script>alert('电话和WhatsApp为必填项');history.back();</script>";
|
|
|
+// exit;
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 市场客户验证
|
|
|
+// if ($cs_from == 8) {
|
|
|
+// $has_wechat = false;
|
|
|
+// for ($i = 1; $i <= 3; $i++) {
|
|
|
+// if (!empty($primary_contact['wechat_' . $i])) {
|
|
|
+// $has_wechat = true;
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if (!$has_wechat) {
|
|
|
+// echo "<script>alert('微信为必填项');history.back();</script>";
|
|
|
+// exit;
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // Facebook验证
|
|
|
+// if ($cs_from == 12) {
|
|
|
+// $has_facebook = false;
|
|
|
+// for ($i = 1; $i <= 3; $i++) {
|
|
|
+// if (!empty($primary_contact['facebook_' . $i])) {
|
|
|
+// $has_facebook = true;
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if (!$has_facebook) {
|
|
|
+// echo "<script>alert('Facebook为必填项');history.back();</script>";
|
|
|
+// exit;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// if ($isedit) {
|
|
|
+// // 验证客户所有权
|
|
|
+// $sql = "SELECT cs_chain FROM customer WHERE id = $id";
|
|
|
+// $result = mysqli_query($conn, $sql);
|
|
|
+// if ($row = mysqli_fetch_assoc($result)) {
|
|
|
+// $cs_chain = $row['cs_chain'];
|
|
|
+// $chain_array = explode(',', $cs_chain);
|
|
|
+// $last_item = end($chain_array);
|
|
|
+//
|
|
|
+// if ($last_item != $cs_belong) {
|
|
|
+// $cs_chain .= ",$cs_belong";
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 更新客户基本信息
|
|
|
+// $sql = "UPDATE customer SET
|
|
|
+// cs_code = '$cs_code',
|
|
|
+// cs_company = '$cs_company',
|
|
|
+// cs_belong = '$cs_belong',
|
|
|
+// cs_country = '$cs_country',
|
|
|
+// cs_address = '$cs_address',
|
|
|
+// cs_from = '$cs_from',
|
|
|
+// cs_state = '$cs_state',
|
|
|
+// cs_deal = '$cs_deal',
|
|
|
+// cs_type = '$cs_type',
|
|
|
+// cs_belongclient = '$cs_belongclient',
|
|
|
+// cs_note = '$no_content',
|
|
|
+// allowedit = $allowedit,
|
|
|
+// cs_chain = '$cs_chain',
|
|
|
+// cs_updatetime = NOW()";
|
|
|
+//
|
|
|
+// // 处理cs_dealdate
|
|
|
+// if ($cs_deal == 3) {
|
|
|
+// $sql .= ", cs_dealdate = CASE WHEN cs_dealdate IS NULL THEN NOW() ELSE cs_dealdate END";
|
|
|
+// }
|
|
|
+//
|
|
|
+// $sql .= " WHERE id = $id";
|
|
|
+// mysqli_query($conn, $sql);
|
|
|
+//
|
|
|
+// // 处理联系人信息
|
|
|
+// $existingContactIds = [];
|
|
|
+// foreach ($contacts as $contact) {
|
|
|
+// if (!empty($contact['id'])) {
|
|
|
+// $existingContactIds[] = (int)$contact['id'];
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 删除不再使用的联系人记录
|
|
|
+// if (!empty($existingContactIds)) {
|
|
|
+// $idsToKeep = implode(',', $existingContactIds);
|
|
|
+// $deleteContactsSql = "DELETE FROM customer_contact WHERE customer_id = $id AND id NOT IN ($idsToKeep)";
|
|
|
+// } else {
|
|
|
+// $deleteContactsSql = "DELETE FROM customer_contact WHERE customer_id = $id";
|
|
|
+// }
|
|
|
+// mysqli_query($conn, $deleteContactsSql);
|
|
|
+//
|
|
|
+// // 更新或添加联系人信息
|
|
|
+// foreach ($contacts as $contact) {
|
|
|
+// $contact_id = !empty($contact['id']) ? (int)$contact['id'] : 0;
|
|
|
+// $contact_name = textEncode($contact['contact_name'] ?? '');
|
|
|
+//
|
|
|
+// // 准备SQL字段和值
|
|
|
+// $fields = ['contact_name'];
|
|
|
+// $values = ["'" . mysqli_real_escape_string($conn, $contact_name) . "'"];
|
|
|
+// $updates = ["contact_name = '" . mysqli_real_escape_string($conn, $contact_name) . "'"];
|
|
|
+//
|
|
|
+// // 处理所有联系方式类型
|
|
|
+// $methodTypes = ['tel', 'email', 'whatsapp', 'wechat', 'linkedin', 'facebook', 'alibaba'];
|
|
|
+// foreach ($methodTypes as $type) {
|
|
|
+// for ($i = 1; $i <= 3; $i++) {
|
|
|
+// $field = $type . '_' . $i;
|
|
|
+// $format_field = $field . '_format';
|
|
|
+// $bu_field = $field . '_bu';
|
|
|
+//
|
|
|
+// $value = textEncode($contact[$field] ?? '');
|
|
|
+// $format_value = ($type == 'tel' || $type == 'whatsapp') ? numFormat($value) : '';
|
|
|
+// $bu_value = textEncode($contact[$bu_field] ?? $value);
|
|
|
+//
|
|
|
+// // 添加字段名
|
|
|
+// $fields[] = $field;
|
|
|
+// $fields[] = $bu_field;
|
|
|
+// if ($type == 'tel' || $type == 'whatsapp') {
|
|
|
+// $fields[] = $format_field;
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 添加值
|
|
|
+// $values[] = "'" . mysqli_real_escape_string($conn, $value) . "'";
|
|
|
+// $values[] = "'" . mysqli_real_escape_string($conn, $bu_value) . "'";
|
|
|
+// if ($type == 'tel' || $type == 'whatsapp') {
|
|
|
+// $values[] = "'" . mysqli_real_escape_string($conn, $format_value) . "'";
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 添加更新语句
|
|
|
+// $updates[] = $field . " = '" . mysqli_real_escape_string($conn, $value) . "'";
|
|
|
+// $updates[] = $bu_field . " = '" . mysqli_real_escape_string($conn, $bu_value) . "'";
|
|
|
+// if ($type == 'tel' || $type == 'whatsapp') {
|
|
|
+// $updates[] = $format_field . " = '" . mysqli_real_escape_string($conn, $format_value) . "'";
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// if ($contact_id > 0) {
|
|
|
+// // 更新已有联系人
|
|
|
+// $updateContactSql = "UPDATE customer_contact SET " .
|
|
|
+// implode(", ", $updates) . ", updated_at = NOW() " .
|
|
|
+// "WHERE id = $contact_id AND customer_id = $id";
|
|
|
+// mysqli_query($conn, $updateContactSql);
|
|
|
+// } else {
|
|
|
+// // 添加新联系人
|
|
|
+// $insertContactSql = "INSERT INTO customer_contact (" .
|
|
|
+// implode(", ", $fields) . ", customer_id, created_at, updated_at) VALUES (" .
|
|
|
+// implode(", ", $values) . ", $id, NOW(), NOW())";
|
|
|
+// mysqli_query($conn, $insertContactSql);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 更新标签
|
|
|
+// mysqli_query($conn, "DELETE FROM tagtable WHERE customerId = $id");
|
|
|
+// foreach ($mytag as $tag) {
|
|
|
+// if (!empty(trim($tag))) {
|
|
|
+// $tagSql = "INSERT INTO tagtable (tagName, employeeId, customerId) VALUES ('" .
|
|
|
+// mysqli_real_escape_string($conn, $tag) . "', " .
|
|
|
+// $_SESSION['employee_id'] . ", $id)";
|
|
|
+// mysqli_query($conn, $tagSql);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// $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_type, cs_belongclient,
|
|
|
+// cs_note, allowedit, cs_chain, cs_addtime, cs_updatetime,
|
|
|
+// is_silent, cs_dealdate
|
|
|
+// ) VALUES (
|
|
|
+// '$cs_code', '$cs_company', '$cs_country', '$cs_address', '$cs_from',
|
|
|
+// '$cs_belong', '$cs_state', '$cs_deal', '$cs_type', '$cs_belongclient',
|
|
|
+// '$no_content', $allowedit, '$cs_belong', NOW(), NOW(),
|
|
|
+// 0, " . ($cs_deal == 3 ? "NOW()" : "NULL") . "
|
|
|
+// )";
|
|
|
+// mysqli_query($conn, $sql);
|
|
|
+// $new_customer_id = mysqli_insert_id($conn);
|
|
|
+//
|
|
|
+// // 插入联系人信息
|
|
|
+// if ($new_customer_id > 0) {
|
|
|
+// foreach ($contacts as $contact) {
|
|
|
+// $contact_name = textEncode($contact['contact_name'] ?? '');
|
|
|
+//
|
|
|
+// // 准备SQL字段和值
|
|
|
+// $fields = ['contact_name'];
|
|
|
+// $values = ["'" . mysqli_real_escape_string($conn, $contact_name) . "'"];
|
|
|
+//
|
|
|
+// // 处理所有联系方式类型
|
|
|
+// $methodTypes = ['tel', 'email', 'whatsapp', 'wechat', 'linkedin', 'facebook', 'alibaba'];
|
|
|
+// foreach ($methodTypes as $type) {
|
|
|
+// for ($i = 1; $i <= 3; $i++) {
|
|
|
+// $field = $type . '_' . $i;
|
|
|
+// $format_field = $field . '_format';
|
|
|
+// $bu_field = $field . '_bu';
|
|
|
+//
|
|
|
+// $value = textEncode($contact[$field] ?? '');
|
|
|
+// $format_value = ($type == 'tel' || $type == 'whatsapp') ? numFormat($value) : '';
|
|
|
+// $bu_value = textEncode($contact[$bu_field] ?? $value);
|
|
|
+//
|
|
|
+// // 添加字段名
|
|
|
+// $fields[] = $field;
|
|
|
+// $fields[] = $bu_field;
|
|
|
+// if ($type == 'tel' || $type == 'whatsapp') {
|
|
|
+// $fields[] = $format_field;
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 添加值
|
|
|
+// $values[] = "'" . mysqli_real_escape_string($conn, $value) . "'";
|
|
|
+// $values[] = "'" . mysqli_real_escape_string($conn, $bu_value) . "'";
|
|
|
+// if ($type == 'tel' || $type == 'whatsapp') {
|
|
|
+// $values[] = "'" . mysqli_real_escape_string($conn, $format_value) . "'";
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 添加新联系人
|
|
|
+// $insertContactSql = "INSERT INTO customer_contact (" .
|
|
|
+// implode(", ", $fields) . ", customer_id, created_at, updated_at) VALUES (" .
|
|
|
+// implode(", ", $values) . ", $new_customer_id, NOW(), NOW())";
|
|
|
+// mysqli_query($conn, $insertContactSql);
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 保存标签
|
|
|
+// foreach ($mytag as $tag) {
|
|
|
+// if (!empty(trim($tag))) {
|
|
|
+// $tagSql = "INSERT INTO tagtable (tagName, employeeId, customerId) VALUES ('" .
|
|
|
+// mysqli_real_escape_string($conn, $tag) . "', " .
|
|
|
+// $_SESSION['employee_id'] . ", $new_customer_id)";
|
|
|
+// mysqli_query($conn, $tagSql);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// $page = $_GET['Page'] ?? '';
|
|
|
+// $keys = urlencode($_GET['Keys'] ?? '');
|
|
|
+// header("Location: ?keys=$keys&Page=$page$urlStr");
|
|
|
+// exit;
|
|
|
+// }
|
|
|
+// }
|
|
|
+//}
|
|
|
+//
|
|
|
+//// 处理编辑操作
|
|
|
+//if ($act == "edit") {
|
|
|
+// $id = $_GET['id'] ?? '';
|
|
|
+// $isedit = false;
|
|
|
+// if (!empty($id) && is_numeric($id)) {
|
|
|
+// $isedit = true;
|
|
|
+// }
|
|
|
+//
|
|
|
+// if ($isedit) {
|
|
|
+// // 联合查询客户基本信息和联系人信息
|
|
|
+// $sql = "SELECT c.*,
|
|
|
+// cc.id as contact_id, cc.contact_name,
|
|
|
+// cc.tel_1, cc.tel_1_format, cc.tel_1_bu,
|
|
|
+// cc.tel_2, cc.tel_2_format, cc.tel_2_bu,
|
|
|
+// cc.tel_3, cc.tel_3_format, cc.tel_3_bu,
|
|
|
+// cc.email_1, cc.email_1_bu,
|
|
|
+// cc.email_2, cc.email_2_bu,
|
|
|
+// cc.email_3, cc.email_3_bu,
|
|
|
+// cc.whatsapp_1, cc.whatsapp_1_format, cc.whatsapp_1_bu,
|
|
|
+// cc.whatsapp_2, cc.whatsapp_2_format, cc.whatsapp_2_bu,
|
|
|
+// cc.whatsapp_3, cc.whatsapp_3_format, cc.whatsapp_3_bu,
|
|
|
+// cc.wechat_1, cc.wechat_1_bu,
|
|
|
+// cc.wechat_2, cc.wechat_2_bu,
|
|
|
+// cc.wechat_3, cc.wechat_3_bu,
|
|
|
+// cc.linkedin_1, cc.linkedin_1_bu,
|
|
|
+// cc.linkedin_2, cc.linkedin_2_bu,
|
|
|
+// cc.linkedin_3, cc.linkedin_3_bu,
|
|
|
+// cc.facebook_1, cc.facebook_1_bu,
|
|
|
+// cc.facebook_2, cc.facebook_2_bu,
|
|
|
+// cc.facebook_3, cc.facebook_3_bu,
|
|
|
+// cc.alibaba_1, cc.alibaba_1_bu,
|
|
|
+// cc.alibaba_2, cc.alibaba_2_bu,
|
|
|
+// cc.alibaba_3, cc.alibaba_3_bu
|
|
|
+// 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['contact_name']);
|
|
|
+// $cs_country = $row['cs_country'];
|
|
|
+// $cs_from = $row['cs_from'];
|
|
|
+// $cs_tel = textDecode($row['tel_1']);
|
|
|
+// $cs_telBu = textDecode($row['tel_1_bu']);
|
|
|
+// $cs_email = textDecode($row['email_1']);
|
|
|
+// $cs_emailBu = textDecode($row['email_1_bu']);
|
|
|
+// $cs_whatsapp = textDecode($row['whatsapp_1']);
|
|
|
+// $cs_whatsappBu = textDecode($row['whatsapp_1_bu']);
|
|
|
+// $cs_wechat = textDecode($row['wechat_1']);
|
|
|
+// $cs_wechatBu = textDecode($row['wechat_1_bu']);
|
|
|
+// $cs_linkedin = textDecode($row['linkedin_1']);
|
|
|
+// $cs_linkedinBu = textDecode($row['linkedin_1_bu']);
|
|
|
+// $cs_facebook = textDecode($row['facebook_1']);
|
|
|
+// $cs_facebookBu = textDecode($row['facebook_1_bu']);
|
|
|
+// $cs_alibaba = textDecode($row['alibaba_1']);
|
|
|
+// $cs_alibabaBu = textDecode($row['alibaba_1_bu']);
|
|
|
+// $cs_address = textDecode($row['cs_address']);
|
|
|
+// $cs_addtime = $row['cs_addtime'];
|
|
|
+// $cs_updatetime = $row['cs_updatetime'];
|
|
|
+// $cs_belong = $row['cs_belong'];
|
|
|
+// $cs_state = $row['cs_state'];
|
|
|
+// $cs_deal = $row['cs_deal'];
|
|
|
+// $cs_note = htmlDecode($row['cs_note']);
|
|
|
+// $allowedit = $row['allowedit'];
|
|
|
+// }
|
|
|
+// }
|
|
|
+//}
|
|
|
|
|
|
// 处理批量操作
|
|
|
if ($act == "postchk") {
|
|
@@ -643,13 +644,13 @@ if (!empty($filters['Business'])) {
|
|
|
|
|
|
if (!empty($filters['Contact'])) {
|
|
|
switch ($filters['Contact']) {
|
|
|
- case "1": $filterStr .= " AND (cc.tel_1 != '' OR cc.tel_2 != '' OR cc.tel_3 != '')"; break;
|
|
|
- case "2": $filterStr .= " AND (cc.wechat_1 != '' OR cc.wechat_2 != '' OR cc.wechat_3 != '')"; break;
|
|
|
- case "3": $filterStr .= " AND (cc.whatsapp_1 != '' OR cc.whatsapp_2 != '' OR cc.whatsapp_3 != '')"; break;
|
|
|
- case "4": $filterStr .= " AND (cc.email_1 != '' OR cc.email_2 != '' OR cc.email_3 != '')"; break;
|
|
|
- case "5": $filterStr .= " AND (cc.linkedin_1 != '' OR cc.linkedin_2 != '' OR cc.linkedin_3 != '')"; break;
|
|
|
- case "6": $filterStr .= " AND (cc.facebook_1 != '' OR cc.facebook_2 != '' OR cc.facebook_3 != '')"; break;
|
|
|
- case "7": $filterStr .= " AND (cc.alibaba_1 != '' OR cc.alibaba_2 != '' OR cc.alibaba_3 != '')"; break;
|
|
|
+ case "1": $filterStr .= " AND c.id IN (SELECT customer_id FROM customer_contact WHERE tel_1 != '' OR tel_2 != '' OR tel_3 != '')"; break;
|
|
|
+ case "2": $filterStr .= " AND c.id IN (SELECT customer_id FROM customer_contact WHERE wechat_1 != '' OR wechat_2 != '' OR wechat_3 != '')"; break;
|
|
|
+ case "3": $filterStr .= " AND c.id IN (SELECT customer_id FROM customer_contact WHERE whatsapp_1 != '' OR whatsapp_2 != '' OR whatsapp_3 != '')"; break;
|
|
|
+ case "4": $filterStr .= " AND c.id IN (SELECT customer_id FROM customer_contact WHERE email_1 != '' OR email_2 != '' OR email_3 != '')"; break;
|
|
|
+ case "5": $filterStr .= " AND c.id IN (SELECT customer_id FROM customer_contact WHERE linkedin_1 != '' OR linkedin_2 != '' OR linkedin_3 != '')"; break;
|
|
|
+ case "6": $filterStr .= " AND c.id IN (SELECT customer_id FROM customer_contact WHERE facebook_1 != '' OR facebook_2 != '' OR facebook_3 != '')"; break;
|
|
|
+ case "7": $filterStr .= " AND c.id IN (SELECT customer_id FROM customer_contact WHERE alibaba_1 != '' OR alibaba_2 != '' OR alibaba_3 != '')"; break;
|
|
|
}
|
|
|
$urlStr .= "&fliterContact=" . $filters['Contact'];
|
|
|
}
|