123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990 |
- <?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']));
-
- switch($chkact) {
- case "0":
- case "1":
- $sql = "UPDATE customer SET cs_state = $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,
- 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%')";
- }
- $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;
- }
- </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 (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;
- }
- $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");
- 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"
- value="<?= empty($keyscode) ? '请输入搜索关键词' : $keyscode ?>"
- onFocus="if(this.value == '<?= empty($keyscode) ? '请输入搜索关键词' : $keyscode ?>'){this.value='';}"
- onBlur="if(this.value == ''){this.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,
- 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.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 cc.contact_name LIKE '%$searchPattern%'
- OR cc.tel_1 LIKE '%$searchPattern%'
- OR cc.tel_2 LIKE '%$searchPattern%'
- OR cc.tel_3 LIKE '%$searchPattern%'
- OR cc.email_1 LIKE '%$searchPattern%'
- OR cc.email_2 LIKE '%$searchPattern%'
- OR cc.email_3 LIKE '%$searchPattern%'
- OR cc.wechat_1 LIKE '%$searchPattern%'
- OR cc.wechat_2 LIKE '%$searchPattern%'
- OR cc.wechat_3 LIKE '%$searchPattern%'
- OR cc.whatsapp_1_format LIKE '%$searchPattern%'
- OR cc.whatsapp_2_format LIKE '%$searchPattern%'
- OR cc.whatsapp_3_format LIKE '%$searchPattern%'
- OR cc.linkedin_1 LIKE '%$searchPattern%'
- OR cc.linkedin_2 LIKE '%$searchPattern%'
- OR cc.linkedin_3 LIKE '%$searchPattern%'
- OR cc.facebook_1 LIKE '%$searchPattern%'
- OR cc.facebook_2 LIKE '%$searchPattern%'
- OR cc.facebook_3 LIKE '%$searchPattern%'
- OR cc.alibaba_1 LIKE '%$searchPattern%'
- OR cc.alibaba_2 LIKE '%$searchPattern%'
- OR cc.alibaba_3 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">
- <div class="tel">
- <?php if(!empty($row['tel_1'])): ?>
- <div><?= $row['tel_1'] ?></div>
- <?php endif; ?>
- <?php if(!empty($row['tel_2'])): ?>
- <div><?= $row['tel_2'] ?></div>
- <?php endif; ?>
- <?php if(!empty($row['tel_3'])): ?>
- <div><?= $row['tel_3'] ?></div>
- <?php endif; ?>
- </div>
- <div class="mail">
- <?php if(!empty($row['email_1'])): ?>
- <div><a href="mailto:<?= $row['email_1'] ?>"><?= $row['email_1'] ?></a></div>
- <?php endif; ?>
- <?php if(!empty($row['email_2'])): ?>
- <div><a href="mailto:<?= $row['email_2'] ?>"><?= $row['email_2'] ?></a></div>
- <?php endif; ?>
- <?php if(!empty($row['email_3'])): ?>
- <div><a href="mailto:<?= $row['email_3'] ?>"><?= $row['email_3'] ?></a></div>
- <?php endif; ?>
- </div>
- <div class="whatsapp">
- <?php if(!empty($row['whatsapp_1'])): ?>
- <div><?= $row['whatsapp_1'] ?></div>
- <?php endif; ?>
- <?php if(!empty($row['whatsapp_2'])): ?>
- <div><?= $row['whatsapp_2'] ?></div>
- <?php endif; ?>
- <?php if(!empty($row['whatsapp_3'])): ?>
- <div><?= $row['whatsapp_3'] ?></div>
- <?php endif; ?>
- </div>
- <div class="wechat">
- <?php if(!empty($row['wechat_1'])): ?>
- <div><?= $row['wechat_1'] ?></div>
- <?php endif; ?>
- <?php if(!empty($row['wechat_2'])): ?>
- <div><?= $row['wechat_2'] ?></div>
- <?php endif; ?>
- <?php if(!empty($row['wechat_3'])): ?>
- <div><?= $row['wechat_3'] ?></div>
- <?php endif; ?>
- </div>
- <div class="linkedin">
- <?php if(!empty($row['linkedin_1'])): ?>
- <div><?= $row['linkedin_1'] ?></div>
- <?php endif; ?>
- <?php if(!empty($row['linkedin_2'])): ?>
- <div><?= $row['linkedin_2'] ?></div>
- <?php endif; ?>
- <?php if(!empty($row['linkedin_3'])): ?>
- <div><?= $row['linkedin_3'] ?></div>
- <?php endif; ?>
- </div>
- <div class="facebook">
- <?php if(!empty($row['facebook_1'])): ?>
- <div><?= $row['facebook_1'] ?></div>
- <?php endif; ?>
- <?php if(!empty($row['facebook_2'])): ?>
- <div><?= $row['facebook_2'] ?></div>
- <?php endif; ?>
- <?php if(!empty($row['facebook_3'])): ?>
- <div><?= $row['facebook_3'] ?></div>
- <?php endif; ?>
- </div>
- <div class="alibaba">
- <?php if(!empty($row['alibaba_1'])): ?>
- <div><?= $row['alibaba_1'] ?></div>
- <?php endif; ?>
- <?php if(!empty($row['alibaba_2'])): ?>
- <div><?= $row['alibaba_2'] ?></div>
- <?php endif; ?>
- <?php if(!empty($row['alibaba_3'])): ?>
- <div><?= $row['alibaba_3'] ?></div>
- <?php endif; ?>
- </div>
- </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>
|