customers.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. <?php
  2. require_once 'conn.php';
  3. checkLogin();
  4. // 辅助函数
  5. function textDecode($str) {
  6. return htmlspecialchars_decode($str, ENT_QUOTES);
  7. }
  8. function htmlDecode($str) {
  9. return htmlspecialchars_decode($str, ENT_QUOTES);
  10. }
  11. $act = $_GET['act'] ?? '';
  12. $urlStr = '';
  13. // 处理保存操作
  14. if ($act == "save") {
  15. $isedit = false;
  16. $id = $_POST['id'] ?? '';
  17. if (!empty($id) && is_numeric($id)) {
  18. $isedit = true;
  19. }
  20. // 获取表单数据 - 客户基本信息
  21. $cs_code = textEncode($_POST['cs_code']);
  22. $cs_company = textEncode($_POST['cs_company']);
  23. $cs_belong = $_POST['cs_belong'];
  24. $cs_country = $_POST['cs_country'];
  25. $cs_from = $_POST['cs_from'];
  26. $cs_state = $_POST['cs_state'];
  27. $cs_deal = $_POST['cs_deal'];
  28. $no_content = htmlEncode($_POST['no_content']);
  29. $allowedit = isset($_POST['allowedit']) ? 1 : 0;
  30. $cs_address = textEncode($_POST['cs_address'] ?? '');
  31. // 获取表单数据 - 联系人信息
  32. $contact_name = textEncode($_POST['cs_name']);
  33. $tel = textEncode($_POST['cs_tel']);
  34. $tel_format = textEncode($_POST['cs_telformat'] ?? '');
  35. $tel_bu = textEncode($_POST['cs_telBu'] ?? '');
  36. $email = textEncode($_POST['cs_email']);
  37. $email_bu = textEncode($_POST['cs_emailBu'] ?? '');
  38. $whatsapp = textEncode($_POST['cs_whatsapp']);
  39. $whatsapp_format = textEncode($_POST['cs_whatsappformat'] ?? '');
  40. $whatsapp_bu = textEncode($_POST['cs_whatsappBu'] ?? '');
  41. $wechat = textEncode($_POST['cs_wechat']);
  42. $wechat_bu = textEncode($_POST['cs_wechatBu'] ?? '');
  43. $linkedin = textEncode($_POST['cs_linkedin']);
  44. $linkedin_bu = textEncode($_POST['cs_linkedinBu'] ?? '');
  45. $facebook = textEncode($_POST['cs_facebook']);
  46. $facebook_bu = textEncode($_POST['cs_facebookBu'] ?? '');
  47. $alibaba = textEncode($_POST['cs_alibaba']);
  48. $alibaba_bu = textEncode($_POST['cs_alibabaBu'] ?? '');
  49. if ($isedit) {
  50. // 更新现有记录
  51. $sql = "SELECT cs_chain FROM customer WHERE id = $id";
  52. $result = mysqli_query($conn, $sql);
  53. if ($row = mysqli_fetch_assoc($result)) {
  54. $cs_chain = $row['cs_chain'];
  55. $chain_array = explode(',', $cs_chain);
  56. $last_item = end($chain_array);
  57. if ($last_item != $cs_belong) {
  58. $cs_chain .= ",$cs_belong";
  59. }
  60. // 更新客户基本信息
  61. $sql = "UPDATE customer SET
  62. cs_code = '$cs_code',
  63. cs_company = '$cs_company',
  64. cs_belong = '$cs_belong',
  65. cs_country = '$cs_country',
  66. cs_address = '$cs_address',
  67. cs_from = '$cs_from',
  68. cs_state = '$cs_state',
  69. cs_deal = '$cs_deal',
  70. cs_note = '$no_content',
  71. allowedit = $allowedit,
  72. cs_chain = '$cs_chain',
  73. cs_updatetime = NOW()
  74. WHERE id = $id";
  75. mysqli_query($conn, $sql);
  76. // 检查是否已有联系人记录
  77. $contact_sql = "SELECT id FROM customer_contact WHERE customer_id = $id";
  78. $contact_result = mysqli_query($conn, $contact_sql);
  79. if ($contact_row = mysqli_fetch_assoc($contact_result)) {
  80. // 更新联系人信息
  81. $contact_id = $contact_row['id'];
  82. $sql = "UPDATE customer_contact SET
  83. contact_name = '$contact_name',
  84. tel = '$tel',
  85. tel_format = '$tel_format',
  86. tel_bu = '$tel_bu',
  87. email = '$email',
  88. email_bu = '$email_bu',
  89. whatsapp = '$whatsapp',
  90. whatsapp_format = '$whatsapp_format',
  91. whatsapp_bu = '$whatsapp_bu',
  92. wechat = '$wechat',
  93. wechat_bu = '$wechat_bu',
  94. linkedin = '$linkedin',
  95. linkedin_bu = '$linkedin_bu',
  96. facebook = '$facebook',
  97. facebook_bu = '$facebook_bu',
  98. alibaba = '$alibaba',
  99. alibaba_bu = '$alibaba_bu',
  100. updated_at = NOW()
  101. WHERE id = $contact_id";
  102. mysqli_query($conn, $sql);
  103. } else {
  104. // 插入新的联系人记录
  105. $sql = "INSERT INTO customer_contact (
  106. customer_id, contact_name, tel, tel_format, tel_bu,
  107. email, email_bu, whatsapp, whatsapp_format, whatsapp_bu,
  108. wechat, wechat_bu, linkedin, linkedin_bu, facebook,
  109. facebook_bu, alibaba, alibaba_bu, created_at, updated_at
  110. ) VALUES (
  111. $id, '$contact_name', '$tel', '$tel_format', '$tel_bu',
  112. '$email', '$email_bu', '$whatsapp', '$whatsapp_format', '$whatsapp_bu',
  113. '$wechat', '$wechat_bu', '$linkedin', '$linkedin_bu', '$facebook',
  114. '$facebook_bu', '$alibaba', '$alibaba_bu', NOW(), NOW()
  115. )";
  116. mysqli_query($conn, $sql);
  117. }
  118. $page = $_GET['Page'] ?? '';
  119. $keys = urlencode($_GET['Keys'] ?? '');
  120. header("Location: ?keys=$keys&Page=$page$urlStr");
  121. exit;
  122. }
  123. } else {
  124. // 创建新记录
  125. // 插入客户基本信息
  126. $sql = "INSERT INTO customer (
  127. cs_code, cs_company, cs_country, cs_address, cs_from,
  128. cs_belong, cs_state, cs_deal, cs_note, allowedit,
  129. cs_chain, cs_addtime, cs_updatetime
  130. ) VALUES (
  131. '$cs_code', '$cs_company', '$cs_country', '$cs_address', '$cs_from',
  132. '$cs_belong', '$cs_state', '$cs_deal', '$no_content', $allowedit,
  133. '$cs_belong', NOW(), NOW()
  134. )";
  135. mysqli_query($conn, $sql);
  136. $new_customer_id = mysqli_insert_id($conn);
  137. // 插入联系人信息
  138. if ($new_customer_id > 0) {
  139. $sql = "INSERT INTO customer_contact (
  140. customer_id, contact_name, tel, tel_format, tel_bu,
  141. email, email_bu, whatsapp, whatsapp_format, whatsapp_bu,
  142. wechat, wechat_bu, linkedin, linkedin_bu, facebook,
  143. facebook_bu, alibaba, alibaba_bu, created_at, updated_at
  144. ) VALUES (
  145. $new_customer_id, '$contact_name', '$tel', '$tel_format', '$tel_bu',
  146. '$email', '$email_bu', '$whatsapp', '$whatsapp_format', '$whatsapp_bu',
  147. '$wechat', '$wechat_bu', '$linkedin', '$linkedin_bu', '$facebook',
  148. '$facebook_bu', '$alibaba', '$alibaba_bu', NOW(), NOW()
  149. )";
  150. mysqli_query($conn, $sql);
  151. $page = $_GET['Page'] ?? '';
  152. $keys = urlencode($_GET['Keys'] ?? '');
  153. header("Location: ?keys=$keys&Page=$page$urlStr");
  154. exit;
  155. }
  156. }
  157. }
  158. // 处理编辑操作
  159. if ($act == "edit") {
  160. $id = $_GET['id'] ?? '';
  161. $isedit = false;
  162. if (!empty($id) && is_numeric($id)) {
  163. $isedit = true;
  164. }
  165. if ($isedit) {
  166. // 联合查询客户基本信息和联系人信息
  167. $sql = "SELECT c.*, cc.contact_name, cc.tel, cc.tel_format, cc.tel_bu,
  168. cc.email, cc.email_bu, cc.whatsapp, cc.whatsapp_format, cc.whatsapp_bu,
  169. cc.wechat, cc.wechat_bu, cc.linkedin, cc.linkedin_bu, cc.facebook,
  170. cc.facebook_bu, cc.alibaba, cc.alibaba_bu, n.c_code
  171. FROM customer c
  172. LEFT JOIN customer_contact cc ON c.id = cc.customer_id
  173. WHERE c.id = $id";
  174. $result = mysqli_query($conn, $sql);
  175. if ($row = mysqli_fetch_assoc($result)) {
  176. $cs_code = textDecode($row['cs_code']);
  177. $cs_company = textDecode($row['cs_company']);
  178. $cs_name = textDecode($row['contact_name']);
  179. $cs_country = $row['cs_country'];
  180. $cs_from = $row['cs_from'];
  181. $cs_tel = textDecode($row['tel']);
  182. $cs_telBu = textDecode($row['tel_bu']);
  183. $cs_email = textDecode($row['email']);
  184. $cs_emailBu = textDecode($row['email_bu']);
  185. $cs_whatsapp = textDecode($row['whatsapp']);
  186. $cs_whatsappBu = textDecode($row['whatsapp_bu']);
  187. $cs_wechat = textDecode($row['wechat']);
  188. $cs_wechatBu = textDecode($row['wechat_bu']);
  189. $cs_linkedin = textDecode($row['linkedin']);
  190. $cs_linkedinBu = textDecode($row['linkedin_bu']);
  191. $cs_facebook = textDecode($row['facebook']);
  192. $cs_facebookBu = textDecode($row['facebook_bu']);
  193. $cs_alibaba = textDecode($row['alibaba']);
  194. $cs_alibabaBu = textDecode($row['alibaba_bu']);
  195. $cs_address = textDecode($row['cs_address']);
  196. $cs_addtime = $row['cs_addtime'];
  197. $cs_updatetime = $row['cs_updatetime'];
  198. $cs_belong = $row['cs_belong'];
  199. $cs_state = $row['cs_state'];
  200. $cs_deal = $row['cs_deal'];
  201. $cs_note = htmlDecode($row['cs_note']);
  202. $allowedit = $row['allowedit'];
  203. }
  204. }
  205. }
  206. // 处理批量操作
  207. if ($act == "postchk") {
  208. if (isset($_POST['chkbox']) && isset($_POST['chkact'])) {
  209. $chkact = $_POST['chkact'];
  210. $ids = implode(',', array_map('intval', $_POST['chkbox']));
  211. switch($chkact) {
  212. case "0":
  213. case "1":
  214. $sql = "UPDATE customer SET cs_state = $chkact WHERE id IN ($ids)";
  215. break;
  216. case "-1":
  217. // 删除客户记录和联系人记录(依靠外键级联删除)
  218. $sql = "DELETE FROM customer WHERE id IN ($ids)";
  219. break;
  220. }
  221. if (isset($sql)) {
  222. mysqli_query($conn, $sql);
  223. }
  224. $keys = urlencode($_GET['Keys'] ?? '');
  225. $page = $_GET['Page'] ?? '';
  226. header("Location: ?keys=$keys&Page=$page$urlStr");
  227. exit;
  228. }
  229. }
  230. // 处理筛选条件
  231. $fliterQudao = $_GET['fliterQudao'] ?? '';
  232. $fliterDeal = $_GET['fliterDeal'] ?? '';
  233. $fliterTeam = $_GET['fliterTeam'] ?? '';
  234. $fliterContact = $_GET['fliterContact'] ?? '';
  235. $fliterEmployee = $_GET['fliterEmployee'] ?? '';
  236. $fliterStr = "";
  237. if (!empty($fliterQudao)) {
  238. $fliterStr .= " AND cs_from = " . intval($fliterQudao);
  239. $urlStr .= "&fliterQudao=" . $fliterQudao;
  240. }
  241. if (!empty($fliterDeal)) {
  242. $fliterStr .= " AND cs_deal = " . intval($fliterDeal);
  243. $urlStr .= "&fliterDeal=" . $fliterDeal;
  244. }
  245. if (!empty($fliterTeam)) {
  246. $fliterStr .= " AND (cs_belong = " . intval($fliterTeam) .
  247. " OR cs_belong IN (SELECT id FROM employee WHERE em_role = " . intval($fliterTeam) . "))";
  248. $urlStr .= "&fliterTeam=" . $fliterTeam;
  249. }
  250. if (!empty($fliterEmployee)) {
  251. $fliterStr .= " AND cs_belong = " . intval($fliterEmployee);
  252. $urlStr .= "&fliterEmployee=" . $fliterEmployee;
  253. }
  254. if (!empty($fliterContact)) {
  255. switch($fliterContact) {
  256. case "1": $fliterStr .= " AND cs_tel != ''"; break;
  257. case "2": $fliterStr .= " AND cs_wechat != ''"; break;
  258. case "3": $fliterStr .= " AND cs_whatsapp != ''"; break;
  259. case "4": $fliterStr .= " AND cs_email != ''"; break;
  260. case "5": $fliterStr .= " AND cs_linkedin != ''"; break;
  261. case "6": $fliterStr .= " AND cs_facebook != ''"; break;
  262. case "7": $fliterStr .= " AND cs_alibaba != ''"; break;
  263. }
  264. $urlStr .= "&fliterContact=" . $fliterContact;
  265. }
  266. // 搜索和排序
  267. $keys = $_GET['Keys'] ?? '';
  268. $keyscode = textEncode($keys);
  269. $page = $_GET['Page'] ?? 1;
  270. $ord = $_GET['Ord'] ?? '';
  271. $ordStr = !empty($ord) ? "$ord," : "";
  272. // 构建查询SQL - 修改为联合查询
  273. $sqlStr = "SELECT c.id, c.cs_code, c.cs_company, c.cs_country, c.cs_address, c.cs_from,
  274. c.cs_deal, c.cs_addtime, c.cs_updatetime, c.cs_belong, c.cs_note, c.cs_claimFrom,
  275. c.cs_chain, c.cs_dealdate, cc.contact_name as cs_name, cc.tel as cs_tel,
  276. cc.email as cs_email, cc.whatsapp as cs_whatsapp, cc.wechat as cs_wechat,
  277. cc.linkedin as cs_linkedin, cc.facebook as cs_facebook, cc.alibaba as cs_alibaba,
  278. cc.tel_format as cs_telformat, cc.whatsapp_format as cs_whatsappformat
  279. FROM customer c
  280. LEFT JOIN customer_contact cc ON c.id = cc.customer_id
  281. WHERE (c.cs_code LIKE '%$keyscode%'
  282. OR cc.contact_name LIKE '%$keyscode%'
  283. OR cc.wechat LIKE '%$keyscode%'
  284. OR cc.alibaba LIKE '%$keyscode%'
  285. OR cc.tel_format LIKE '%$keyscode%'
  286. OR cc.whatsapp_format LIKE '%$keyscode%'
  287. OR cc.email LIKE '%$keyscode%')
  288. $fliterStr
  289. ORDER BY {$ordStr}c.cs_updatetime DESC";
  290. ?>
  291. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  292. <html xmlns="http://www.w3.org/1999/xhtml">
  293. <head>
  294. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  295. <title>客户列表</title>
  296. <link rel="stylesheet" href="css/common.css" type="text/css" />
  297. <link rel="stylesheet" href="css/alert.css" type="text/css" />
  298. <script src="js/jquery-1.7.2.min.js"></script>
  299. <script src="js/js.js"></script>
  300. <style>
  301. body {
  302. margin: 0;
  303. padding: 20px;
  304. background: #fff;
  305. }
  306. #man_zone {
  307. margin-left: 0;
  308. }
  309. </style>
  310. </head>
  311. <body>
  312. <div id="man_zone">
  313. <?php
  314. $keys = $_GET['Keys'] ?? '';
  315. $keys = str_replace([" ", "+"], "", $keys);
  316. $keyscode = textEncode($keys);
  317. $page = $_GET['Page'] ?? 1;
  318. $filters = [
  319. 'Country' => $_GET['fliterCountry'] ?? '',
  320. 'Qudao' => $_GET['fliterQudao'] ?? '',
  321. 'Deal' => $_GET['fliterDeal'] ?? '',
  322. 'Business' => $_GET['fliterBusiness'] ?? '',
  323. 'Contact' => $_GET['fliterContact'] ?? ''
  324. ];
  325. $filterStr = "";
  326. $urlStr = "";
  327. // Build filter conditions
  328. if (!empty($filters['Country'])) {
  329. $filterStr .= " AND cs_country=" . (int)$filters['Country'];
  330. $urlStr .= "&fliterCountry=" . $filters['Country'];
  331. }
  332. if (!empty($filters['Qudao'])) {
  333. $filterStr .= " AND cs_from=" . (int)$filters['Qudao'];
  334. $urlStr .= "&fliterQudao=" . $filters['Qudao'];
  335. }
  336. if (!empty($filters['Deal'])) {
  337. $filterStr .= " AND cs_deal=" . (int)$filters['Deal'];
  338. $urlStr .= "&fliterDeal=" . $filters['Deal'];
  339. }
  340. if (!empty($filters['Business'])) {
  341. $filterStr .= " AND cs_type=" . (int)$filters['Business'];
  342. $urlStr .= "&fliterBusiness=" . $filters['Business'];
  343. }
  344. if (!empty($filters['Contact'])) {
  345. switch ($filters['Contact']) {
  346. case "1": $filterStr .= " AND cs_tel<>''"; break;
  347. case "2": $filterStr .= " AND cs_wechat<>''"; break;
  348. case "3": $filterStr .= " AND cs_whatsapp<>''"; break;
  349. case "4": $filterStr .= " AND cs_email<>''"; break;
  350. case "5": $filterStr .= " AND cs_linkedin<>''"; break;
  351. case "6": $filterStr .= " AND cs_facebook<>''"; break;
  352. default: $filterStr .= " AND cs_alibaba<>''";
  353. }
  354. $urlStr .= "&fliterContact=" . $filters['Contact'];
  355. }
  356. $keys = urlencode($keys);
  357. $hrefstr = "?keys=" . $keys;
  358. ?>
  359. <form id="form1" method="post" action="?act=postchk&Keys=<?= $keys ?>&Page=<?= $page ?>" onSubmit="return false">
  360. <div class="fastSelect clear">
  361. <H1>搜索条件</H1>
  362. <div class="selectItem">
  363. <label>区域</label>
  364. <select name="fliterCountry" class="filterSearch">
  365. <option value="">请选择国家地区</option>
  366. <?php
  367. $result = $conn->query("SELECT id, countryName FROM country");
  368. while ($row = $result->fetch_assoc()) {
  369. $selected = ($filters['Country'] == $row['id']) ? ' selected' : '';
  370. echo "<option value=\"{$row['id']}\"$selected>{$row['countryName']}</option>";
  371. }
  372. ?>
  373. </select>
  374. </div>
  375. <div class="selectItem">
  376. <label>来源渠道</label>
  377. <select name="fliterQudao" class="filterSearch">
  378. <option value="">请选择渠道</option>
  379. <?php
  380. $result = $conn->query("SELECT id, ch_name FROM qudao");
  381. while ($row = $result->fetch_assoc()) {
  382. $selected = ($filters['Qudao'] == $row['id']) ? ' selected' : '';
  383. echo "<option value=\"{$row['id']}\"$selected>{$row['ch_name']}</option>";
  384. }
  385. ?>
  386. </select>
  387. </div>
  388. <div class="selectItem">
  389. <label>跟进阶段</label>
  390. <select name="fliterDeal" class="filterSearch">
  391. <option value="">请选择</option>
  392. <option value="1"<?= ($filters['Deal'] == "1") ? ' selected' : '' ?>>背景调查</option>
  393. <option value="2"<?= ($filters['Deal'] == "2") ? ' selected' : '' ?>>明确需求</option>
  394. <option value="3"<?= ($filters['Deal'] == "3") ? ' selected' : '' ?>>已成交</option>
  395. </select>
  396. </div>
  397. <div class="selectItem">
  398. <label>客户类型</label>
  399. <select name="fliterBusiness" class="filterSearch">
  400. <option value="">请选择</option>
  401. <?php
  402. $result = $conn->query("SELECT id, businessType FROM clienttype");
  403. while ($row = $result->fetch_assoc()) {
  404. $selected = ($filters['Business'] == $row['id']) ? ' selected' : '';
  405. echo "<option value=\"{$row['id']}\"$selected>{$row['businessType']}</option>";
  406. }
  407. ?>
  408. </select>
  409. </div>
  410. <div class="selectItem">
  411. <label>联系方式</label>
  412. <select name="fliterContact" class="filterSearch">
  413. <option value="">请选择</option>
  414. <option value="1"<?= ($filters['Contact'] == "1") ? ' selected' : '' ?>>电话</option>
  415. <option value="2"<?= ($filters['Contact'] == "2") ? ' selected' : '' ?>>微信</option>
  416. <option value="3"<?= ($filters['Contact'] == "3") ? ' selected' : '' ?>>WhatsApp</option>
  417. <option value="4"<?= ($filters['Contact'] == "4") ? ' selected' : '' ?>>邮箱</option>
  418. <option value="5"<?= ($filters['Contact'] == "5") ? ' selected' : '' ?>>领英</option>
  419. <option value="6"<?= ($filters['Contact'] == "6") ? ' selected' : '' ?>>Facebook</option>
  420. <option value="7"<?= ($filters['Contact'] == "7") ? ' selected' : '' ?>>阿里巴巴</option>
  421. </select>
  422. </div>
  423. <div class="inputSearch">
  424. <input type="text" id="keys" class="inputTxt"
  425. value="<?= empty($keyscode) ? '请输入搜索关键词' : $keyscode ?>"
  426. onFocus="if(this.value == '<?= empty($keyscode) ? '请输入搜索关键词' : $keyscode ?>'){this.value='';}"
  427. onBlur="if(this.value == ''){this.value='<?= empty($keyscode) ? '请输入搜索关键词' : $keyscode ?>';}"
  428. onKeyDown="if(event.keyCode==13){location.href='?Keys='+escape(document.getElementById('keys').value)}" />
  429. <input type="button" id="searchgo" class="searchgo" value="go"
  430. onClick="location.href='?Keys='+escape(document.getElementById('keys').value)" />
  431. </div>
  432. </div>
  433. <div class="table2 em<?= $_SESSION['employee_id'] ?>">
  434. <div class="theader">
  435. <div class="col1"><input type="checkbox" name="chkall" id="chkall" onClick="chkboxall(this,'chkbox')" /></div>
  436. <div class="col2">序号</div>
  437. <div class="col3">客户编号</div>
  438. <div class="col4">渠道来源</div>
  439. <div class="col5">区域</div>
  440. <div class="col6">客户类型</div>
  441. <div class="col6">跟进阶段</div>
  442. <div class="colmark">颜色标记</div>
  443. <div class="col6">录入时间</div>
  444. <div class="col9">操作</div>
  445. </div>
  446. <?php
  447. $sql = "SELECT c.id, c.cs_code, c.cs_from, c.cs_country, c.cs_type, c.cs_deal, c.cs_addtime,
  448. c.colortag, c.cs_note, c.cs_claimFrom, cc.tel as cs_tel, cc.email as cs_email,
  449. cc.whatsapp as cs_whatsapp, cc.wechat as cs_wechat, cc.linkedin as cs_linkedin,
  450. cc.facebook as cs_facebook, cc.alibaba as cs_alibaba, cc.tel_format as cs_telformat,
  451. cc.whatsapp_format as cs_whatsappformat
  452. FROM customer c
  453. LEFT JOIN customer_contact cc ON c.id = cc.customer_id
  454. WHERE c.is_silent=0 AND c.cs_deal>0 AND c.cs_belong=" . (int)$_SESSION['employee_id'];
  455. $searchPattern = mysqli_real_escape_string($conn, $keyscode);
  456. if(!empty($searchPattern)) {
  457. $sql .= " AND (c.cs_code LIKE '%$searchPattern%'
  458. OR cc.contact_name LIKE '%$searchPattern%'
  459. OR cc.email LIKE '%$searchPattern%'
  460. OR cc.wechat LIKE '%$searchPattern%'
  461. OR cc.tel_format LIKE '%$searchPattern%'
  462. OR cc.whatsapp_format LIKE '%$searchPattern%'
  463. OR c.cs_code LIKE '%$searchPattern%')";
  464. }
  465. $sql .= " $filterStr ORDER BY c.colortag DESC, c.id DESC";
  466. $result = mysqli_query($conn, $sql);
  467. // Pagination logic
  468. $perPage = 20;
  469. $totalRecords = mysqli_num_rows($result);
  470. $totalPages = max(1, ceil($totalRecords / $perPage));
  471. $page = max(1, min((int)$page, $totalPages));
  472. $offset = max(0, ($page - 1) * $perPage);
  473. // Add pagination to query
  474. $sql .= " LIMIT $offset, $perPage";
  475. $result = mysqli_query($conn, $sql);
  476. if (mysqli_num_rows($result) > 0) {
  477. $tempNum = $offset;
  478. while ($row = mysqli_fetch_assoc($result)) {
  479. $tempNum++;
  480. ?>
  481. <div class="tline color<?= $row['colortag'] ?>">
  482. <div class="col1" align="center"><input type="checkbox" name="chkbox" value="<?= $row['id'] ?>" /></div>
  483. <div class="col2"><?= $tempNum ?></div>
  484. <div class="col3 slidepanel"><?= $row['cs_code'] ?>
  485. <?php if ($row['cs_claimFrom'] > 0): ?>
  486. <img src="../images/yijiao.png" class="handover" title="来自认领">
  487. <?php endif; ?>
  488. </div>
  489. <div class="col4">
  490. <?php
  491. $qudao = $conn->query("SELECT ch_name FROM qudao WHERE id=" . (int)$row['cs_from']);
  492. echo $qudao->num_rows > 0 ? $qudao->fetch_assoc()['ch_name'] : '未填写';
  493. ?>
  494. </div>
  495. <div class="col5">
  496. <?php
  497. $country = $conn->query("SELECT countryName FROM country WHERE id=" . (int)$row['cs_country']);
  498. echo $country->num_rows > 0 ? $country->fetch_assoc()['countryName'] : '未填写';
  499. ?>
  500. </div>
  501. <div class="col6">
  502. <?php
  503. $clientType = $conn->query("SELECT businessType FROM clienttype WHERE id=" . (int)$row['cs_type']);
  504. echo $clientType->num_rows > 0 ? $clientType->fetch_assoc()['businessType'] : '未填写';
  505. ?>
  506. </div>
  507. <div class="col6">
  508. <?php
  509. switch ($row['cs_deal']) {
  510. case 3: echo '<span style="color:red;">成交</span>'; break;
  511. case 2: echo '明确需求'; break;
  512. case 1: echo '背景调查'; break;
  513. default: echo '无响应';
  514. }
  515. ?>
  516. </div>
  517. <div class="colmark colormark">
  518. <ul class="colorlist" data-id="<?= $row['id'] ?>">
  519. <li value="1" class="color1"></li>
  520. <li value="2" class="color2"></li>
  521. <li value="3" class="color3"></li>
  522. <li value="4" class="color4"></li>
  523. <li value="0" class="color0"></li>
  524. </ul>
  525. </div>
  526. <div class="col6"><?= $row['cs_addtime'] ?></div>
  527. <div class="col9">
  528. <a href="customerEdit.php?Keys=<?= $keys ?>&fliterDeal=<?= $filters['Deal'] ?>&fliterBusiness=<?= $filters['Business'] ?>&Page=<?= $page ?>&act=edit&id=<?= $row['id'] ?>" class="ico_edit ico">修改</a>
  529. </div>
  530. </div>
  531. <div class="notepanel clear">
  532. <div class="noteItem">联系方式</div>
  533. <div class="lx">
  534. <div class="tel"><?= $row['cs_tel'] ?></div>
  535. <div class="mail"><a href="mailto:<?= $row['cs_email'] ?>"><?= $row['cs_email'] ?></a></div>
  536. <div class="whatsapp"><?= $row['cs_whatsapp'] ?></div>
  537. <div class="wechat"><?= $row['cs_wechat'] ?></div>
  538. <div class="linkedin"><?= $row['cs_linkedin'] ?></div>
  539. <div class="facebook"><?= $row['cs_facebook'] ?></div>
  540. <div class="alibaba"><?= $row['cs_alibaba'] ?></div>
  541. </div>
  542. <div class="noteItem2">备注</div>
  543. <div class="notecontent"><?= htmlUnCode($row['cs_note']) ?></div>
  544. </div>
  545. <?php
  546. }
  547. } else {
  548. if (empty($keys)) {
  549. echo '<tr><div align="center" colspan="9">Sorry,当前暂无信息</div></tr>';
  550. } else {
  551. echo '<tr><div align="center" colspan="9"><a href="?">Sorry,没有找到"' .
  552. htmlspecialcharsFix($keyscode) . '"相关的信息,点击返回</a></div></tr>';
  553. }
  554. }
  555. ?>
  556. <div colspan="9">
  557. <div class="showpagebox">
  558. <?php
  559. if ($totalPages > 1) {
  560. $pageName = "?Keys=$keys$urlStr&";
  561. $pageLen = 3;
  562. if ($page > 1) {
  563. echo "<a href=\"{$pageName}Page=1\">首页</a>";
  564. echo "<a href=\"{$pageName}Page=" . ($page - 1) . "\">上一页</a>";
  565. }
  566. if ($pageLen * 2 + 1 >= $totalPages) {
  567. $startPage = 1;
  568. $endPage = $totalPages;
  569. } else {
  570. if ($page <= $pageLen + 1) {
  571. $startPage = 1;
  572. $endPage = $pageLen * 2 + 1;
  573. } else {
  574. $startPage = $page - $pageLen;
  575. $endPage = $page + $pageLen;
  576. }
  577. if ($page + $pageLen > $totalPages) {
  578. $startPage = $totalPages - $pageLen * 2;
  579. $endPage = $totalPages;
  580. }
  581. }
  582. for ($i = $startPage; $i <= $endPage; $i++) {
  583. if ($i == $page) {
  584. echo "<a class=\"current\">$i</a>";
  585. } else {
  586. echo "<a href=\"{$pageName}Page=$i\">$i</a>";
  587. }
  588. }
  589. if ($page < $totalPages) {
  590. if ($totalPages - $page > $pageLen) {
  591. echo "<a href=\"{$pageName}Page=$totalPages\">...$totalPages</a>";
  592. }
  593. echo "<a href=\"{$pageName}Page=" . ($page + 1) . "\">下一页</a>";
  594. echo "<a href=\"{$pageName}Page=$totalPages\">尾页</a>";
  595. }
  596. }
  597. ?>
  598. </div>
  599. <?php require_once 'postchkbox.php'; ?>
  600. </div>
  601. </div>
  602. </form>
  603. </div>
  604. </body>
  605. </html>