customers.php 56 KB

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