customers.php 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193
  1. <?php
  2. require_once('conn.php');
  3. checkLogin("信息管理");
  4. // 辅助函数
  5. function numFormat($str) {
  6. // 移除所有非数字字符
  7. $formatted = preg_replace('/[^0-9]/', '', $str);
  8. return $formatted;
  9. }
  10. // Initialize variables
  11. $urlStr = "";
  12. $act = $_GET['act'] ?? '';
  13. $output = '';
  14. // Process all actions that might need headers
  15. if ($act == "save") {
  16. $isEdit = false;
  17. $id = $_POST['id'] ?? '';
  18. if (!empty($id) && is_numeric($id)) {
  19. $isEdit = true;
  20. }
  21. // Main customer table fields
  22. $cs_code = textEncode($_POST['cs_code'] ?? '');
  23. $cs_company = textEncode($_POST['cs_company'] ?? '');
  24. $cs_belong = intval($_POST['cs_belong'] ?? 0);
  25. $cs_country = intval($_POST['cs_country'] ?? 0);
  26. $cs_from = intval($_POST['cs_from'] ?? 0);
  27. $cs_state = intval($_POST['cs_state'] ?? 0);
  28. $cs_deal = intval($_POST['cs_deal'] ?? 0);
  29. $no_content = htmlEncode($_POST['no_content'] ?? '');
  30. $cs_address = textEncode($_POST['cs_address'] ?? '');
  31. $allowedit = isset($_POST['allowedit']) ? 1 : 0;
  32. // Begin transaction for all database operations
  33. $conn->begin_transaction();
  34. try {
  35. if ($isEdit) {
  36. // Get existing chain info
  37. $sql = "SELECT cs_chain FROM customer WHERE id=$id";
  38. $result = $conn->query($sql);
  39. if ($row = $result->fetch_assoc()) {
  40. $cs_chain = $row['cs_chain'];
  41. $chain_array = explode(',', $cs_chain);
  42. $last_item = end($chain_array);
  43. if ($last_item != $cs_belong) {
  44. $cs_chain .= ",$cs_belong";
  45. }
  46. // Update customer table
  47. $sql = "UPDATE customer SET
  48. cs_code='$cs_code',
  49. cs_company='$cs_company',
  50. cs_belong=$cs_belong,
  51. cs_country=$cs_country,
  52. cs_from=$cs_from,
  53. cs_state=$cs_state,
  54. cs_deal=$cs_deal,
  55. cs_note='$no_content',
  56. cs_address='$cs_address',
  57. allowedit=$allowedit,
  58. cs_chain='$cs_chain',
  59. cs_updatetime=NOW()
  60. WHERE id=$id";
  61. $conn->query($sql);
  62. // Delete existing contacts to replace with new ones
  63. $sql = "DELETE FROM customer_contact WHERE customer_id=$id";
  64. $conn->query($sql);
  65. } else {
  66. throw new Exception('不存在该客户');
  67. }
  68. } else {
  69. // Insert new customer
  70. $sql = "INSERT INTO customer (
  71. cs_code, cs_company, cs_belong, cs_country, cs_from,
  72. cs_state, cs_deal, cs_note, cs_address,
  73. allowedit, cs_chain, cs_addtime, cs_updatetime
  74. ) VALUES (
  75. '$cs_code', '$cs_company', $cs_belong, $cs_country, $cs_from,
  76. $cs_state, $cs_deal, '$no_content', '$cs_address',
  77. $allowedit, '$cs_belong', NOW(), NOW()
  78. )";
  79. $conn->query($sql);
  80. $id = $conn->insert_id;
  81. }
  82. // Process contacts array
  83. if (isset($_POST['contact']) && is_array($_POST['contact'])) {
  84. foreach ($_POST['contact'] as $contact) {
  85. if (empty($contact['contact_name'])) continue;
  86. $contact_name = textEncode($contact['contact_name']);
  87. // Initialize arrays for contact methods
  88. $methods = ['tel', 'email', 'whatsapp', 'wechat', 'linkedin', 'facebook', 'alibaba'];
  89. $fields = ['customer_id', 'contact_name'];
  90. $values = [$id, "'".$conn->real_escape_string($contact_name)."'"];
  91. // Process each contact method (up to 3 entries each)
  92. foreach ($methods as $method) {
  93. for ($i = 1; $i <= 3; $i++) {
  94. $field_base = $method . '_' . $i;
  95. $value = $contact[$field_base] ?? '';
  96. $escaped_value = $conn->real_escape_string(textEncode($value));
  97. $fields[] = $field_base;
  98. $values[] = "'$escaped_value'";
  99. // Add format field for tel and whatsapp
  100. if ($method == 'tel' || $method == 'whatsapp') {
  101. $format_value = numFormat($value);
  102. $fields[] = $field_base . '_format';
  103. $values[] = "'".$conn->real_escape_string($format_value)."'";
  104. }
  105. // Add backup field
  106. $bu_value = $contact[$field_base . '_bu'] ?? $value;
  107. $escaped_bu_value = $conn->real_escape_string(textEncode($bu_value));
  108. $fields[] = $field_base . '_bu';
  109. $values[] = "'$escaped_bu_value'";
  110. }
  111. }
  112. // Create and execute insert statement for contact
  113. $sql = "INSERT INTO customer_contact (" . implode(', ', $fields) . ", created_at, updated_at)
  114. VALUES (" . implode(', ', $values) . ", NOW(), NOW())";
  115. $conn->query($sql);
  116. }
  117. }
  118. // Commit transaction
  119. $conn->commit();
  120. // Redirect after successful save
  121. $page = $_GET['Page'] ?? '';
  122. $keys = urlencode($_GET['Keys'] ?? '');
  123. header("Location: ?keys=$keys&Page=$page$urlStr");
  124. exit;
  125. } catch (Exception $e) {
  126. // Rollback on failure
  127. $conn->rollback();
  128. $output = "<script>alert('保存失败: " . $e->getMessage() . "');history.back();</script>";
  129. }
  130. }
  131. // If we have output from processing, we'll show it instead of the normal page
  132. if (!empty($output)) {
  133. echo $output;
  134. exit;
  135. }
  136. // 批量操作
  137. if ($act == "postchk") {
  138. $keys = urlencode($_GET['Keys'] ?? '');
  139. $page = $_GET['Page'] ?? '';
  140. $chkact = $_POST['chkact'] ?? '';
  141. if (isset($_POST['chkbox']) && is_array($_POST['chkbox'])) {
  142. $ids = array_map('intval', $_POST['chkbox']);
  143. $idList = implode(',', $ids);
  144. if (!empty($idList)) {
  145. switch($chkact) {
  146. case "0":
  147. case "1":
  148. $sql = "UPDATE customer SET cs_state=$chkact WHERE id IN ($idList)";
  149. break;
  150. default:
  151. // In delete case, let's use transactions to ensure both tables are updated
  152. $conn->begin_transaction();
  153. try {
  154. // Delete from customer_contact first (due to foreign key constraint)
  155. $sql = "DELETE FROM customer_contact WHERE customer_id IN ($idList)";
  156. $conn->query($sql);
  157. // Then delete from customer table
  158. $sql = "DELETE FROM customer WHERE id IN ($idList)";
  159. $conn->query($sql);
  160. $conn->commit();
  161. } catch (Exception $e) {
  162. $conn->rollback();
  163. echo "<script>alert('删除失败: " . $e->getMessage() . "');</script>";
  164. }
  165. }
  166. if ($chkact == "0" || $chkact == "1") {
  167. $conn->query($sql);
  168. }
  169. }
  170. }
  171. header("Location: ?Keys=$keys&Page=$page");
  172. exit;
  173. }
  174. ?>
  175. <!DOCTYPE html>
  176. <html xmlns="http://www.w3.org/1999/xhtml">
  177. <head>
  178. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  179. <title>管理区域</title>
  180. <link rel="stylesheet" href="css/common.css" type="text/css" />
  181. <script language="javascript" src="js/jquery-1.7.2.min.js"></script>
  182. <script type="text/javascript" src="js/js.js"></script>
  183. <script type="text/javascript" src="xheditor-1.1.9/xheditor-1.1.9-zh-cn.min.js"></script>
  184. <script>
  185. $(document).ready(function(){
  186. $('.txt2').xheditor({
  187. tools:'full',
  188. hoverExecDelay:-1,
  189. urlBase:'system/',
  190. upLinkUrl:"upload.php",
  191. upLinkExt:"zip,rar,txt,pdf",
  192. upImgUrl:"upload.php",
  193. upImgExt:"jpg,jpeg,gif,png",
  194. upFlashUrl:"upload.php",
  195. upFlashExt:"swf",
  196. upMediaUrl:"upload.php",
  197. upMediaExt:"wmv,avi,wma,mp3,mid"
  198. });
  199. // Remove contact
  200. $(document).on('click', '.remove-contact-btn', function() {
  201. var contactForm = $(this).closest('.contact-form');
  202. contactForm.remove();
  203. // Renumber remaining contacts
  204. $('#contacts-container .contact-form').each(function(index) {
  205. $(this).find('h3').text('联系人 #' + (index + 1));
  206. });
  207. });
  208. // Add contact form
  209. $('.add-contact-btn').click(function() {
  210. var contactsContainer = $('#contacts-container');
  211. var contactIndex = contactsContainer.children('.contact-form').length;
  212. var contactForm = `
  213. <div class="contact-form" id="contact-form-${contactIndex}">
  214. <div class="contact-header">
  215. <button type="button" class="remove-contact-btn" data-index="${contactIndex}">删除</button>
  216. <h3>联系人 #${contactIndex + 1}</h3>
  217. </div>
  218. <input type="hidden" name="contact[${contactIndex}][id]" value="">
  219. <table width="100%" border="0" cellpadding="3" cellspacing="1" class="contact-table">
  220. <tr>
  221. <th width="8%">联系人</th>
  222. <td><input type="text" name="contact[${contactIndex}][contact_name]" class="txt1" placeholder="联系人姓名"/></td>
  223. </tr>
  224. </table>
  225. <div class="contact-methods-container" id="contact-methods-${contactIndex}">
  226. <!-- Contact methods will be added here -->
  227. </div>
  228. <button type="button" class="add-method-btn" data-contact-index="${contactIndex}">添加联系方式</button>
  229. </div>
  230. `;
  231. contactsContainer.append(contactForm);
  232. });
  233. // Add contact method
  234. $(document).on('click', '.add-method-btn', function() {
  235. var contactIndex = $(this).data('contact-index');
  236. var methodsContainer = $('#contact-methods-' + contactIndex);
  237. // Count existing methods by type
  238. var methodCounts = {};
  239. methodsContainer.find('select.method-select').each(function() {
  240. var type = $(this).val();
  241. if (type) {
  242. methodCounts[type] = (methodCounts[type] || 0) + 1;
  243. }
  244. });
  245. var methodRow = `
  246. <div class="contact-method-row">
  247. <select class="method-select" onchange="updateMethodSelectAndPlaceholder(this)">
  248. <option value="">请选择联系方式</option>
  249. <option value="tel" ${(methodCounts.tel || 0) >= 3 ? 'disabled' : ''}>电话</option>
  250. <option value="wechat" ${(methodCounts.wechat || 0) >= 3 ? 'disabled' : ''}>微信</option>
  251. <option value="whatsapp" ${(methodCounts.whatsapp || 0) >= 3 ? 'disabled' : ''}>WhatsApp</option>
  252. <option value="email" ${(methodCounts.email || 0) >= 3 ? 'disabled' : ''}>邮箱</option>
  253. <option value="linkedin" ${(methodCounts.linkedin || 0) >= 3 ? 'disabled' : ''}>领英</option>
  254. <option value="facebook" ${(methodCounts.facebook || 0) >= 3 ? 'disabled' : ''}>Facebook</option>
  255. <option value="alibaba" ${(methodCounts.alibaba || 0) >= 3 ? 'disabled' : ''}>阿里巴巴</option>
  256. </select>
  257. <input type="text" class="txt1 method-input" style="width:60%;" placeholder="请选择联系方式类型">
  258. <button type="button" class="remove-method-btn">删除</button>
  259. </div>
  260. `;
  261. methodsContainer.append(methodRow);
  262. updateMethodFields(methodsContainer.find('.contact-method-row:last-child'));
  263. });
  264. // Remove contact method
  265. $(document).on('click', '.remove-method-btn', function() {
  266. var methodRow = $(this).closest('.contact-method-row');
  267. var contactIndex = methodRow.closest('.contact-form').attr('id').split('-')[2];
  268. var type = methodRow.find('select.method-select').val();
  269. methodRow.remove();
  270. // Update available options in other selects
  271. updateAvailableMethodTypes(contactIndex);
  272. });
  273. });
  274. // Update method fields based on selection
  275. function updateMethodFields(methodRow) {
  276. var select = methodRow.find('select.method-select');
  277. var input = methodRow.find('input.method-input');
  278. var contactForm = methodRow.closest('.contact-form');
  279. var contactIndex = contactForm.attr('id').split('-')[2];
  280. var type = select.val();
  281. if (!type) return;
  282. // Count existing methods of this type
  283. var count = 1;
  284. contactForm.find('select.method-select').each(function() {
  285. if ($(this).val() === type && $(this)[0] !== select[0]) {
  286. count++;
  287. }
  288. });
  289. // Update field names
  290. select.attr('name', `contact[${contactIndex}][${type}_${count}]`);
  291. input.attr('name', `contact[${contactIndex}][${type}_${count}]`);
  292. // Add format field for tel and whatsapp
  293. if (type === 'tel' || type === 'whatsapp') {
  294. if (!methodRow.find('.format-input').length) {
  295. input.after(`<input type="hidden" class="format-input" name="contact[${contactIndex}][${type}_${count}_format]">`);
  296. }
  297. }
  298. // Add backup field
  299. if (!methodRow.find('.backup-input').length) {
  300. methodRow.append(`<input type="hidden" class="backup-input" name="contact[${contactIndex}][${type}_${count}_bu]">`);
  301. }
  302. }
  303. // Update available method types for a contact
  304. function updateAvailableMethodTypes(contactIndex) {
  305. var methodsContainer = $('#contact-methods-' + contactIndex);
  306. // Count methods by type
  307. var methodCounts = {};
  308. methodsContainer.find('select.method-select').each(function() {
  309. var type = $(this).val();
  310. if (type) {
  311. methodCounts[type] = (methodCounts[type] || 0) + 1;
  312. }
  313. });
  314. // Update all selects in this contact
  315. methodsContainer.find('select.method-select').each(function() {
  316. var currentValue = $(this).val();
  317. $(this).find('option').each(function() {
  318. var optionValue = $(this).val();
  319. if (optionValue && optionValue !== currentValue) {
  320. $(this).prop('disabled', (methodCounts[optionValue] || 0) >= 3);
  321. }
  322. });
  323. });
  324. }
  325. // Update placeholder and handle method fields
  326. function updateMethodSelectAndPlaceholder(selectElement) {
  327. var methodRow = $(selectElement).closest('.contact-method-row');
  328. updateMethodPlaceholder(selectElement);
  329. updateMethodFields(methodRow);
  330. var contactIndex = methodRow.closest('.contact-form').attr('id').split('-')[2];
  331. updateAvailableMethodTypes(contactIndex);
  332. }
  333. function updateMethodPlaceholder(selectElement) {
  334. var placeholder = "";
  335. var value = $(selectElement).val();
  336. switch(value) {
  337. case "tel":
  338. placeholder = "电话格式:区号+号码 如:+86 15012345678";
  339. break;
  340. case "wechat":
  341. placeholder = "微信";
  342. break;
  343. case "whatsapp":
  344. placeholder = "Whatsapp 格式:区号+号码 如:+86 15012345678";
  345. break;
  346. case "email":
  347. placeholder = "邮件";
  348. break;
  349. case "linkedin":
  350. placeholder = "领英链接";
  351. break;
  352. case "facebook":
  353. placeholder = "Facebook";
  354. break;
  355. case "alibaba":
  356. placeholder = "阿里巴巴";
  357. break;
  358. default:
  359. placeholder = "请选择联系方式类型";
  360. }
  361. $(selectElement).next('.method-input').attr('placeholder', placeholder);
  362. }
  363. </script>
  364. <style>
  365. .contact-form {
  366. margin-bottom: 10px;
  367. padding: 8px;
  368. background-color: #FFFFFF;
  369. }
  370. .contact-header {
  371. display: flex;
  372. align-items: center;
  373. margin-bottom: 8px;
  374. gap: 10px;
  375. }
  376. .contact-header h3 {
  377. margin: 0;
  378. order: 2;
  379. flex-grow: 1;
  380. }
  381. .remove-contact-btn {
  382. background-color: #f44336;
  383. color: white;
  384. border: none;
  385. padding: 4px 8px;
  386. cursor: pointer;
  387. order: 1;
  388. }
  389. .add-contact-btn {
  390. background-color: #4CAF50;
  391. color: white;
  392. border: none;
  393. padding: 6px 12px;
  394. margin-bottom: 10px;
  395. cursor: pointer;
  396. }
  397. .contact-methods-container {
  398. margin-top: 8px;
  399. }
  400. .contact-method-row {
  401. margin-bottom: 6px;
  402. padding: 6px;
  403. border: 1px solid #eee;
  404. display: flex;
  405. align-items: center;
  406. gap: 8px;
  407. }
  408. .add-method-btn {
  409. background-color: #2196F3;
  410. color: white;
  411. border: none;
  412. padding: 4px 8px;
  413. margin-top: 4px;
  414. cursor: pointer;
  415. }
  416. .remove-method-btn {
  417. background-color: #f44336;
  418. color: white;
  419. border: none;
  420. padding: 2px 4px;
  421. cursor: pointer;
  422. }
  423. .method-select {
  424. margin-right: 8px;
  425. padding: 3px;
  426. }
  427. .contact-table {
  428. margin-bottom: 6px;
  429. }
  430. .contact-table td, .contact-table th {
  431. padding: 4px 6px;
  432. }
  433. </style>
  434. </head>
  435. <body>
  436. <div id="man_zone">
  437. <?php
  438. // 编辑操作
  439. if ($act == "edit" || $act == "add") {
  440. $id = $_GET['id'] ?? '';
  441. $isEdit = false;
  442. // Initialize variables
  443. $cs_code = $cs_company = $cs_address = $cs_addtime = $cs_updatetime = $cs_note = '';
  444. $cs_belong = $cs_country = $cs_from = $cs_state = $cs_deal = $allowedit = $cs_type = $cs_belongclient = 0;
  445. $contacts = [];
  446. if (!empty($id) && is_numeric($id)) {
  447. $isEdit = true;
  448. // Join customer and customer_contact tables
  449. $sql = "SELECT c.*, cc.* FROM customer c
  450. LEFT JOIN customer_contact cc ON c.id = cc.customer_id
  451. WHERE c.id = $id";
  452. $result = $conn->query($sql);
  453. if ($row = $result->fetch_assoc()) {
  454. // Basic customer info
  455. $cs_code = textUncode($row['cs_code']);
  456. $cs_company = textUncode($row['cs_company']);
  457. $cs_country = $row['cs_country'];
  458. $cs_from = $row['cs_from'];
  459. $cs_address = textUncode($row['cs_address']);
  460. $cs_addtime = $row['cs_addtime'];
  461. $cs_updatetime = $row['cs_updatetime'];
  462. $cs_belong = $row['cs_belong'];
  463. $cs_state = $row['cs_state'];
  464. $cs_deal = $row['cs_deal'];
  465. $cs_note = htmlUncode($row['cs_note']);
  466. $allowedit = $row['allowedit'];
  467. $cs_type = $row['cs_type'];
  468. $cs_belongclient = $row['cs_belongclient'];
  469. // Get all contacts for this customer
  470. $contactSql = "SELECT * FROM customer_contact WHERE customer_id = $id";
  471. $contactResult = $conn->query($contactSql);
  472. while ($contactRow = $contactResult->fetch_assoc()) {
  473. $contact = [
  474. 'id' => $contactRow['id'],
  475. 'contact_name' => textUncode($contactRow['contact_name']),
  476. 'created_at' => $contactRow['created_at'],
  477. 'updated_at' => $contactRow['updated_at']
  478. ];
  479. // Process each contact method type (up to 3 entries each)
  480. $methodTypes = ['tel', 'email', 'whatsapp', 'wechat', 'linkedin', 'facebook', 'alibaba'];
  481. foreach ($methodTypes as $type) {
  482. for ($i = 1; $i <= 3; $i++) {
  483. $fieldBase = $type . '_' . $i;
  484. $contact[$fieldBase] = textUncode($contactRow[$fieldBase]);
  485. if ($type == 'tel' || $type == 'whatsapp') {
  486. $contact[$fieldBase . '_format'] = textUncode($contactRow[$fieldBase . '_format']);
  487. }
  488. $contact[$fieldBase . '_bu'] = textUncode($contactRow[$fieldBase . '_bu']);
  489. }
  490. }
  491. $contacts[] = $contact;
  492. }
  493. }
  494. }
  495. $page = $_GET['Page'] ?? '';
  496. $keys = urlencode($_GET['Keys'] ?? '');
  497. $ord = urlencode($_GET['Ord'] ?? '');
  498. $hrefstr = "?keys=$keys&Page=$page&Ord=$ord";
  499. ?>
  500. <form name="form1" method="post" action="<?php echo $hrefstr; ?>&act=save">
  501. <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
  502. <tbody>
  503. <tr>
  504. <th width="8%">客户编号</th>
  505. <td><input type="text" id="cs_code" name="cs_code" value="<?php echo $cs_code; ?>" class="txt1" />
  506. <input type="hidden" name="id" value="<?php echo $id; ?>" /></td>
  507. </tr>
  508. <tr>
  509. <th width="8%">公司名称</th>
  510. <td><input type="text" id="cs_company" name="cs_company" value="<?php echo $cs_company; ?>" class="txt1" /></td>
  511. </tr>
  512. <tr>
  513. <th width="8%">所属业务</th>
  514. <td>
  515. <select name="cs_belong">
  516. <option value="0">请选择</option>
  517. <?php
  518. $sql = "SELECT id,em_user FROM employee";
  519. $result = $conn->query($sql);
  520. while($row = $result->fetch_assoc()) {
  521. $selected = ($row['id'] == $cs_belong) ? ' selected="selected"' : '';
  522. echo "<option value=\"{$row['id']}\"$selected>{$row['em_user']}</option>";
  523. }
  524. ?>
  525. </select>
  526. </td>
  527. </tr>
  528. <tr>
  529. <th width="8%">国家</th>
  530. <td>
  531. <select name="cs_country">
  532. <option value="0">请选择</option>
  533. <?php
  534. $sql = "SELECT id,countryCode,countryName FROM country";
  535. $result = $conn->query($sql);
  536. while($row = $result->fetch_assoc()) {
  537. $selected = ($row['id'] == $cs_country) ? ' selected="selected"' : '';
  538. echo "<option value=\"{$row['id']}\"$selected>{$row['countryName']}</option>";
  539. }
  540. ?>
  541. </select>
  542. </td>
  543. </tr>
  544. <tr>
  545. <th width="8%">来源</th>
  546. <td>
  547. <select name="cs_from">
  548. <option value="0">请选择</option>
  549. <?php
  550. $sql = "SELECT id,ch_name FROM qudao";
  551. $result = $conn->query($sql);
  552. while($row = $result->fetch_assoc()) {
  553. $selected = ($row['id'] == $cs_from) ? ' selected="selected"' : '';
  554. echo "<option value=\"{$row['id']}\"$selected>{$row['ch_name']}</option>";
  555. }
  556. ?>
  557. </select>
  558. </td>
  559. </tr>
  560. <tr>
  561. <th width="8%">录入时间</th>
  562. <td><?php echo $cs_addtime; ?></td>
  563. </tr>
  564. <tr>
  565. <th width="8%">更新时间</th>
  566. <td><?php echo $cs_updatetime; ?></td>
  567. </tr>
  568. <tr>
  569. <th width="8%" valign="top">联系人信息</th>
  570. <td>
  571. <button type="button" class="add-contact-btn">添加联系人</button>
  572. <div id="contacts-container">
  573. <?php if (!empty($contacts)): ?>
  574. <?php foreach ($contacts as $index => $contact): ?>
  575. <div class="contact-form" id="contact-form-<?php echo $index; ?>">
  576. <div class="contact-header">
  577. <button type="button" class="remove-contact-btn" data-index="<?php echo $index; ?>">删除</button>
  578. <h3>联系人 #<?php echo $index + 1; ?></h3>
  579. </div>
  580. <input type="hidden" name="contact[<?php echo $index; ?>][id]" value="<?php echo $contact['id']; ?>">
  581. <table width="100%" border="0" cellpadding="3" cellspacing="1" class="contact-table">
  582. <tr>
  583. <th width="8%">联系人</th>
  584. <td><input type="text" name="contact[<?php echo $index; ?>][contact_name]" value="<?php echo htmlspecialcharsFix($contact['contact_name']); ?>" class="txt1" placeholder="联系人姓名"/></td>
  585. </tr>
  586. </table>
  587. <div class="contact-methods-container" id="contact-methods-<?php echo $index; ?>">
  588. <?php
  589. $methodTypes = [
  590. 'tel' => '电话',
  591. 'wechat' => '微信',
  592. 'whatsapp' => 'WhatsApp',
  593. 'email' => '邮箱',
  594. 'linkedin' => '领英',
  595. 'facebook' => 'Facebook',
  596. 'alibaba' => '阿里巴巴'
  597. ];
  598. foreach ($methodTypes as $type => $label) {
  599. for ($i = 1; $i <= 3; $i++) {
  600. $fieldName = $type . '_' . $i;
  601. if (!empty($contact[$fieldName])) {
  602. echo '<div class="contact-method-row">';
  603. echo '<select class="method-select" name="contact[' . $index . '][' . $fieldName . ']" onchange="updateMethodSelectAndPlaceholder(this)">';
  604. echo '<option value="">请选择联系方式</option>';
  605. foreach ($methodTypes as $optionType => $optionLabel) {
  606. $selected = ($optionType === $type) ? 'selected' : '';
  607. echo '<option value="' . $optionType . '" ' . $selected . '>' . $optionLabel . '</option>';
  608. }
  609. echo '</select>';
  610. echo '<input type="text" class="txt1 method-input" style="width:60%;" name="contact[' . $index . '][' . $fieldName . ']" value="' . htmlspecialcharsFix($contact[$fieldName]) . '">';
  611. if ($type === 'tel' || $type === 'whatsapp') {
  612. echo '<input type="hidden" class="format-input" name="contact[' . $index . '][' . $fieldName . '_format]" value="' . htmlspecialcharsFix($contact[$fieldName . '_format']) . '">';
  613. }
  614. echo '<input type="hidden" class="backup-input" name="contact[' . $index . '][' . $fieldName . '_bu]" value="' . htmlspecialcharsFix($contact[$fieldName . '_bu']) . '">';
  615. echo '</div>';
  616. }
  617. }
  618. }
  619. ?>
  620. </div>
  621. <button type="button" class="add-method-btn" data-contact-index="<?php echo $index; ?>">添加联系方式</button>
  622. </div>
  623. <?php endforeach; ?>
  624. <?php else: ?>
  625. <div class="contact-form" id="contact-form-0">
  626. <div class="contact-header">
  627. <button type="button" class="remove-contact-btn" data-index="0">删除</button>
  628. <h3>联系人 #1</h3>
  629. </div>
  630. <input type="hidden" name="contact[0][id]" value="">
  631. <table width="100%" border="0" cellpadding="3" cellspacing="1" class="contact-table">
  632. <tr>
  633. <th width="8%">联系人</th>
  634. <td><input type="text" name="contact[0][contact_name]" class="txt1" placeholder="联系人姓名"/></td>
  635. </tr>
  636. </table>
  637. <div class="contact-methods-container" id="contact-methods-0">
  638. <!-- Contact methods will be added here -->
  639. </div>
  640. <button type="button" class="add-method-btn" data-contact-index="0">添加联系方式</button>
  641. </div>
  642. <?php endif; ?>
  643. </div>
  644. </td>
  645. </tr>
  646. <tr>
  647. <th width="8%">地址</th>
  648. <td><input type="text" id="cs_address" name="cs_address" value="<?php echo $cs_address; ?>" class="txt1" /></td>
  649. </tr>
  650. <tr>
  651. <th width="8%">标签</th>
  652. <td>
  653. <?php
  654. if($isEdit) {
  655. $sql = "SELECT id,tagName FROM tagtable WHERE customerId = " . (int)$id;
  656. $result = $conn->query($sql);
  657. while($row = $result->fetch_assoc()) {
  658. echo htmlspecialcharsFix($row['tagName']) . ',';
  659. }
  660. }
  661. ?>
  662. </td>
  663. </tr>
  664. <tr>
  665. <th width="8%">状态</th>
  666. <td>
  667. <label><input type="radio" name="cs_state" value="1" <?php if($cs_state==1) echo 'checked="checked"'; ?> />有效</label>
  668. <label><input type="radio" name="cs_state" value="0" <?php if($cs_state!=1) echo 'checked="checked"'; ?> />不再跟进</label>
  669. </td>
  670. </tr>
  671. <tr>
  672. <th width="8%">是否误报</th>
  673. <td>
  674. <label><input type="radio" name="allowedit" value="1" <?php if($allowedit==1) echo 'checked="checked"'; ?> />审核通过</label>
  675. <label><input type="radio" name="allowedit" value="0" <?php if($allowedit!=1) echo 'checked="checked"'; ?> />一般处理</label>
  676. </td>
  677. </tr>
  678. <tr>
  679. <th width="8%">是否成交</th>
  680. <td>
  681. <label><input type="radio" name="cs_deal" value="3" <?php if($cs_deal==3) echo 'checked="checked"'; ?> />成交</label>
  682. <label><input type="radio" name="cs_deal" value="2" <?php if($cs_deal==2) echo 'checked="checked"'; ?> />明确需求</label>
  683. <label><input type="radio" name="cs_deal" value="1" <?php if($cs_deal==1) echo 'checked="checked"'; ?> />背景调查</label>
  684. <label><input type="radio" name="cs_deal" value="0" <?php if($cs_deal==0) echo 'checked="checked"'; ?> />无响应</label>
  685. </td>
  686. </tr>
  687. <tr>
  688. <th>内容</th>
  689. <td><textarea id="no_content" name="no_content" class="txt2"><?php echo $cs_note; ?></textarea></td>
  690. </tr>
  691. <tr>
  692. <th></th>
  693. <td>
  694. <input type="submit" name="save" id="save" value="确定" class="btn1" />
  695. <input type="reset" name="save" id="save" value="重置" class="btn1" />
  696. <input type="button" value="返回" class="btn1" onClick="location.href='<?php echo $hrefstr; ?>'" />
  697. </td>
  698. </tr>
  699. </tbody>
  700. </table>
  701. </form>
  702. <?php
  703. exit;
  704. }
  705. // 主列表页面
  706. $fliterQudao = $_GET['fliterQudao'] ?? '';
  707. $fliterDeal = $_GET['fliterDeal'] ?? '';
  708. $fliterTeam = $_GET['fliterTeam'] ?? '';
  709. $fliterContact = $_GET['fliterContact'] ?? '';
  710. $fliterEmployee = $_GET['fliterEmployee'] ?? '';
  711. $filterStr = "";
  712. $urlStr = "";
  713. if (!empty($fliterQudao)) {
  714. $filterStr .= " AND c.cs_from=" . intval($fliterQudao);
  715. $urlStr .= "&fliterQudao=$fliterQudao";
  716. }
  717. if (!empty($fliterDeal)) {
  718. $filterStr .= " AND c.cs_deal=" . intval($fliterDeal);
  719. $urlStr .= "&fliterDeal=$fliterDeal";
  720. }
  721. if (!empty($fliterTeam)) {
  722. $teamId = intval($fliterTeam);
  723. $filterStr .= " AND (c.cs_belong=$teamId OR c.cs_belong IN (SELECT id FROM employee WHERE em_role=$teamId))";
  724. $urlStr .= "&fliterTeam=$fliterTeam";
  725. }
  726. if (!empty($fliterEmployee)) {
  727. $filterStr .= " AND c.cs_belong=" . intval($fliterEmployee);
  728. $urlStr .= "&fliterEmployee=$fliterEmployee";
  729. }
  730. if (!empty($fliterContact)) {
  731. switch($fliterContact) {
  732. case "1": $filterStr .= " AND (cc.tel_1 != '' OR cc.tel_2 != '' OR cc.tel_3 != '')"; break;
  733. case "2": $filterStr .= " AND (cc.wechat_1 != '' OR cc.wechat_2 != '' OR cc.wechat_3 != '')"; break;
  734. case "3": $filterStr .= " AND (cc.whatsapp_1 != '' OR cc.whatsapp_2 != '' OR cc.whatsapp_3 != '')"; break;
  735. case "4": $filterStr .= " AND (cc.email_1 != '' OR cc.email_2 != '' OR cc.email_3 != '')"; break;
  736. case "5": $filterStr .= " AND (cc.linkedin_1 != '' OR cc.linkedin_2 != '' OR cc.linkedin_3 != '')"; break;
  737. case "6": $filterStr .= " AND (cc.facebook_1 != '' OR cc.facebook_2 != '' OR cc.facebook_3 != '')"; break;
  738. default: $filterStr .= " AND (cc.alibaba_1 != '' OR cc.alibaba_2 != '' OR cc.alibaba_3 != '')";
  739. }
  740. $urlStr .= "&fliterContact=$fliterContact";
  741. }
  742. $keys = $_GET['Keys'] ?? '';
  743. $keyscode = textEncode($keys);
  744. $page = $_GET['Page'] ?? '';
  745. $ord = $_GET['Ord'] ?? '';
  746. $sql = "SELECT c.id, c.cs_code, c.cs_company, c.cs_country, c.cs_address,
  747. c.cs_from, c.cs_deal, c.cs_addtime, c.cs_updatetime, c.cs_belong, c.cs_note,
  748. c.cs_claimFrom, c.cs_chain, c.cs_dealdate,
  749. cc.contact_name as cs_name,
  750. cc.tel_1 as cs_tel, cc.email_1 as cs_email,
  751. cc.whatsapp_1 as cs_whatsapp, cc.wechat_1 as cs_wechat,
  752. cc.linkedin_1 as cs_linkedin, cc.facebook_1 as cs_facebook,
  753. cc.alibaba_1 as cs_alibaba
  754. FROM customer c
  755. LEFT JOIN customer_contact cc ON c.id = cc.customer_id
  756. WHERE (c.cs_code LIKE '%".$conn->real_escape_string($keyscode)."%'
  757. OR cc.contact_name LIKE '%".$conn->real_escape_string($keyscode)."%'
  758. OR cc.tel_1 LIKE '%".$conn->real_escape_string($keyscode)."%'
  759. OR cc.tel_2 LIKE '%".$conn->real_escape_string($keyscode)."%'
  760. OR cc.tel_3 LIKE '%".$conn->real_escape_string($keyscode)."%'
  761. OR cc.wechat_1 LIKE '%".$conn->real_escape_string($keyscode)."%'
  762. OR cc.wechat_2 LIKE '%".$conn->real_escape_string($keyscode)."%'
  763. OR cc.wechat_3 LIKE '%".$conn->real_escape_string($keyscode)."%'
  764. OR cc.alibaba_1 LIKE '%".$conn->real_escape_string($keyscode)."%'
  765. OR cc.alibaba_2 LIKE '%".$conn->real_escape_string($keyscode)."%'
  766. OR cc.alibaba_3 LIKE '%".$conn->real_escape_string($keyscode)."%'
  767. OR cc.whatsapp_1_format LIKE '%".$conn->real_escape_string($keyscode)."%'
  768. OR cc.whatsapp_2_format LIKE '%".$conn->real_escape_string($keyscode)."%'
  769. OR cc.whatsapp_3_format LIKE '%".$conn->real_escape_string($keyscode)."%'
  770. OR cc.email_1 LIKE '%".$conn->real_escape_string($keyscode)."%'
  771. OR cc.email_2 LIKE '%".$conn->real_escape_string($keyscode)."%'
  772. OR cc.email_3 LIKE '%".$conn->real_escape_string($keyscode)."%')
  773. AND c.cs_state=1
  774. $filterStr
  775. ORDER BY c.cs_updatetime DESC";
  776. // Execute query to count total records
  777. $countResult = $conn->query($sql);
  778. if (!$countResult) {
  779. die("查询失败: " . $conn->error . "<br>SQL: " . $sql);
  780. }
  781. $totalRecords = $countResult->num_rows;
  782. $countResult->close(); // 关闭第一个结果集
  783. // Create pagination variables
  784. $pageSize = 18;
  785. $totalPages = ceil($totalRecords / $pageSize);
  786. if ($totalPages < 1) $totalPages = 1; // 确保至少有一页,即使没有结果
  787. if (empty($page)) $page = 1;
  788. if ($page == 'end') $page = $totalPages;
  789. if (!is_numeric($page) || $page < 1) $page = 1;
  790. $page = (int)$page;
  791. if ($page > $totalPages) $page = $totalPages;
  792. // Apply pagination
  793. $offset = ($page - 1) * $pageSize;
  794. if ($offset < 0) $offset = 0; // 确保偏移量不为负数
  795. $sql_paginated = $sql . " LIMIT $offset, $pageSize"; // 使用新变量,不修改原始SQL
  796. // Execute the paginated query
  797. $result = $conn->query($sql_paginated);
  798. if (!$result) {
  799. die("分页查询失败: " . $conn->error . "<br>SQL: " . $sql_paginated);
  800. }
  801. $tempNum = $pageSize * ($page - 1);
  802. ?>
  803. <form id="form1" method="post" action="?act=postchk&Keys=<?php echo $keys; ?>&Page=<?php echo $page; ?>" onSubmit="return false">
  804. <div class="fastSelect clear">
  805. <H1>搜索条件</H1>
  806. <div class="selectItem">
  807. <label>来源渠道</label>
  808. <select name="fliterQudao" class="filterSearch">
  809. <option value="">请选择渠道</option>
  810. <?php
  811. $sql_temp = "SELECT id,ch_name FROM qudao";
  812. $qudaoResult = $conn->query($sql_temp);
  813. while($row = $qudaoResult->fetch_assoc()) {
  814. $selected = ($fliterQudao == $row['id']) ? ' selected="selected"' : '';
  815. echo "<option value=\"{$row['id']}\"$selected>{$row['ch_name']}</option>";
  816. }
  817. ?>
  818. </select>
  819. </div>
  820. <div class="selectItem">
  821. <label>是否成交</label>
  822. <select name="fliterDeal" class="filterSearch">
  823. <option value="">请选择</option>
  824. <option value="3" <?php if($fliterDeal=="3") echo 'selected="selected"'; ?>>已成交</option>
  825. <option value="2" <?php if($fliterDeal=="2") echo 'selected="selected"'; ?>>明确需求</option>
  826. <option value="1" <?php if($fliterDeal=="1") echo 'selected="selected"'; ?>>背景调查</option>
  827. <option value="0" <?php if($fliterDeal=="0") echo 'selected="selected"'; ?>>无响应</option>
  828. </select>
  829. </div>
  830. <div class="selectItem">
  831. <label>按组</label>
  832. <select name="fliterTeam" class="filterSearch">
  833. <option value="">请选择</option>
  834. <?php
  835. $sql_temp = "SELECT id,em_user FROM employee WHERE em_role=0";
  836. $teamResult = $conn->query($sql_temp);
  837. while($row = $teamResult->fetch_assoc()) {
  838. $selected = ($fliterTeam == $row['id']) ? ' selected="selected"' : '';
  839. echo "<option value=\"{$row['id']}\"$selected>{$row['em_user']}组</option>";
  840. }
  841. ?>
  842. </select>
  843. </div>
  844. <div class="selectItem">
  845. <label>业务</label>
  846. <select name="fliterEmployee" class="filterSearch">
  847. <option value="">请选择</option>
  848. <?php
  849. $sql_temp = "SELECT id,em_user FROM employee";
  850. $empResult = $conn->query($sql_temp);
  851. while($row = $empResult->fetch_assoc()) {
  852. $selected = ($fliterEmployee == $row['id']) ? ' selected="selected"' : '';
  853. echo "<option value=\"{$row['id']}\"$selected>{$row['em_user']}</option>";
  854. }
  855. ?>
  856. </select>
  857. </div>
  858. <div class="selectItem">
  859. <label>联系方式</label>
  860. <select name="fliterContact" class="filterSearch">
  861. <option value="">请选择</option>
  862. <option value="1" <?php if($fliterContact=="1") echo 'selected="selected"'; ?>>电话</option>
  863. <option value="2" <?php if($fliterContact=="2") echo 'selected="selected"'; ?>>微信</option>
  864. <option value="3" <?php if($fliterContact=="3") echo 'selected="selected"'; ?>>WhatsApp</option>
  865. <option value="4" <?php if($fliterContact=="4") echo 'selected="selected"'; ?>>邮箱</option>
  866. <option value="5" <?php if($fliterContact=="5") echo 'selected="selected"'; ?>>领英</option>
  867. <option value="6" <?php if($fliterContact=="6") echo 'selected="selected"'; ?>>Facebook</option>
  868. <option value="7" <?php if($fliterContact=="7") echo 'selected="selected"'; ?>>阿里巴巴</option>
  869. </select>
  870. </div>
  871. <div class="inputSearch">
  872. <input type="text" id="keys" class="inputTxt" placeholder="请输入搜索关键词" value="<?php echo empty($keyscode) ? '' : $keyscode; ?>"
  873. />
  874. <input type="button" id="searchgo" class="searchgo" value="go"
  875. onClick="location.href='?Keys='+encodeURIComponent(document.getElementById('keys').value)+'<?php echo $urlStr; ?>'" />
  876. </div>
  877. </div>
  878. <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
  879. <thead>
  880. <tr>
  881. <th width="4%"><input type="checkbox" name="chkall" id="chkall" onClick="chkboxall(this,'chkbox')" /></th>
  882. <th width="6%">序号</th>
  883. <th width="20%">客户编码</th>
  884. <th width="10%">联系人</th>
  885. <th width="10%">国家地区</th>
  886. <th width="7.5%">来源</th>
  887. <th width="7.5%">是否成交</th>
  888. <th width="10%">业务员</th>
  889. <th width="10%">操作</th>
  890. </tr>
  891. </thead>
  892. <tbody>
  893. <?php
  894. if ($result->num_rows > 0) {
  895. while ($row = $result->fetch_assoc()) {
  896. $tempNum++;
  897. ?>
  898. <tr onMouseOver="this.style.background='#F7FCFF'" onMouseOut="this.style.background='#FFFFFF'">
  899. <td align="center"><input type="checkbox" name="chkbox[]" value="<?php echo $row['id'] ?? ''; ?>" /></td>
  900. <td align="center"><?php echo $tempNum; ?></td>
  901. <td align="center" class="code" data-id="<?php echo $row['id'] ?? ''; ?>">
  902. <?php
  903. echo $row['cs_code'] ?? ''; ?>
  904. <?php if(($row['cs_claimFrom'] ?? 0) > 0): ?>
  905. <img src="../images/yijiao.png" class="handover">
  906. <?php endif; ?>
  907. </td>
  908. <td align="center"><?php echo htmlspecialcharsFix($row['cs_name'] ?? ''); ?></td>
  909. <td align="center">
  910. <?php
  911. $countryId = intval($row['cs_country'] ?? 0);
  912. $sql = "SELECT countryName FROM country WHERE id = $countryId";
  913. $countryResult = $conn->query($sql);
  914. if ($countryResult && $countryRow = $countryResult->fetch_assoc()) {
  915. echo htmlspecialcharsFix($countryRow['countryName']);
  916. } else {
  917. echo "未选择";
  918. }
  919. ?>
  920. </td>
  921. <td align="center">
  922. <?php
  923. $fromId = intval($row['cs_from'] ?? 0);
  924. $sql = "SELECT ch_name FROM qudao WHERE id = $fromId";
  925. $fromResult = $conn->query($sql);
  926. if ($fromResult && $fromRow = $fromResult->fetch_assoc()) {
  927. echo htmlspecialcharsFix($fromRow['ch_name']);
  928. } else {
  929. echo "未选择";
  930. }
  931. ?>
  932. </td>
  933. <td align="center">
  934. <?php
  935. if (($row['cs_deal'] ?? 0) == 3) {
  936. echo "<span style='color:red;font-size:10px;'>" . htmlspecialcharsFix($row['cs_dealdate'] ?? '') . "成交</span>";
  937. } elseif (($row['cs_deal'] ?? 0) == 2) {
  938. echo "明确需求";
  939. } elseif (($row['cs_deal'] ?? 0) == 1) {
  940. echo "背景调查";
  941. } else {
  942. echo "无响应";
  943. }
  944. ?>
  945. </td>
  946. <td align="center">
  947. <?php
  948. $belongId = intval($row['cs_belong'] ?? 0);
  949. $sql = "SELECT em_user FROM employee WHERE id = $belongId";
  950. $empResult = $conn->query($sql);
  951. if ($empResult && $empRow = $empResult->fetch_assoc()) {
  952. echo htmlspecialcharsFix($empRow['em_user']);
  953. } else {
  954. echo "未选择";
  955. }
  956. ?>
  957. </td>
  958. <td align="center">
  959. <a href="?Keys=<?php echo urlencode($keys ?? ''); ?>&Page=<?php echo urlencode($page ?? '') . $urlStr; ?>&act=edit&id=<?php echo $row['id'] ?? ''; ?>" class="ico_edit ico">修改</a>
  960. </td>
  961. </tr>
  962. <tr class="detail_panel code<?php echo $row['id'] ?? ''; ?>__panel">
  963. <td colspan="2"></td>
  964. <td colspan="7" class="cs_detail">
  965. <ul>
  966. <li class="cs_detail_addtime">录入时间:<?php echo htmlspecialcharsFix($row['cs_addtime'] ?? ''); ?></li>
  967. <li class="cs_detail_addtime">更新时间:<?php echo htmlspecialcharsFix($row['cs_updatetime'] ?? ''); ?></li>
  968. <li class="cs_detail_addtime">
  969. 流转记录:
  970. <?php
  971. $chain = $row['cs_chain'] ?? '';
  972. if(!empty($chain)) {
  973. $chain_array = explode(',', $chain);
  974. $chain_ids = array_filter(array_map('intval', $chain_array));
  975. if(!empty($chain_ids)) {
  976. $chain_ids_str = implode(',', $chain_ids);
  977. $sql = "SELECT em_user FROM employee WHERE id IN (" . $chain_ids_str . ")";
  978. $chainResult = $conn->query($sql);
  979. $chain_users = [];
  980. while($chainRow = $chainResult->fetch_assoc()) {
  981. $chain_users[] = htmlspecialcharsFix($chainRow['em_user']);
  982. }
  983. echo implode(' > ', $chain_users);
  984. }
  985. }
  986. ?>
  987. </li>
  988. <?php if(!empty($row['cs_tel'] ?? '')): ?>
  989. <li class="tel"><?php echo htmlspecialcharsFix($row['cs_tel']); ?></li>
  990. <?php endif; ?>
  991. <?php if(!empty($row['cs_email'] ?? '')): ?>
  992. <li class="mail"><?php echo htmlspecialcharsFix($row['cs_email']); ?></li>
  993. <?php endif; ?>
  994. <?php if(!empty($row['cs_whatsapp'] ?? '')): ?>
  995. <li class="whatsapp"><?php echo htmlspecialcharsFix($row['cs_whatsapp']); ?></li>
  996. <?php endif; ?>
  997. <?php if(!empty($row['cs_wechat'] ?? '')): ?>
  998. <li class="wechat"><?php echo htmlspecialcharsFix($row['cs_wechat']); ?></li>
  999. <?php endif; ?>
  1000. <?php if(!empty($row['cs_linkedin'] ?? '')): ?>
  1001. <li class="linkedin"><?php echo htmlspecialcharsFix($row['cs_linkedin']); ?></li>
  1002. <?php endif; ?>
  1003. <?php if(!empty($row['cs_facebook'] ?? '')): ?>
  1004. <li class="facebook"><?php echo htmlspecialcharsFix($row['cs_facebook']); ?></li>
  1005. <?php endif; ?>
  1006. <?php if(!empty($row['cs_alibaba'] ?? '')): ?>
  1007. <li class="alibaba"><?php echo htmlspecialcharsFix($row['cs_alibaba']); ?></li>
  1008. <?php endif; ?>
  1009. <?php if(!empty($row['cs_address'] ?? '')): ?>
  1010. <li class="address"><?php echo htmlspecialcharsFix($row['cs_address']); ?></li>
  1011. <?php endif; ?>
  1012. </ul>
  1013. <div class="cs_detail_note"><?php echo htmlspecialcharsFix($row['cs_note'] ?? ''); ?></div>
  1014. </td>
  1015. </tr>
  1016. <?php
  1017. }
  1018. } else {
  1019. // 没有搜索结果的情况
  1020. if (!empty($keyscode)) {
  1021. echo '<tr><td colspan="9" align="center">没有找到 "' . htmlspecialcharsFix($keyscode) . '" 相关的客户信息</td></tr>';
  1022. } else {
  1023. echo '<tr><td colspan="9" align="center">暂无客户信息</td></tr>';
  1024. }
  1025. }
  1026. ?>
  1027. </tbody>
  1028. <tfoot>
  1029. <tr>
  1030. <td colspan="9">
  1031. <div class="showpagebox">
  1032. <?php
  1033. if ($totalPages > 1) {
  1034. $pageName = "?Keys=$keys&Ord=$ord$urlStr&";
  1035. $pageLen = 3;
  1036. if ($page > 1) {
  1037. echo "<a href=\"{$pageName}Page=1\">首页</a>";
  1038. echo "<a href=\"{$pageName}Page=" . ($page-1) . "\">上一页</a>";
  1039. }
  1040. if ($pageLen * 2 + 1 >= $totalPages) {
  1041. $startPage = 1;
  1042. $endPage = $totalPages;
  1043. } else {
  1044. if ($page <= $pageLen + 1) {
  1045. $startPage = 1;
  1046. $endPage = $pageLen * 2 + 1;
  1047. } else {
  1048. $startPage = $page - $pageLen;
  1049. $endPage = $page + $pageLen;
  1050. }
  1051. if ($page + $pageLen > $totalPages) {
  1052. $startPage = $totalPages - $pageLen * 2;
  1053. $endPage = $totalPages;
  1054. }
  1055. }
  1056. for ($i = $startPage; $i <= $endPage; $i++) {
  1057. if ($i == $page) {
  1058. echo "<a class=\"current\">$i</a>";
  1059. } else {
  1060. echo "<a href=\"{$pageName}Page=$i\">$i</a>";
  1061. }
  1062. }
  1063. if ($page < $totalPages) {
  1064. if ($totalPages - $page > $pageLen) {
  1065. echo "<a href=\"{$pageName}Page=$totalPages\">...$totalPages</a>";
  1066. }
  1067. echo "<a href=\"{$pageName}Page=" . ($page+1) . "\">下一页</a>";
  1068. echo "<a href=\"{$pageName}Page=$totalPages\">尾页</a>";
  1069. }
  1070. echo "<input type=\"text\" id=\"Pagego\" value=\"$page\"
  1071. onFocus=\"if(this.value == '$page'){this.value='';}\"
  1072. onBlur=\"if(this.value == ''){this.value='$page';}\"
  1073. onKeyUp=\"this.value=this.value.replace(/\D/g,'')\"
  1074. onKeyDown=\"if(event.keyCode==13){location.href='{$pageName}Page='+document.getElementById('Pagego').value}\" />";
  1075. }
  1076. ?>
  1077. </div>
  1078. <div class="postchkbox">
  1079. <select id="chkact" name="chkact">
  1080. <option value="1">显示</option>
  1081. <option value="0">隐藏</option>
  1082. <option value="-1">删除</option>
  1083. </select>
  1084. <input type="button" value="执行" onClick="postchk_new(1)" class="btn1" />
  1085. <input type="button" value="新增" onClick="location.href='?act=add'" class="btn1" />
  1086. </div>
  1087. </td>
  1088. </tr>
  1089. </tfoot>
  1090. </table>
  1091. </form>
  1092. </div>
  1093. </body>
  1094. </html>
  1095. <?php
  1096. $conn->close();
  1097. ?>