customers.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  1. <?php
  2. require_once('conn.php');
  3. checkLogin("信息管理");
  4. // Initialize variables
  5. $urlStr = "";
  6. $act = $_GET['act'] ?? '';
  7. $output = '';
  8. // Process all actions that might need headers
  9. if ($act == "save") {
  10. $isEdit = false;
  11. $id = $_POST['id'] ?? '';
  12. if (!empty($id) && is_numeric($id)) {
  13. $isEdit = true;
  14. }
  15. // Main customer table fields
  16. $cs_code = textEncode($_POST['cs_code'] ?? '');
  17. $cs_company = textEncode($_POST['cs_company'] ?? '');
  18. $cs_belong = intval($_POST['cs_belong'] ?? 0);
  19. $cs_country = intval($_POST['cs_country'] ?? 0);
  20. $cs_from = intval($_POST['cs_from'] ?? 0);
  21. $cs_state = intval($_POST['cs_state'] ?? 0);
  22. $cs_deal = intval($_POST['cs_deal'] ?? 0);
  23. $no_content = htmlEncode($_POST['no_content'] ?? '');
  24. $cs_address = textEncode($_POST['cs_address'] ?? '');
  25. $allowedit = isset($_POST['allowedit']) ? 1 : 0;
  26. // Contact fields
  27. $contact_name = textEncode($_POST['cs_name'] ?? '');
  28. $tel = textEncode($_POST['cs_tel'] ?? '');
  29. $email = textEncode($_POST['cs_email'] ?? '');
  30. $whatsapp = textEncode($_POST['cs_whatsapp'] ?? '');
  31. $wechat = textEncode($_POST['cs_wechat'] ?? '');
  32. $linkedin = textEncode($_POST['cs_linkedin'] ?? '');
  33. $facebook = textEncode($_POST['cs_facebook'] ?? '');
  34. $alibaba = textEncode($_POST['cs_alibaba'] ?? '');
  35. if ($isEdit) {
  36. $sql = "SELECT cs_chain FROM customer WHERE id=" . $id;
  37. $result = $conn->query($sql);
  38. if ($row = $result->fetch_assoc()) {
  39. $cs_chain = $row['cs_chain'];
  40. $chain_array = explode(',', $cs_chain);
  41. $last_item = end($chain_array);
  42. if ($last_item != $cs_belong) {
  43. $cs_chain .= ",$cs_belong";
  44. }
  45. // Update customer table
  46. $sql = "UPDATE customer SET
  47. cs_code='$cs_code',
  48. cs_company='$cs_company',
  49. cs_belong=$cs_belong,
  50. cs_country=$cs_country,
  51. cs_from=$cs_from,
  52. cs_state=$cs_state,
  53. cs_deal=$cs_deal,
  54. cs_note='$no_content',
  55. cs_address='$cs_address',
  56. allowedit=$allowedit,
  57. cs_chain='$cs_chain',
  58. cs_updatetime=NOW()
  59. WHERE id=$id";
  60. $conn->query($sql);
  61. // Check if contact exists for this customer
  62. $sql = "SELECT id FROM customer_contact WHERE customer_id=$id";
  63. $contact_result = $conn->query($sql);
  64. if ($contact_result->num_rows > 0) {
  65. $contact_row = $contact_result->fetch_assoc();
  66. $contact_id = $contact_row['id'];
  67. // Update existing contact
  68. $sql = "UPDATE customer_contact SET
  69. contact_name='$contact_name',
  70. tel='$tel',
  71. email='$email',
  72. whatsapp='$whatsapp',
  73. wechat='$wechat',
  74. linkedin='$linkedin',
  75. facebook='$facebook',
  76. alibaba='$alibaba',
  77. updated_at=NOW()
  78. WHERE id=$contact_id";
  79. $conn->query($sql);
  80. } else {
  81. // Create new contact for existing customer
  82. $sql = "INSERT INTO customer_contact (
  83. customer_id, contact_name, tel, email, whatsapp, wechat,
  84. linkedin, facebook, alibaba, created_at, updated_at
  85. ) VALUES (
  86. $id, '$contact_name', '$tel', '$email', '$whatsapp', '$wechat',
  87. '$linkedin', '$facebook', '$alibaba', NOW(), NOW()
  88. )";
  89. $conn->query($sql);
  90. }
  91. $page = $_GET['Page'] ?? '';
  92. $keys = urlencode($_GET['Keys'] ?? '');
  93. header("Location: ?keys=$keys&Page=$page$urlStr");
  94. exit;
  95. } else {
  96. $output = "<script>alert('不存在该客户');history.back();</script>";
  97. }
  98. } else {
  99. // Begin transaction
  100. $conn->begin_transaction();
  101. try {
  102. // Insert into customer table
  103. $sql = "INSERT INTO customer (
  104. cs_code, cs_company, cs_belong, cs_country, cs_from,
  105. cs_state, cs_deal, cs_note, cs_address,
  106. allowedit, cs_chain, cs_addtime, cs_updatetime
  107. ) VALUES (
  108. '$cs_code', '$cs_company', $cs_belong, $cs_country, $cs_from,
  109. $cs_state, $cs_deal, '$no_content', '$cs_address',
  110. $allowedit, '$cs_belong', NOW(), NOW()
  111. )";
  112. $conn->query($sql);
  113. $new_customer_id = $conn->insert_id;
  114. // Insert into customer_contact table
  115. $sql = "INSERT INTO customer_contact (
  116. customer_id, contact_name, tel, email, whatsapp, wechat,
  117. linkedin, facebook, alibaba, created_at, updated_at
  118. ) VALUES (
  119. $new_customer_id, '$contact_name', '$tel', '$email', '$whatsapp', '$wechat',
  120. '$linkedin', '$facebook', '$alibaba', NOW(), NOW()
  121. )";
  122. $conn->query($sql);
  123. // Commit transaction
  124. $conn->commit();
  125. header("Location: ?");
  126. exit;
  127. } catch (Exception $e) {
  128. // Rollback on failure
  129. $conn->rollback();
  130. $output = "<script>alert('保存失败: " . $e->getMessage() . "');history.back();</script>";
  131. }
  132. }
  133. }
  134. // If we have output from processing, we'll show it instead of the normal page
  135. if (!empty($output)) {
  136. echo $output;
  137. exit;
  138. }
  139. ?>
  140. <!DOCTYPE html>
  141. <html xmlns="http://www.w3.org/1999/xhtml">
  142. <head>
  143. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  144. <title>管理区域</title>
  145. <link rel="stylesheet" href="css/common.css" type="text/css" />
  146. <script language="javascript" src="js/jquery-1.7.2.min.js"></script>
  147. <script type="text/javascript" src="js/js.js"></script>
  148. <script type="text/javascript" src="xheditor-1.1.9/xheditor-1.1.9-zh-cn.min.js"></script>
  149. <script>
  150. $(document).ready(function(){
  151. $('.txt2').xheditor({
  152. tools:'full',
  153. hoverExecDelay:-1,
  154. urlBase:'system/',
  155. upLinkUrl:"upload.php",
  156. upLinkExt:"zip,rar,txt,pdf",
  157. upImgUrl:"upload.php",
  158. upImgExt:"jpg,jpeg,gif,png",
  159. upFlashUrl:"upload.php",
  160. upFlashExt:"swf",
  161. upMediaUrl:"upload.php",
  162. upMediaExt:"wmv,avi,wma,mp3,mid"
  163. });
  164. });
  165. </script>
  166. </head>
  167. <body>
  168. <div id="man_zone">
  169. <?php
  170. // 编辑操作
  171. if ($act == "edit" || $act == "add") {
  172. $id = $_GET['id'] ?? '';
  173. $isEdit = false;
  174. // 初始化变量
  175. $cs_code = $cs_company = $cs_name = $cs_tel = $cs_telBu = '';
  176. $cs_wechat = $cs_wechatBu = $cs_whatsapp = $cs_whatsappBu = '';
  177. $cs_email = $cs_emailBu = $cs_linkedin = $cs_linkedinBu = '';
  178. $cs_facebook = $cs_facebookBu = $cs_alibaba = $cs_alibabaBu = '';
  179. $cs_address = $cs_addtime = $cs_updatetime = $cs_note = '';
  180. $cs_belong = $cs_country = $cs_from = $cs_state = $cs_deal = $allowedit = 0;
  181. if (!empty($id) && is_numeric($id)) {
  182. $isEdit = true;
  183. // Join customer and customer_contact tables
  184. $sql = "SELECT c.*, cc.contact_name, cc.tel, cc.tel_bu, cc.email, cc.email_bu,
  185. cc.whatsapp, cc.whatsapp_bu, cc.wechat, cc.wechat_bu,
  186. cc.linkedin, cc.linkedin_bu, cc.facebook, cc.facebook_bu,
  187. cc.alibaba, cc.alibaba_bu
  188. FROM customer c
  189. LEFT JOIN customer_contact cc ON c.id = cc.customer_id
  190. WHERE c.id=$id";
  191. $result = $conn->query($sql);
  192. if ($row = $result->fetch_assoc()) {
  193. $cs_code = textUncode($row['cs_code']);
  194. $cs_company = textUncode($row['cs_company']);
  195. $cs_name = textUncode($row['contact_name']);
  196. $cs_country = $row['cs_country'];
  197. $cs_from = $row['cs_from'];
  198. $cs_tel = textUncode($row['tel']);
  199. $cs_telBu = textUncode($row['tel_bu']);
  200. $cs_wechat = textUncode($row['wechat']);
  201. $cs_wechatBu = textUncode($row['wechat_bu']);
  202. $cs_whatsapp = textUncode($row['whatsapp']);
  203. $cs_whatsappBu = textUncode($row['whatsapp_bu']);
  204. $cs_email = textUncode($row['email']);
  205. $cs_emailBu = textUncode($row['email_bu']);
  206. $cs_linkedin = textUncode($row['linkedin']);
  207. $cs_linkedinBu = textUncode($row['linkedin_bu']);
  208. $cs_facebook = textUncode($row['facebook']);
  209. $cs_facebookBu = textUncode($row['facebook_bu']);
  210. $cs_alibaba = textUncode($row['alibaba']);
  211. $cs_alibabaBu = textUncode($row['alibaba_bu']);
  212. $cs_address = textUncode($row['cs_address']);
  213. $cs_addtime = $row['cs_addtime'];
  214. $cs_updatetime = $row['cs_updatetime'];
  215. $cs_belong = $row['cs_belong'];
  216. $cs_state = $row['cs_state'];
  217. $cs_deal = $row['cs_deal'];
  218. $cs_note = htmlUncode($row['cs_note']);
  219. $allowedit = $row['allowedit'];
  220. }
  221. }
  222. $page = $_GET['Page'] ?? '';
  223. $keys = urlencode($_GET['Keys'] ?? '');
  224. $ord = urlencode($_GET['Ord'] ?? '');
  225. $hrefstr = "?keys=$keys&Page=$page&Ord=$ord";
  226. ?>
  227. <form name="form1" method="post" action="<?php echo $hrefstr; ?>&act=save">
  228. <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
  229. <tbody>
  230. <tr>
  231. <th width="8%">客户编号</th>
  232. <td><input type="text" id="cs_code" name="cs_code" value="<?php echo $cs_code; ?>" class="txt1" />
  233. <input type="hidden" name="id" value="<?php echo $id; ?>" /></td>
  234. </tr>
  235. <tr>
  236. <th width="8%">公司名称</th>
  237. <td><input type="text" id="cs_company" name="cs_company" value="<?php echo $cs_company; ?>" class="txt1" /></td>
  238. </tr>
  239. <tr>
  240. <th width="8%">联系人</th>
  241. <td><input type="text" id="cs_name" name="cs_name" value="<?php echo $cs_name; ?>" class="txt1" /></td>
  242. </tr>
  243. <tr>
  244. <th width="8%">所属业务</th>
  245. <td>
  246. <select name="cs_belong">
  247. <option value="0">请选择</option>
  248. <?php
  249. $sql = "SELECT id,em_user FROM employee";
  250. $result = $conn->query($sql);
  251. while($row = $result->fetch_assoc()) {
  252. $selected = ($row['id'] == $cs_belong) ? ' selected="selected"' : '';
  253. echo "<option value=\"{$row['id']}\"$selected>{$row['em_user']}</option>";
  254. }
  255. ?>
  256. </select>
  257. </td>
  258. </tr>
  259. <tr>
  260. <th width="8%">国家</th>
  261. <td>
  262. <select name="cs_country">
  263. <option value="0">请选择</option>
  264. <?php
  265. $sql = "SELECT id,countryCode,countryName FROM country";
  266. $result = $conn->query($sql);
  267. while($row = $result->fetch_assoc()) {
  268. $selected = ($row['id'] == $cs_country) ? ' selected="selected"' : '';
  269. echo "<option value=\"{$row['id']}\"$selected>{$row['countryName']}</option>";
  270. }
  271. ?>
  272. </select>
  273. </td>
  274. </tr>
  275. <tr>
  276. <th width="8%">来源</th>
  277. <td>
  278. <select name="cs_from">
  279. <option value="0">请选择</option>
  280. <?php
  281. $sql = "SELECT id,ch_name FROM qudao";
  282. $result = $conn->query($sql);
  283. while($row = $result->fetch_assoc()) {
  284. $selected = ($row['id'] == $cs_from) ? ' selected="selected"' : '';
  285. echo "<option value=\"{$row['id']}\"$selected>{$row['ch_name']}</option>";
  286. }
  287. ?>
  288. </select>
  289. </td>
  290. </tr>
  291. <tr>
  292. <th width="8%">录入时间</th>
  293. <td><?php echo $cs_addtime; ?></td>
  294. </tr>
  295. <tr>
  296. <th width="8%">更新时间</th>
  297. <td><?php echo $cs_updatetime; ?></td>
  298. </tr>
  299. <tr>
  300. <th width="8%" rowspan="7">联系方式</th>
  301. <td><input type="text" id="cs_tel" name="cs_tel" value="<?php echo $cs_tel ?? ''; ?>" class="txt5 tel" />备份:<?php echo $cs_telBu ?? ''; ?></td>
  302. </tr>
  303. <tr>
  304. <td><input type="text" id="cs_email" name="cs_email" value="<?php echo $cs_email ?? ''; ?>" class="txt5 mail" />备份:<?php echo $cs_emailBu ?? ''; ?></td>
  305. </tr>
  306. <tr>
  307. <td><input type="text" id="cs_whatsapp" name="cs_whatsapp" value="<?php echo $cs_whatsapp ?? ''; ?>" class="txt5 whatsapp" />备份:<?php echo $cs_whatsappBu ?? ''; ?></td>
  308. </tr>
  309. <tr>
  310. <td><input type="text" id="cs_wechat" name="cs_wechat" value="<?php echo $cs_wechat ?? ''; ?>" class="txt5 wechat" />备份:<?php echo $cs_wechatBu ?? ''; ?></td>
  311. </tr>
  312. <tr>
  313. <td><input type="text" id="cs_linkedin" name="cs_linkedin" value="<?php echo $cs_linkedin ?? ''; ?>" class="txt5 linkedin" />备份:<?php echo $cs_linkedinBu ?? ''; ?></td>
  314. </tr>
  315. <tr>
  316. <td><input type="text" id="cs_facebook" name="cs_facebook" value="<?php echo $cs_facebook ?? ''; ?>" class="txt5 facebook" />备份:<?php echo $cs_facebookBu ?? ''; ?></td>
  317. </tr>
  318. <tr>
  319. <td><input type="text" id="cs_alibaba" name="cs_alibaba" value="<?php echo $cs_alibaba ?? ''; ?>" class="txt5 alibaba" />备份:<?php echo $cs_alibabaBu ?? ''; ?></td>
  320. </tr>
  321. <tr>
  322. <th width="8%">地址</th>
  323. <td><input type="text" id="cs_address" name="cs_address" value="<?php echo $cs_address ?? ''; ?>" class="txt1" /></td>
  324. </tr>
  325. <tr>
  326. <th width="8%">标签</th>
  327. <td>
  328. <?php
  329. if($isEdit ?? false) {
  330. $sql = "SELECT id,tagName FROM tagtable WHERE customerId = ?";
  331. $stmt = $conn->prepare($sql);
  332. $stmt->bind_param("i", $id);
  333. $stmt->execute();
  334. $result = $stmt->get_result();
  335. while($row = $result->fetch_assoc()) {
  336. echo htmlspecialchars($row['tagName'] ?? '') . ',';
  337. }
  338. $stmt->close();
  339. }
  340. ?>
  341. </td>
  342. </tr>
  343. <tr>
  344. <th width="8%">状态</th>
  345. <td>
  346. <label><input type="radio" name="cs_state" value="1" <?php if(($cs_state ?? 0)==1) echo 'checked="checked"'; ?> />有效</label>
  347. <label><input type="radio" name="cs_state" value="0" <?php if(($cs_state ?? 0)!=1) echo 'checked="checked"'; ?> />不再跟进</label>
  348. </td>
  349. </tr>
  350. <tr>
  351. <th width="8%">是否误报</th>
  352. <td>
  353. <label><input type="radio" name="allowedit" value="1" <?php if(($allowedit ?? 0)==1) echo 'checked="checked"'; ?> />审核通过</label>
  354. <label><input type="radio" name="allowedit" value="0" <?php if(($allowedit ?? 0)!=1) echo 'checked="checked"'; ?> />一般处理</label>
  355. </td>
  356. </tr>
  357. <tr>
  358. <th width="8%">是否成交</th>
  359. <td>
  360. <label><input type="radio" name="cs_deal" value="3" <?php if(($cs_deal ?? 0)==3) echo 'checked="checked"'; ?> />成交</label>
  361. <label><input type="radio" name="cs_deal" value="2" <?php if(($cs_deal ?? 0)==2) echo 'checked="checked"'; ?> />明确需求</label>
  362. <label><input type="radio" name="cs_deal" value="1" <?php if(($cs_deal ?? 0)==1) echo 'checked="checked"'; ?> />背景调查</label>
  363. <label><input type="radio" name="cs_deal" value="0" <?php if(($cs_deal ?? 0)==0) echo 'checked="checked"'; ?> />无响应</label>
  364. </td>
  365. </tr>
  366. <tr>
  367. <th>内容</th>
  368. <td><textarea id="no_content" name="no_content" class="txt2"><?php echo $cs_note ?? ''; ?></textarea></td>
  369. </tr>
  370. <tr>
  371. <th></th>
  372. <td>
  373. <input type="submit" name="save" id="save" value="确定" class="btn1" />
  374. <input type="reset" name="save" id="save" value="重置" class="btn1" />
  375. <input type="button" value="返回" class="btn1" onClick="location.href='<?php echo $hrefstr; ?>'" />
  376. </td>
  377. </tr>
  378. </tbody>
  379. </table>
  380. </form>
  381. <?php
  382. exit;
  383. }
  384. // 批量操作
  385. if ($act == "postchk") {
  386. $keys = urlencode($_GET['Keys'] ?? '');
  387. $page = $_GET['Page'] ?? '';
  388. $chkact = $_POST['chkact'] ?? '';
  389. if (isset($_POST['chkbox']) && is_array($_POST['chkbox'])) {
  390. $ids = array_map('intval', $_POST['chkbox']);
  391. $idList = implode(',', $ids);
  392. if (!empty($idList)) {
  393. switch($chkact) {
  394. case "0":
  395. case "1":
  396. $sql = "UPDATE customer SET cs_state=$chkact WHERE id IN ($idList)";
  397. break;
  398. default:
  399. // In delete case, let's use transactions to ensure both tables are updated
  400. $conn->begin_transaction();
  401. try {
  402. // Delete from customer_contact first (due to foreign key constraint)
  403. $sql = "DELETE FROM customer_contact WHERE customer_id IN ($idList)";
  404. $conn->query($sql);
  405. // Then delete from customer table
  406. $sql = "DELETE FROM customer WHERE id IN ($idList)";
  407. $conn->query($sql);
  408. $conn->commit();
  409. } catch (Exception $e) {
  410. $conn->rollback();
  411. echo "<script>alert('删除失败: " . $e->getMessage() . "');</script>";
  412. }
  413. }
  414. if ($chkact == "0" || $chkact == "1") {
  415. $conn->query($sql);
  416. }
  417. }
  418. }
  419. header("Location: ?Keys=$keys&Page=$page");
  420. exit;
  421. }
  422. // 主列表页面
  423. $fliterQudao = $_GET['fliterQudao'] ?? '';
  424. $fliterDeal = $_GET['fliterDeal'] ?? '';
  425. $fliterTeam = $_GET['fliterTeam'] ?? '';
  426. $fliterContact = $_GET['fliterContact'] ?? '';
  427. $fliterEmployee = $_GET['fliterEmployee'] ?? '';
  428. $filterStr = "";
  429. $urlStr = "";
  430. if (!empty($fliterQudao)) {
  431. $filterStr .= " AND c.cs_from=" . intval($fliterQudao);
  432. $urlStr .= "&fliterQudao=$fliterQudao";
  433. }
  434. if (!empty($fliterDeal)) {
  435. $filterStr .= " AND c.cs_deal=" . intval($fliterDeal);
  436. $urlStr .= "&fliterDeal=$fliterDeal";
  437. }
  438. if (!empty($fliterTeam)) {
  439. $filterStr .= " AND (c.cs_belong=" . intval($fliterTeam) .
  440. " OR c.cs_belong IN (SELECT id FROM employee WHERE em_role=" . intval($fliterTeam) . "))";
  441. $urlStr .= "&fliterTeam=$fliterTeam";
  442. }
  443. if (!empty($fliterEmployee)) {
  444. $filterStr .= " AND c.cs_belong=" . intval($fliterEmployee);
  445. $urlStr .= "&fliterEmployee=$fliterEmployee";
  446. }
  447. if (!empty($fliterContact)) {
  448. switch($fliterContact) {
  449. case "1": $filterStr .= " AND cc.tel<>''"; break;
  450. case "2": $filterStr .= " AND cc.wechat<>''"; break;
  451. case "3": $filterStr .= " AND cc.whatsapp<>''"; break;
  452. case "4": $filterStr .= " AND cc.email<>''"; break;
  453. case "5": $filterStr .= " AND cc.linkedin<>''"; break;
  454. case "6": $filterStr .= " AND cc.facebook<>''"; break;
  455. default: $filterStr .= " AND cc.alibaba<>''";
  456. }
  457. $urlStr .= "&fliterContact=$fliterContact";
  458. }
  459. $keys = $_GET['Keys'] ?? '';
  460. $keyscode = textEncode($keys);
  461. $page = $_GET['Page'] ?? '';
  462. $ord = $_GET['Ord'] ?? '';
  463. $sql = "SELECT c.id, c.cs_code, c.cs_company, c.cs_country, c.cs_address,
  464. c.cs_from, c.cs_deal, c.cs_addtime, c.cs_updatetime, c.cs_belong, c.cs_note,
  465. c.cs_claimFrom, c.cs_chain, c.cs_dealdate,
  466. cc.contact_name as cs_name, cc.tel as cs_tel, cc.email as cs_email,
  467. cc.whatsapp as cs_whatsapp, cc.wechat as cs_wechat, cc.linkedin as cs_linkedin,
  468. cc.facebook as cs_facebook, cc.alibaba as cs_alibaba
  469. FROM customer c
  470. LEFT JOIN customer_contact cc ON c.id = cc.customer_id
  471. WHERE (c.cs_code LIKE '%$keyscode%'
  472. OR cc.contact_name LIKE '%$keyscode%'
  473. OR cc.wechat LIKE '%$keyscode%'
  474. OR cc.alibaba LIKE '%$keyscode%'
  475. OR cc.tel LIKE '%$keyscode%'
  476. OR cc.whatsapp LIKE '%$keyscode%'
  477. OR cc.email LIKE '%$keyscode%')
  478. $filterStr
  479. ORDER BY c.cs_updatetime DESC";
  480. $result = $conn->query($sql);
  481. ?>
  482. <form id="form1" method="post" action="?act=postchk&Keys=<?php echo $keys; ?>&Page=<?php echo $page; ?>" onSubmit="return false">
  483. <div class="fastSelect clear">
  484. <H1>搜索条件</H1>
  485. <div class="selectItem">
  486. <label>来源渠道</label>
  487. <select name="fliterQudao" class="filterSearch">
  488. <option value="">请选择渠道</option>
  489. <?php
  490. $sql_temp = "SELECT id,ch_name FROM qudao";
  491. $qudaoResult = $conn->query($sql_temp);
  492. while($row = $qudaoResult->fetch_assoc()) {
  493. $selected = ($fliterQudao == $row['id']) ? ' selected="selected"' : '';
  494. echo "<option value=\"{$row['id']}\"$selected>{$row['ch_name']}</option>";
  495. }
  496. ?>
  497. </select>
  498. </div>
  499. <div class="selectItem">
  500. <label>是否成交</label>
  501. <select name="fliterDeal" class="filterSearch">
  502. <option value="">请选择</option>
  503. <option value="3" <?php if($fliterDeal=="3") echo 'selected="selected"'; ?>>已成交</option>
  504. <option value="2" <?php if($fliterDeal=="2") echo 'selected="selected"'; ?>>明确需求</option>
  505. <option value="1" <?php if($fliterDeal=="1") echo 'selected="selected"'; ?>>背景调查</option>
  506. <option value="0" <?php if($fliterDeal=="0") echo 'selected="selected"'; ?>>无响应</option>
  507. </select>
  508. </div>
  509. <div class="selectItem">
  510. <label>按组</label>
  511. <select name="fliterTeam" class="filterSearch">
  512. <option value="">请选择</option>
  513. <?php
  514. $sql_temp = "SELECT id,em_user FROM employee WHERE em_role=0";
  515. $teamResult = $conn->query($sql_temp);
  516. while($row = $teamResult->fetch_assoc()) {
  517. $selected = ($fliterTeam == $row['id']) ? ' selected="selected"' : '';
  518. echo "<option value=\"{$row['id']}\"$selected>{$row['em_user']}组</option>";
  519. }
  520. ?>
  521. </select>
  522. </div>
  523. <div class="selectItem">
  524. <label>业务</label>
  525. <select name="fliterEmployee" class="filterSearch">
  526. <option value="">请选择</option>
  527. <?php
  528. $sql_temp = "SELECT id,em_user FROM employee";
  529. $empResult = $conn->query($sql_temp);
  530. while($row = $empResult->fetch_assoc()) {
  531. $selected = ($fliterEmployee == $row['id']) ? ' selected="selected"' : '';
  532. echo "<option value=\"{$row['id']}\"$selected>{$row['em_user']}</option>";
  533. }
  534. ?>
  535. </select>
  536. </div>
  537. <div class="selectItem">
  538. <label>联系方式</label>
  539. <select name="fliterContact" class="filterSearch">
  540. <option value="">请选择</option>
  541. <option value="1" <?php if($fliterContact=="1") echo 'selected="selected"'; ?>>电话</option>
  542. <option value="2" <?php if($fliterContact=="2") echo 'selected="selected"'; ?>>微信</option>
  543. <option value="3" <?php if($fliterContact=="3") echo 'selected="selected"'; ?>>WhatsApp</option>
  544. <option value="4" <?php if($fliterContact=="4") echo 'selected="selected"'; ?>>邮箱</option>
  545. <option value="5" <?php if($fliterContact=="5") echo 'selected="selected"'; ?>>领英</option>
  546. <option value="6" <?php if($fliterContact=="6") echo 'selected="selected"'; ?>>Facebook</option>
  547. <option value="7" <?php if($fliterContact=="7") echo 'selected="selected"'; ?>>阿里巴巴</option>
  548. </select>
  549. </div>
  550. <div class="inputSearch">
  551. <input type="text" id="keys" class="inputTxt" value="<?php echo empty($keyscode) ? '请输入搜索关键词' : $keyscode; ?>"
  552. onFocus="if(this.value == '<?php echo empty($keyscode) ? '请输入搜索关键词' : $keyscode; ?>'){this.value='';}"
  553. onBlur="if(this.value == ''){this.value='<?php echo empty($keyscode) ? '请输入搜索关键词' : $keyscode; ?>';}"
  554. onKeyDown="if(event.keyCode==13){location.href='?Keys='+escape(document.getElementById('keys').value)+'<?php echo $urlStr; ?>'}" />
  555. <input type="button" id="searchgo" class="searchgo" value="go"
  556. onClick="location.href='?Keys='+escape(document.getElementById('keys').value)+'<?php echo $urlStr; ?>'" />
  557. </div>
  558. </div>
  559. <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
  560. <thead>
  561. <tr>
  562. <th width="4%"><input type="checkbox" name="chkall" id="chkall" onClick="chkboxall(this,'chkbox')" /></th>
  563. <th width="6%">序号</th>
  564. <th width="20%">客户编码</th>
  565. <th width="10%">联系人</th>
  566. <th width="10%">国家地区</th>
  567. <th width="7.5%">来源</th>
  568. <th width="7.5%">是否成交</th>
  569. <th width="10%">业务员</th>
  570. <th width="10%">操作</th>
  571. </tr>
  572. </thead>
  573. <tbody>
  574. <?php
  575. if ($result->num_rows > 0) {
  576. $pageSize = 18;
  577. $totalPages = ceil($result->num_rows / $pageSize);
  578. if (empty($page)) $page = 1;
  579. if ($page == 'end') $page = $totalPages;
  580. if (!is_numeric($page) || $page < 1) $page = 1;
  581. $page = (int)$page;
  582. if ($page > $totalPages) $page = $totalPages;
  583. $offset = ($page - 1) * $pageSize;
  584. $sql .= " LIMIT $offset, $pageSize";
  585. $result = $conn->query($sql);
  586. $tempNum = $pageSize * ($page - 1);
  587. while ($row = $result->fetch_assoc()) {
  588. $tempNum++;
  589. ?>
  590. <tr onMouseOver="this.style.background='#F7FCFF'" onMouseOut="this.style.background='#FFFFFF'">
  591. <td align="center"><input type="checkbox" name="chkbox" value="<?php echo $row['id'] ?? ''; ?>" /></td>
  592. <td align="center"><?php echo $tempNum; ?></td>
  593. <td align="center" class="code" data-id="<?php echo $row['id'] ?? ''; ?>">
  594. <?php
  595. echo $row['cs_code'] ?? ''; ?>
  596. <?php if(($row['cs_claimFrom'] ?? 0) > 0): ?>
  597. <img src="../images/yijiao.png" class="handover">
  598. <?php endif; ?>
  599. </td>
  600. <td align="center"><?php echo $row['cs_name'] ?? ''; ?></td>
  601. <td align="center">
  602. <?php
  603. $countryId = intval($row['cs_country'] ?? 0);
  604. $sql = "SELECT countryName FROM country WHERE id = ?";
  605. $stmt = $conn->prepare($sql);
  606. $stmt->bind_param("i", $countryId);
  607. $stmt->execute();
  608. $countryResult = $stmt->get_result();
  609. if ($countryRow = $countryResult->fetch_assoc()) {
  610. echo htmlspecialchars($countryRow['countryName']);
  611. } else {
  612. echo "未选择";
  613. }
  614. $stmt->close();
  615. ?>
  616. </td>
  617. <td align="center">
  618. <?php
  619. $fromId = intval($row['cs_from'] ?? 0);
  620. $sql = "SELECT ch_name FROM qudao WHERE id = ?";
  621. $stmt = $conn->prepare($sql);
  622. $stmt->bind_param("i", $fromId);
  623. $stmt->execute();
  624. $qudaoResult = $stmt->get_result();
  625. if ($qudaoRow = $qudaoResult->fetch_assoc()) {
  626. echo htmlspecialchars($qudaoRow['ch_name']);
  627. } else {
  628. echo "未选择";
  629. }
  630. $stmt->close();
  631. ?>
  632. </td>
  633. <td align="center">
  634. <?php
  635. $cs_deal = intval($row['cs_deal'] ?? 0);
  636. if ($cs_deal == 3) {
  637. echo "<span style='color:red;font-size:10px;'>" . htmlspecialchars($row['cs_dealdate'] ?? '') . "成交</span>";
  638. } elseif ($cs_deal == 2) {
  639. echo "明确需求";
  640. } elseif ($cs_deal == 1) {
  641. echo "背景调查";
  642. } else {
  643. echo "无响应";
  644. }
  645. ?>
  646. </td>
  647. <td align="center">
  648. <?php
  649. $belongId = intval($row['cs_belong'] ?? 0);
  650. $sql = "SELECT em_user FROM employee WHERE id = ?";
  651. $stmt = $conn->prepare($sql);
  652. $stmt->bind_param("i", $belongId);
  653. $stmt->execute();
  654. $empResult = $stmt->get_result();
  655. if ($empRow = $empResult->fetch_assoc()) {
  656. echo htmlspecialchars($empRow['em_user']);
  657. } else {
  658. echo "未选择";
  659. }
  660. $stmt->close();
  661. ?>
  662. </td>
  663. <td align="center">
  664. <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>
  665. </td>
  666. </tr>
  667. <tr class="detail_panel code<?php echo $row['id'] ?? ''; ?>__panel">
  668. <td colspan="2"></td>
  669. <td colspan="7" class="cs_detail">
  670. <ul>
  671. <li class="cs_detail_addtime">录入时间:<?php echo htmlspecialchars($row['cs_addtime'] ?? ''); ?></li>
  672. <li class="cs_detail_addtime">更新时间:<?php echo htmlspecialchars($row['cs_updatetime'] ?? ''); ?></li>
  673. <li class="cs_detail_addtime">
  674. 流转记录:
  675. <?php
  676. $chain = $row['cs_chain'] ?? '';
  677. if(!empty($chain)) {
  678. $chain_array = explode(',', $chain);
  679. $chain_ids = array_filter(array_map('intval', $chain_array));
  680. if(!empty($chain_ids)) {
  681. $placeholders = str_repeat('?,', count($chain_ids) - 1) . '?';
  682. $sql = "SELECT em_user FROM employee WHERE id IN ($placeholders)";
  683. $stmt = $conn->prepare($sql);
  684. $stmt->bind_param(str_repeat('i', count($chain_ids)), ...$chain_ids);
  685. $stmt->execute();
  686. $chainResult = $stmt->get_result();
  687. $chain_users = [];
  688. while($chainRow = $chainResult->fetch_assoc()) {
  689. $chain_users[] = htmlspecialchars($chainRow['em_user']);
  690. }
  691. echo implode(' > ', $chain_users);
  692. $stmt->close();
  693. }
  694. }
  695. ?>
  696. </li>
  697. <?php if(!empty($row['cs_tel'] ?? '')): ?>
  698. <li class="tel"><?php echo htmlspecialchars($row['cs_tel']); ?></li>
  699. <?php endif; ?>
  700. <?php if(!empty($row['cs_email'] ?? '')): ?>
  701. <li class="mail"><?php echo htmlspecialchars($row['cs_email']); ?></li>
  702. <?php endif; ?>
  703. <?php if(!empty($row['cs_whatsapp'] ?? '')): ?>
  704. <li class="whatsapp"><?php echo htmlspecialchars($row['cs_whatsapp']); ?></li>
  705. <?php endif; ?>
  706. <?php if(!empty($row['cs_wechat'] ?? '')): ?>
  707. <li class="wechat"><?php echo htmlspecialchars($row['cs_wechat']); ?></li>
  708. <?php endif; ?>
  709. <?php if(!empty($row['cs_linkedin'] ?? '')): ?>
  710. <li class="linkedin"><?php echo htmlspecialchars($row['cs_linkedin']); ?></li>
  711. <?php endif; ?>
  712. <?php if(!empty($row['cs_facebook'] ?? '')): ?>
  713. <li class="facebook"><?php echo htmlspecialchars($row['cs_facebook']); ?></li>
  714. <?php endif; ?>
  715. <?php if(!empty($row['cs_alibaba'] ?? '')): ?>
  716. <li class="alibaba"><?php echo htmlspecialchars($row['cs_alibaba']); ?></li>
  717. <?php endif; ?>
  718. <?php if(!empty($row['cs_address'] ?? '')): ?>
  719. <li class="address"><?php echo htmlspecialchars($row['cs_address']); ?></li>
  720. <?php endif; ?>
  721. </ul>
  722. <div class="cs_detail_note"><?php echo htmlspecialchars($row['cs_note'] ?? ''); ?></div>
  723. </td>
  724. </tr>
  725. <?php
  726. }
  727. } else {
  728. if (empty($keys)) {
  729. ?>
  730. <tr>
  731. <td align="center" colspan="9">Sorry,当前暂无信息</td>
  732. </tr>
  733. <?php
  734. } else {
  735. ?>
  736. <tr>
  737. <td align="center" colspan="9"><a href="?">Sorry,没有找到"<?php echo $keyscode; ?>"相关的信息,点击返回</a></td>
  738. </tr>
  739. <?php
  740. }
  741. }
  742. ?>
  743. </tbody>
  744. <tfoot>
  745. <tr>
  746. <td colspan="9">
  747. <div class="showpagebox">
  748. <?php
  749. if ($totalPages > 1) {
  750. $pageName = "?Keys=$keys&Ord=$ord$urlStr&";
  751. $pageLen = 3;
  752. if ($page > 1) {
  753. echo "<a href=\"{$pageName}Page=1\">首页</a>";
  754. echo "<a href=\"{$pageName}Page=" . ($page-1) . "\">上一页</a>";
  755. }
  756. if ($pageLen * 2 + 1 >= $totalPages) {
  757. $startPage = 1;
  758. $endPage = $totalPages;
  759. } else {
  760. if ($page <= $pageLen + 1) {
  761. $startPage = 1;
  762. $endPage = $pageLen * 2 + 1;
  763. } else {
  764. $startPage = $page - $pageLen;
  765. $endPage = $page + $pageLen;
  766. }
  767. if ($page + $pageLen > $totalPages) {
  768. $startPage = $totalPages - $pageLen * 2;
  769. $endPage = $totalPages;
  770. }
  771. }
  772. for ($i = $startPage; $i <= $endPage; $i++) {
  773. if ($i == $page) {
  774. echo "<a class=\"current\">$i</a>";
  775. } else {
  776. echo "<a href=\"{$pageName}Page=$i\">$i</a>";
  777. }
  778. }
  779. if ($page < $totalPages) {
  780. if ($totalPages - $page > $pageLen) {
  781. echo "<a href=\"{$pageName}Page=$totalPages\">...$totalPages</a>";
  782. }
  783. echo "<a href=\"{$pageName}Page=" . ($page+1) . "\">下一页</a>";
  784. echo "<a href=\"{$pageName}Page=$totalPages\">尾页</a>";
  785. }
  786. echo "<input type=\"text\" id=\"Pagego\" value=\"$page\"
  787. onFocus=\"if(this.value == '$page'){this.value='';}\"
  788. onBlur=\"if(this.value == ''){this.value='$page';}\"
  789. onKeyUp=\"this.value=this.value.replace(/\D/g,'')\"
  790. onKeyDown=\"if(event.keyCode==13){location.href='{$pageName}Page='+document.getElementById('Pagego').value}\" />";
  791. }
  792. ?>
  793. </div>
  794. <div class="postchkbox">
  795. <select id="chkact" name="chkact">
  796. <option value="1">显示</option>
  797. <option value="0">隐藏</option>
  798. <option value="-1">删除</option>
  799. </select>
  800. <input type="button" value="执行" onClick="postchk(1)" class="btn1" />
  801. <input type="button" value="新增" onClick="location.href='?act=add'" class="btn1" />
  802. </div>
  803. </td>
  804. </tr>
  805. </tfoot>
  806. </table>
  807. </form>
  808. </div>
  809. </body>
  810. </html>
  811. <?php
  812. $conn->close();
  813. ?>