1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042 |
- <?php
- require_once 'conn.php';
- 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 == "postchk") {
- if (isset($_POST['chkbox']) && isset($_POST['chkact'])) {
- $chkact = $_POST['chkact'];
- $ids = implode(',', array_map('intval', $_POST['chkbox']));
- $count = count($_POST['chkbox']);
-
- // 检查是否为员工转让操作
- if (substr($chkact, 0, 1) === 't') {
- // 从chkact值中提取员工ID
- $employeeId = (int)substr($chkact, 1);
-
- // 获取员工代码和名称
- $stmt = $conn->prepare("SELECT em_code, em_user FROM employee WHERE id = ?");
- $stmt->bind_param("i", $employeeId);
- $stmt->execute();
- $result = $stmt->get_result();
- $employeeCode = '';
- $employeeName = '未知业务员';
- if ($row = $result->fetch_assoc()) {
- $employeeCode = $row['em_code'];
- $employeeName = $row['em_user'];
- }
- $stmt->close();
-
- // 检查是否有客户已经属于目标业务员
- $checkSql = "SELECT GROUP_CONCAT(id) as existing_ids FROM customer
- WHERE cs_belong = $employeeId AND id IN ({$ids})";
- $checkResult = $conn->query($checkSql);
- $existingIds = "";
-
- if ($checkResult && $checkRow = $checkResult->fetch_assoc()) {
- $existingIds = $checkRow['existing_ids'];
- }
-
- if (!empty($existingIds)) {
- // 有客户已经属于该业务员,显示错误信息
- echo "<script>alert('无法转移,客户ID:{$existingIds} 已经属于业务员【{$employeeName}】!');history.back();</script>";
- exit;
- }
-
- // 更新客户记录
- $sql = "UPDATE customer SET
- cs_updatetime = NOW(),
- cs_code = REPLACE(cs_code, '-', '/{$employeeCode}-'),
- cs_belong = {$employeeId},
- cs_chain = CONCAT(cs_chain, ',{$employeeId}')
- WHERE id IN ({$ids})";
- mysqli_query($conn, $sql);
-
- // 记录操作日志
- $action = "{$_SESSION['employee_name']} 批量转移{$count}个客户({$ids})给业务员【{$employeeName}】";
- logAction($action);
-
- } else {
- switch($chkact) {
- case "0":
- case "1":
- case "2":
- $sql = "UPDATE customer SET cs_deal = $chkact WHERE id IN ($ids)";
- break;
- case "-1":
- // 删除客户记录和联系人记录(依靠外键级联删除)
- $sql = "DELETE FROM customer WHERE id IN ($ids)";
- break;
- }
-
- if (isset($sql)) {
- mysqli_query($conn, $sql);
- }
- }
-
- $keys = urlencode($_GET['Keys'] ?? '');
- $page = $_GET['Page'] ?? '';
- header("Location: ?keys=$keys&Page=$page$urlStr");
- exit;
- }
- }
- /*
- // 处理筛选条件
- $fliterQudao = $_GET['fliterQudao'] ?? '';
- $fliterDeal = $_GET['fliterDeal'] ?? '';
- $fliterTeam = $_GET['fliterTeam'] ?? '';
- $fliterContact = $_GET['fliterContact'] ?? '';
- $fliterEmployee = $_GET['fliterEmployee'] ?? '';
- $fliterStr = "";
- if (!empty($fliterQudao)) {
- $fliterStr .= " AND c.cs_from = " . intval($fliterQudao);
- $urlStr .= "&fliterQudao=" . $fliterQudao;
- }
- if (!empty($fliterDeal)) {
- $fliterStr .= " AND c.cs_deal = " . intval($fliterDeal);
- $urlStr .= "&fliterDeal=" . $fliterDeal;
- }
- if (!empty($fliterTeam)) {
- $fliterStr .= " 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)) {
- $fliterStr .= " AND c.cs_belong = " . intval($fliterEmployee);
- $urlStr .= "&fliterEmployee=" . $fliterEmployee;
- }
- if (!empty($fliterContact)) {
- switch ($fliterContact) {
- case "1": $fliterStr .= " AND (cc.tel_1 != '' OR cc.tel_2 != '' OR cc.tel_3 != '')"; break;
- case "2": $fliterStr .= " AND (cc.wechat_1 != '' OR cc.wechat_2 != '' OR cc.wechat_3 != '')"; break;
- case "3": $fliterStr .= " AND (cc.whatsapp_1 != '' OR cc.whatsapp_2 != '' OR cc.whatsapp_3 != '')"; break;
- case "4": $fliterStr .= " AND (cc.email_1 != '' OR cc.email_2 != '' OR cc.email_3 != '')"; break;
- case "5": $fliterStr .= " AND (cc.linkedin_1 != '' OR cc.linkedin_2 != '' OR cc.linkedin_3 != '')"; break;
- case "6": $fliterStr .= " AND (cc.facebook_1 != '' OR cc.facebook_2 != '' OR cc.facebook_3 != '')"; break;
- case "7": $fliterStr .= " AND (cc.alibaba_1 != '' OR cc.alibaba_2 != '' OR cc.alibaba_3 != '')"; break;
- }
- $urlStr .= "&fliterContact=" . $fliterContact;
- }
- // 搜索和排序
- $keys = $_GET['Keys'] ?? '';
- $keyscode = textEncode($keys);
- $page = $_GET['Page'] ?? 1;
- $ord = $_GET['Ord'] ?? '';
- $ordStr = !empty($ord) ? "$ord," : "";
- // 构建查询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, c.cs_type, c.cs_belongclient, c.allowedit,c.colortag,
- 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 1=1";
- if (!empty($keyscode)) {
- $sqlStr .= " AND (c.cs_code LIKE '%$keyscode%'
- OR cc.contact_name LIKE '%$keyscode%'
- OR cc.tel_1 LIKE '%$keyscode%'
- OR cc.tel_2 LIKE '%$keyscode%'
- OR cc.tel_3 LIKE '%$keyscode%'
- OR cc.email_1 LIKE '%$keyscode%'
- OR cc.email_2 LIKE '%$keyscode%'
- OR cc.email_3 LIKE '%$keyscode%'
- OR cc.wechat_1 LIKE '%$keyscode%'
- OR cc.wechat_2 LIKE '%$keyscode%'
- OR cc.wechat_3 LIKE '%$keyscode%'
- OR cc.whatsapp_1_format LIKE '%$keyscode%'
- OR cc.whatsapp_2_format LIKE '%$keyscode%'
- OR cc.whatsapp_3_format LIKE '%$keyscode%'
- OR cc.linkedin_1 LIKE '%$keyscode%'
- OR cc.linkedin_2 LIKE '%$keyscode%'
- OR cc.linkedin_3 LIKE '%$keyscode%'
- OR cc.facebook_1 LIKE '%$keyscode%'
- OR cc.facebook_2 LIKE '%$keyscode%'
- OR cc.facebook_3 LIKE '%$keyscode%'
- OR cc.alibaba_1 LIKE '%$keyscode%'
- OR cc.alibaba_2 LIKE '%$keyscode%'
- OR cc.alibaba_3 LIKE '%$keyscode%'
- OR c.id IN (SELECT customerId FROM tagtable WHERE tagName LIKE '%$keyscode%'))";
- }
- $sqlStr .= " $fliterStr 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">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>客户列表</title>
- <link rel="stylesheet" href="css/common.css" type="text/css" />
- <link rel="stylesheet" href="css/alert.css" type="text/css" />
- <script src="js/jquery-1.7.2.min.js"></script>
- <script src="js/js.js"></script>
- <style>
- body {
- margin: 0;
- padding: 20px;
- background: #fff;
- }
- #man_zone {
- margin-left: 0;
- }
-
- /*解决操作换行变形问题*/
- .table2 .col9 {
- white-space: nowrap;
- overflow: hidden;
- }
-
- </style>
- </head>
- <body>
- <div id="man_zone">
- <?php
- $keys = $_GET['Keys'] ?? '';
- $keys = str_replace([" ", "+"], "", $keys);
- $keyscode = textEncode($keys);
- $page = $_GET['Page'] ?? 1;
- $filters = [
- 'Country' => $_GET['fliterCountry'] ?? '',
- 'Qudao' => $_GET['fliterQudao'] ?? '',
- 'Deal' => $_GET['fliterDeal'] ?? '',
- 'Business' => $_GET['fliterBusiness'] ?? '',
- 'Contact' => $_GET['fliterContact'] ?? ''
- ];
- $filterStr = "";
- $urlStr = "";
- // Build filter conditions
- if (!empty($filters['Country'])) {
- $filterStr .= " AND c.cs_country=" . (int)$filters['Country'];
- $urlStr .= "&fliterCountry=" . $filters['Country'];
- }
- if (!empty($filters['Qudao'])) {
- $filterStr .= " AND c.cs_from=" . (int)$filters['Qudao'];
- $urlStr .= "&fliterQudao=" . $filters['Qudao'];
- }
- if (!empty($filters['Deal'])) {
- $filterStr .= " AND c.cs_deal=" . (int)$filters['Deal'];
- $urlStr .= "&fliterDeal=" . $filters['Deal'];
- }
- if (!empty($filters['Business'])) {
- $filterStr .= " AND c.cs_type=" . (int)$filters['Business'];
- $urlStr .= "&fliterBusiness=" . $filters['Business'];
- }
- if (!empty($filters['Contact'])) {
- switch ($filters['Contact']) {
- 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'];
- }
- $keys = urlencode($keys);
- $hrefstr = "?keys=" . $keys;
- ?>
- <form id="form1" method="post" action="?act=postchk&Keys=<?= $keys ?>&Page=<?= $page ?>" onSubmit="return false">
- <div class="fastSelect clear">
- <H1>搜索条件</H1>
- <div class="selectItem">
- <label>区域</label>
- <select name="fliterCountry" class="filterSearch">
- <option value="">请选择国家地区</option>
- <?php
- $result = $conn->query("SELECT id, countryName FROM country ORDER BY CONVERT(countryName USING gbk) COLLATE gbk_chinese_ci ASC");
- while ($row = $result->fetch_assoc()) {
- $selected = ($filters['Country'] == $row['id']) ? ' selected' : '';
- echo "<option value=\"{$row['id']}\"$selected>{$row['countryName']}</option>";
- }
- ?>
- </select>
- </div>
- <div class="selectItem">
- <label>来源渠道</label>
- <select name="fliterQudao" class="filterSearch">
- <option value="">请选择渠道</option>
- <?php
- $result = $conn->query("SELECT id, ch_name FROM qudao");
- while ($row = $result->fetch_assoc()) {
- $selected = ($filters['Qudao'] == $row['id']) ? ' selected' : '';
- echo "<option value=\"{$row['id']}\"$selected>{$row['ch_name']}</option>";
- }
- ?>
- </select>
- </div>
- <div class="selectItem">
- <label>跟进阶段</label>
- <select name="fliterDeal" class="filterSearch">
- <option value="">请选择</option>
- <option value="1"<?= ($filters['Deal'] == "1") ? ' selected' : '' ?>>背景调查</option>
- <option value="2"<?= ($filters['Deal'] == "2") ? ' selected' : '' ?>>明确需求</option>
- <option value="3"<?= ($filters['Deal'] == "3") ? ' selected' : '' ?>>已成交</option>
- </select>
- </div>
- <div class="selectItem">
- <label>客户类型</label>
- <select name="fliterBusiness" class="filterSearch">
- <option value="">请选择</option>
- <?php
- $result = $conn->query("SELECT id, businessType FROM clienttype");
- while ($row = $result->fetch_assoc()) {
- $selected = ($filters['Business'] == $row['id']) ? ' selected' : '';
- echo "<option value=\"{$row['id']}\"$selected>{$row['businessType']}</option>";
- }
- ?>
- </select>
- </div>
- <div class="selectItem">
- <label>联系方式</label>
- <select name="fliterContact" class="filterSearch">
- <option value="">请选择</option>
- <option value="1"<?= ($filters['Contact'] == "1") ? ' selected' : '' ?>>电话</option>
- <option value="2"<?= ($filters['Contact'] == "2") ? ' selected' : '' ?>>微信</option>
- <option value="3"<?= ($filters['Contact'] == "3") ? ' selected' : '' ?>>WhatsApp</option>
- <option value="4"<?= ($filters['Contact'] == "4") ? ' selected' : '' ?>>邮箱</option>
- <option value="5"<?= ($filters['Contact'] == "5") ? ' selected' : '' ?>>领英</option>
- <option value="6"<?= ($filters['Contact'] == "6") ? ' selected' : '' ?>>Facebook</option>
- <option value="7"<?= ($filters['Contact'] == "7") ? ' selected' : '' ?>>阿里巴巴</option>
- </select>
- </div>
- <div class="inputSearch">
- <input type="text" id="keys" class="inputTxt" placeholder="请输入搜索关键词"
- value="<?= empty($keyscode) ? '' : $keyscode ?>"
- onKeyDown="if(event.keyCode==13){location.href='?Keys='+encodeURIComponent(document.getElementById('keys').value)}" />
- <input type="button" id="searchgo" class="searchgo" value="go"
- onClick="location.href='?Keys='+encodeURIComponent(document.getElementById('keys').value)" />
- </div>
- </div>
- <div class="table2 em<?= $_SESSION['employee_id'] ?>">
- <div class="theader">
- <div class="col1"><input type="checkbox" name="chkall" id="chkall" onClick="chkboxall(this,'chkbox')" /></div>
- <div class="col2">序号</div>
- <div class="col3">客户编号</div>
- <div class="col4">渠道来源</div>
- <div class="col5">区域</div>
- <div class="col6">客户类型</div>
- <div class="col6">跟进阶段</div>
- <div class="colmark">颜色标记</div>
- <div class="col6">录入时间</div>
- <div class="col9">操作</div>
- </div>
- <?php
- $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, c.cs_type, c.cs_belongclient, c.allowedit,c.colortag
- FROM customer c
- 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 (c.cs_code LIKE '%$searchPattern%'
- OR c.id IN (SELECT customer_id FROM customer_contact WHERE
- contact_name LIKE '%$searchPattern%' OR
- tel_1 LIKE '%$searchPattern%' OR
- tel_2 LIKE '%$searchPattern%' OR
- tel_3 LIKE '%$searchPattern%' OR
- email_1 LIKE '%$searchPattern%' OR
- email_2 LIKE '%$searchPattern%' OR
- email_3 LIKE '%$searchPattern%' OR
- wechat_1 LIKE '%$searchPattern%' OR
- wechat_2 LIKE '%$searchPattern%' OR
- wechat_3 LIKE '%$searchPattern%' OR
- whatsapp_1_format LIKE '%$searchPattern%' OR
- whatsapp_2_format LIKE '%$searchPattern%' OR
- whatsapp_3_format LIKE '%$searchPattern%' OR
- linkedin_1 LIKE '%$searchPattern%' OR
- linkedin_2 LIKE '%$searchPattern%' OR
- linkedin_3 LIKE '%$searchPattern%' OR
- facebook_1 LIKE '%$searchPattern%' OR
- facebook_2 LIKE '%$searchPattern%' OR
- facebook_3 LIKE '%$searchPattern%' OR
- alibaba_1 LIKE '%$searchPattern%' OR
- alibaba_2 LIKE '%$searchPattern%' OR
- alibaba_3 LIKE '%$searchPattern%')
- OR c.id IN (SELECT customerId FROM tagtable WHERE tagName LIKE '%$searchPattern%'))";
- }
-
- $sql .= " $filterStr ORDER BY c.colortag DESC, c.id DESC";
- $result = mysqli_query($conn, $sql);
- // Pagination logic
- $perPage = 20;
- $totalRecords = mysqli_num_rows($result);
- $totalPages = max(1, ceil($totalRecords / $perPage));
- $page = max(1, min((int)$page, $totalPages));
- $offset = max(0, ($page - 1) * $perPage);
- // Add pagination to query
- $sql .= " LIMIT $offset, $perPage";
- $result = mysqli_query($conn, $sql);
- if (mysqli_num_rows($result) > 0) {
- $tempNum = $offset;
- while ($row = mysqli_fetch_assoc($result)) {
- $tempNum++;
- ?>
- <div class="tline color<?= $row['colortag'] ?>">
- <div class="col1" align="center"><input type="checkbox" name="chkbox[]" value="<?= $row['id'] ?>" /></div>
- <div class="col2"><?= $tempNum ?></div>
- <div class="col3 slidepanel"><?= $row['cs_code'] ?>
- <?php if ($row['cs_claimFrom'] > 0): ?>
- <img src="../images/yijiao.png" class="handover" title="来自认领">
- <?php endif; ?>
- </div>
- <div class="col4">
- <?php
- $qudao = $conn->query("SELECT ch_name FROM qudao WHERE id=" . (int)$row['cs_from']);
- echo $qudao->num_rows > 0 ? $qudao->fetch_assoc()['ch_name'] : '未填写';
- ?>
- </div>
- <div class="col5">
- <?php
- $country = $conn->query("SELECT countryName FROM country WHERE id=" . (int)$row['cs_country']);
- echo $country->num_rows > 0 ? $country->fetch_assoc()['countryName'] : '未填写';
- ?>
- </div>
- <div class="col6">
- <?php
- $clientType = $conn->query("SELECT businessType FROM clienttype WHERE id=" . (int)$row['cs_type']);
- echo $clientType->num_rows > 0 ? $clientType->fetch_assoc()['businessType'] : '未填写';
- ?>
- </div>
- <div class="col6">
- <?php
- switch ($row['cs_deal']) {
- case 3: echo '<span style="color:red;">成交</span>'; break;
- case 2: echo '明确需求'; break;
- case 1: echo '背景调查'; break;
- default: echo '无响应';
- }
- ?>
- </div>
- <div class="colmark colormark">
- <ul class="colorlist" data-id="<?= $row['id'] ?>">
- <li value="1" class="color1"></li>
- <li value="2" class="color2"></li>
- <li value="3" class="color3"></li>
- <li value="4" class="color4"></li>
- <li value="0" class="color0"></li>
- </ul>
- </div>
- <div class="col6"><?= $row['cs_addtime'] ?></div>
- <div class="col9">
- <a href="customerEdit.php?Keys=<?= $keys ?>&fliterDeal=<?= $filters['Deal'] ?>&fliterBusiness=<?= $filters['Business'] ?>&Page=<?= $page ?>&act=edit&id=<?= $row['id'] ?>" class="ico_edit ico">修改</a>
- <a href="order_add.php?customer_id=<?= $row['id'] ?>" class="ico_add ico">添加订单</a>
- </div>
- </div>
- <div class="notepanel clear">
- <div class="noteItem">联系方式</div>
- <div class="lx">
- <?php
- // Fetch all contacts for this customer
- $contact_sql = "SELECT * FROM customer_contact WHERE customer_id = " . $row['id'];
- $contact_result = mysqli_query($conn, $contact_sql);
- while ($contact = mysqli_fetch_assoc($contact_result)) {
- ?>
- <div class="contact-block">
- <?php if(!empty($contact['contact_name'])): ?>
- <div class="contact-name"><?= $contact['contact_name'] ?></div>
- <?php endif; ?>
- <div class="tel">
- <?php if(!empty($contact['tel_1'])): ?>
- <div><?= $contact['tel_1'] ?></div>
- <?php endif; ?>
- <?php if(!empty($contact['tel_2'])): ?>
- <div><?= $contact['tel_2'] ?></div>
- <?php endif; ?>
- <?php if(!empty($contact['tel_3'])): ?>
- <div><?= $contact['tel_3'] ?></div>
- <?php endif; ?>
- </div>
- <div class="mail">
- <?php if(!empty($contact['email_1'])): ?>
- <div><a href="mailto:<?= $contact['email_1'] ?>"><?= $contact['email_1'] ?></a></div>
- <?php endif; ?>
- <?php if(!empty($contact['email_2'])): ?>
- <div><a href="mailto:<?= $contact['email_2'] ?>"><?= $contact['email_2'] ?></a></div>
- <?php endif; ?>
- <?php if(!empty($contact['email_3'])): ?>
- <div><a href="mailto:<?= $contact['email_3'] ?>"><?= $contact['email_3'] ?></a></div>
- <?php endif; ?>
- </div>
- <div class="whatsapp">
- <?php if(!empty($contact['whatsapp_1'])): ?>
- <div><?= $contact['whatsapp_1'] ?></div>
- <?php endif; ?>
- <?php if(!empty($contact['whatsapp_2'])): ?>
- <div><?= $contact['whatsapp_2'] ?></div>
- <?php endif; ?>
- <?php if(!empty($contact['whatsapp_3'])): ?>
- <div><?= $contact['whatsapp_3'] ?></div>
- <?php endif; ?>
- </div>
- <div class="wechat">
- <?php if(!empty($contact['wechat_1'])): ?>
- <div><?= $contact['wechat_1'] ?></div>
- <?php endif; ?>
- <?php if(!empty($contact['wechat_2'])): ?>
- <div><?= $contact['wechat_2'] ?></div>
- <?php endif; ?>
- <?php if(!empty($contact['wechat_3'])): ?>
- <div><?= $contact['wechat_3'] ?></div>
- <?php endif; ?>
- </div>
- <div class="linkedin">
- <?php if(!empty($contact['linkedin_1'])): ?>
- <div><?= $contact['linkedin_1'] ?></div>
- <?php endif; ?>
- <?php if(!empty($contact['linkedin_2'])): ?>
- <div><?= $contact['linkedin_2'] ?></div>
- <?php endif; ?>
- <?php if(!empty($contact['linkedin_3'])): ?>
- <div><?= $contact['linkedin_3'] ?></div>
- <?php endif; ?>
- </div>
- <div class="facebook">
- <?php if(!empty($contact['facebook_1'])): ?>
- <div><?= $contact['facebook_1'] ?></div>
- <?php endif; ?>
- <?php if(!empty($contact['facebook_2'])): ?>
- <div><?= $contact['facebook_2'] ?></div>
- <?php endif; ?>
- <?php if(!empty($contact['facebook_3'])): ?>
- <div><?= $contact['facebook_3'] ?></div>
- <?php endif; ?>
- </div>
- <div class="alibaba">
- <?php if(!empty($contact['alibaba_1'])): ?>
- <div><?= $contact['alibaba_1'] ?></div>
- <?php endif; ?>
- <?php if(!empty($contact['alibaba_2'])): ?>
- <div><?= $contact['alibaba_2'] ?></div>
- <?php endif; ?>
- <?php if(!empty($contact['alibaba_3'])): ?>
- <div><?= $contact['alibaba_3'] ?></div>
- <?php endif; ?>
- </div>
- </div>
- <?php } ?>
- </div>
- <div class="noteItem2">备注</div>
- <div class="notecontent"><?= htmlUnCode($row['cs_note']) ?></div>
- </div>
- <?php
- }
- } else {
- if (empty($keys)) {
- echo '<tr><div align="center" colspan="9">Sorry,当前暂无信息</div></tr>';
- } else {
- echo '<tr><div align="center" colspan="9"><a href="?">Sorry,没有找到"' .
- htmlspecialcharsFix($keyscode) . '"相关的信息,点击返回</a></div></tr>';
- }
- }
- ?>
- <div colspan="9">
- <div class="showpagebox">
- <?php
- if ($totalPages > 1) {
- $pageName = "?Keys=$keys$urlStr&";
- $pageLen = 3;
- if ($page > 1) {
- echo "<a href=\"{$pageName}Page=1\">首页</a>";
- echo "<a href=\"{$pageName}Page=" . ($page - 1) . "\">上一页</a>";
- }
- if ($pageLen * 2 + 1 >= $totalPages) {
- $startPage = 1;
- $endPage = $totalPages;
- } else {
- if ($page <= $pageLen + 1) {
- $startPage = 1;
- $endPage = $pageLen * 2 + 1;
- } else {
- $startPage = $page - $pageLen;
- $endPage = $page + $pageLen;
- }
- if ($page + $pageLen > $totalPages) {
- $startPage = $totalPages - $pageLen * 2;
- $endPage = $totalPages;
- }
- }
- for ($i = $startPage; $i <= $endPage; $i++) {
- if ($i == $page) {
- echo "<a class=\"current\">$i</a>";
- } else {
- echo "<a href=\"{$pageName}Page=$i\">$i</a>";
- }
- }
- if ($page < $totalPages) {
- if ($totalPages - $page > $pageLen) {
- echo "<a href=\"{$pageName}Page=$totalPages\">...$totalPages</a>";
- }
- echo "<a href=\"{$pageName}Page=" . ($page + 1) . "\">下一页</a>";
- echo "<a href=\"{$pageName}Page=$totalPages\">尾页</a>";
- }
- }
- ?>
- </div>
- <?php require_once 'postchkbox.php'; ?>
- </div>
- </div>
- </form>
- </div>
- </body>
- </html>
|