searchResult.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <?php
  2. require_once 'conn.php';
  3. checkLogin();
  4. $keywordsNative = $_POST['keywords'] ?? '';
  5. $keywords = str_replace(['+', ' ', '-', ')', '('], '', $keywordsNative);
  6. $keywords = textEncode($keywords);
  7. if (empty($keywords) || strlen($keywords) < 4) {
  8. echo "<script>alert('请至少输入4位数字或文字进行查找');window.location.href='/home.php';</script>";
  9. exit;
  10. }
  11. $searchStr = "SELECT c.id, c.cs_code, cc.contact_name as cs_name, c.cs_country, cc.tel_1 as cs_tel,
  12. cc.email_1 as cs_email, cc.whatsapp_1 as cs_whatsapp, cc.wechat_1 as cs_wechat,
  13. cc.linkedin_1 as cs_linkedin, cc.facebook_1 as cs_facebook, c.cs_addtime,
  14. c.cs_from, c.cs_belong, c.cs_deal, cc.alibaba_1 as cs_alibaba
  15. FROM customer c
  16. LEFT JOIN customer_contact cc ON c.id = cc.customer_id
  17. WHERE (cc.tel_1_format LIKE '%" . $conn->real_escape_string($keywords) . "%'
  18. OR cc.tel_2_format LIKE '%" . $conn->real_escape_string($keywords) . "%'
  19. OR cc.tel_3_format LIKE '%" . $conn->real_escape_string($keywords) . "%'
  20. OR cc.email_1 LIKE '%" . $conn->real_escape_string($keywords) . "%'
  21. OR cc.email_2 LIKE '%" . $conn->real_escape_string($keywords) . "%'
  22. OR cc.email_3 LIKE '%" . $conn->real_escape_string($keywords) . "%'
  23. OR cc.whatsapp_1_format LIKE '%" . $conn->real_escape_string($keywords) . "%'
  24. OR cc.whatsapp_2_format LIKE '%" . $conn->real_escape_string($keywords) . "%'
  25. OR cc.whatsapp_3_format LIKE '%" . $conn->real_escape_string($keywords) . "%'
  26. OR cc.wechat_1 LIKE '%" . $conn->real_escape_string($keywords) . "%'
  27. OR cc.wechat_2 LIKE '%" . $conn->real_escape_string($keywords) . "%'
  28. OR cc.wechat_3 LIKE '%" . $conn->real_escape_string($keywords) . "%'
  29. OR cc.alibaba_1 LIKE '%" . $conn->real_escape_string($keywords) . "%'
  30. OR cc.alibaba_2 LIKE '%" . $conn->real_escape_string($keywords) . "%'
  31. OR cc.alibaba_3 LIKE '%" . $conn->real_escape_string($keywords) . "%'
  32. OR cc.linkedin_1 LIKE '%" . $conn->real_escape_string($keywords) . "%'
  33. OR cc.linkedin_2 LIKE '%" . $conn->real_escape_string($keywords) . "%'
  34. OR cc.linkedin_3 LIKE '%" . $conn->real_escape_string($keywords) . "%'
  35. OR cc.facebook_1 LIKE '%" . $conn->real_escape_string($keywords) . "%'
  36. OR cc.facebook_2 LIKE '%" . $conn->real_escape_string($keywords) . "%'
  37. OR cc.facebook_3 LIKE '%" . $conn->real_escape_string($keywords) . "%'
  38. OR cc.email_1 LIKE '%" . $conn->real_escape_string($keywordsNative) . "%'
  39. OR cc.email_2 LIKE '%" . $conn->real_escape_string($keywordsNative) . "%'
  40. OR cc.email_3 LIKE '%" . $conn->real_escape_string($keywordsNative) . "%'
  41. OR cc.wechat_1 LIKE '%" . $conn->real_escape_string($keywordsNative) . "%'
  42. OR cc.wechat_2 LIKE '%" . $conn->real_escape_string($keywordsNative) . "%'
  43. OR cc.wechat_3 LIKE '%" . $conn->real_escape_string($keywordsNative) . "%'
  44. OR cc.alibaba_1 LIKE '%" . $conn->real_escape_string($keywordsNative) . "%'
  45. OR cc.alibaba_2 LIKE '%" . $conn->real_escape_string($keywordsNative) . "%'
  46. OR cc.alibaba_3 LIKE '%" . $conn->real_escape_string($keywordsNative) . "%'
  47. OR cc.linkedin_1 LIKE '%" . $conn->real_escape_string($keywordsNative) . "%'
  48. OR cc.linkedin_2 LIKE '%" . $conn->real_escape_string($keywordsNative) . "%'
  49. OR cc.linkedin_3 LIKE '%" . $conn->real_escape_string($keywordsNative) . "%'
  50. OR cc.facebook_1 LIKE '%" . $conn->real_escape_string($keywordsNative) . "%'
  51. OR cc.facebook_2 LIKE '%" . $conn->real_escape_string($keywordsNative) . "%'
  52. OR cc.facebook_3 LIKE '%" . $conn->real_escape_string($keywordsNative) . "%')";
  53. ?>
  54. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  55. <html xmlns="http://www.w3.org/1999/xhtml">
  56. <head>
  57. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  58. <title>管理区域</title>
  59. <link rel="stylesheet" href="css/common.css" type="text/css" />
  60. <link rel="stylesheet" href="css/alert.css" type="text/css" />
  61. <script src="system/js/jquery-1.7.2.min.js"></script>
  62. <script src="js/js.js"></script>
  63. <style>
  64. body {
  65. margin: 0;
  66. padding: 20px;
  67. background: #fff;
  68. }
  69. #man_zone {
  70. margin-left: 0;
  71. }
  72. </style>
  73. </head>
  74. <body class="clear">
  75. <?php // require_once 'panel.php'; ?>
  76. <div id="man_zone">
  77. <div class="searchForm resultSearch">
  78. <form method="post" action="searchResult.php" accept-charset="UTF-8">
  79. <input class="keywords" name="keywords" id="keyword" placeholder="请输入电话/邮箱/微信/WhatsApp.." value="<?= htmlspecialcharsFix($keywordsNative) ?>">
  80. <input class="searchSubmit" type="submit" value="客户检索">
  81. </form>
  82. </div>
  83. <table width="100%" class="resultForm">
  84. <tr class="tableHead">
  85. <td align="center">序号</td>
  86. <td align="center">客户编号</td>
  87. <td align="center">联系人</td>
  88. <td align="center">国家</td>
  89. <td align="center">来源</td>
  90. <td align="center">跟进阶段</td>
  91. <td align="center">录入日期</td>
  92. <td align="center">所属业务员</td>
  93. </tr>
  94. <?php
  95. $result = $conn->query($searchStr);
  96. if ($result && $result->num_rows > 0) {
  97. $i = 1;
  98. while ($row = $result->fetch_assoc()) {
  99. ?>
  100. <tr>
  101. <td align="center" rowspan="2"><?= $i ?></td>
  102. <td align="center"><?= htmlspecialcharsFix($row['cs_code']) ?></td>
  103. <td align="center"><?= htmlspecialcharsFix($row['cs_name']) ?></td>
  104. <td align="center">
  105. <?php
  106. $countryResult = $conn->query("SELECT countryName FROM country WHERE id=" . (int)$row['cs_country']);
  107. echo ($countryRow = $countryResult->fetch_assoc()) ? htmlspecialcharsFix($countryRow['countryName']) : '未选择';
  108. ?>
  109. </td>
  110. <td align="center">
  111. <?php
  112. $qudaoResult = $conn->query("SELECT ch_name FROM qudao WHERE id=" . (int)$row['cs_from']);
  113. echo ($qudaoRow = $qudaoResult->fetch_assoc()) ? htmlspecialcharsFix($qudaoRow['ch_name']) : '未选择';
  114. ?>
  115. </td>
  116. <td align="center">
  117. <?= ($row['cs_deal'] == 3) ? '<span class="highline">成交</span>' : '未成交' ?>
  118. </td>
  119. <td align="center"><?= $row['cs_addtime'] ?></td>
  120. <td align="center" rowspan="2">
  121. <?php
  122. $employeeResult = $conn->query("SELECT em_user FROM employee WHERE id=" . (int)$row['cs_belong']);
  123. echo ($employeeRow = $employeeResult->fetch_assoc()) ? htmlspecialcharsFix($employeeRow['em_user']) : '系统出错';
  124. ?>
  125. </td>
  126. </tr>
  127. <tr>
  128. <td colspan="6" class="contacts">
  129. <?php
  130. // 获取该客户的所有联系人信息
  131. if (isset($row['id']) && !empty($row['id'])) {
  132. $contact_sql = "SELECT * FROM customer_contact WHERE customer_id = " . (int)$row['id'];
  133. $contact_result = mysqli_query($conn, $contact_sql);
  134. while ($contact = mysqli_fetch_assoc($contact_result)) {
  135. ?>
  136. <div class="contact-block">
  137. <?php if(!empty($contact['contact_name'])): ?>
  138. <div class="contact-name"><?= htmlspecialcharsFix($contact['contact_name']) ?></div>
  139. <?php endif; ?>
  140. <div class="tel">
  141. <?php if(!empty($contact['tel_1'])): ?>
  142. <div><?= htmlspecialcharsFix($contact['tel_1']) ?></div>
  143. <?php endif; ?>
  144. <?php if(!empty($contact['tel_2'])): ?>
  145. <div><?= htmlspecialcharsFix($contact['tel_2']) ?></div>
  146. <?php endif; ?>
  147. <?php if(!empty($contact['tel_3'])): ?>
  148. <div><?= htmlspecialcharsFix($contact['tel_3']) ?></div>
  149. <?php endif; ?>
  150. </div>
  151. <div class="mail">
  152. <?php if(!empty($contact['email_1'])): ?>
  153. <div><a href="mailto:<?= $contact['email_1'] ?>"><?= htmlspecialcharsFix($contact['email_1']) ?></a></div>
  154. <?php endif; ?>
  155. <?php if(!empty($contact['email_2'])): ?>
  156. <div><a href="mailto:<?= $contact['email_2'] ?>"><?= htmlspecialcharsFix($contact['email_2']) ?></a></div>
  157. <?php endif; ?>
  158. <?php if(!empty($contact['email_3'])): ?>
  159. <div><a href="mailto:<?= $contact['email_3'] ?>"><?= htmlspecialcharsFix($contact['email_3']) ?></a></div>
  160. <?php endif; ?>
  161. </div>
  162. <div class="whatsapp">
  163. <?php if(!empty($contact['whatsapp_1'])): ?>
  164. <div><?= htmlspecialcharsFix($contact['whatsapp_1']) ?></div>
  165. <?php endif; ?>
  166. <?php if(!empty($contact['whatsapp_2'])): ?>
  167. <div><?= htmlspecialcharsFix($contact['whatsapp_2']) ?></div>
  168. <?php endif; ?>
  169. <?php if(!empty($contact['whatsapp_3'])): ?>
  170. <div><?= htmlspecialcharsFix($contact['whatsapp_3']) ?></div>
  171. <?php endif; ?>
  172. </div>
  173. <div class="wechat">
  174. <?php if(!empty($contact['wechat_1'])): ?>
  175. <div><?= htmlspecialcharsFix($contact['wechat_1']) ?></div>
  176. <?php endif; ?>
  177. <?php if(!empty($contact['wechat_2'])): ?>
  178. <div><?= htmlspecialcharsFix($contact['wechat_2']) ?></div>
  179. <?php endif; ?>
  180. <?php if(!empty($contact['wechat_3'])): ?>
  181. <div><?= htmlspecialcharsFix($contact['wechat_3']) ?></div>
  182. <?php endif; ?>
  183. </div>
  184. <div class="linkedin">
  185. <?php if(!empty($contact['linkedin_1'])): ?>
  186. <div><?= htmlspecialcharsFix($contact['linkedin_1']) ?></div>
  187. <?php endif; ?>
  188. <?php if(!empty($contact['linkedin_2'])): ?>
  189. <div><?= htmlspecialcharsFix($contact['linkedin_2']) ?></div>
  190. <?php endif; ?>
  191. <?php if(!empty($contact['linkedin_3'])): ?>
  192. <div><?= htmlspecialcharsFix($contact['linkedin_3']) ?></div>
  193. <?php endif; ?>
  194. </div>
  195. <div class="facebook">
  196. <?php if(!empty($contact['facebook_1'])): ?>
  197. <div><?= htmlspecialcharsFix($contact['facebook_1']) ?></div>
  198. <?php endif; ?>
  199. <?php if(!empty($contact['facebook_2'])): ?>
  200. <div><?= htmlspecialcharsFix($contact['facebook_2']) ?></div>
  201. <?php endif; ?>
  202. <?php if(!empty($contact['facebook_3'])): ?>
  203. <div><?= htmlspecialcharsFix($contact['facebook_3']) ?></div>
  204. <?php endif; ?>
  205. </div>
  206. <div class="alibaba">
  207. <?php if(!empty($contact['alibaba_1'])): ?>
  208. <div><?= htmlspecialcharsFix($contact['alibaba_1']) ?></div>
  209. <?php endif; ?>
  210. <?php if(!empty($contact['alibaba_2'])): ?>
  211. <div><?= htmlspecialcharsFix($contact['alibaba_2']) ?></div>
  212. <?php endif; ?>
  213. <?php if(!empty($contact['alibaba_3'])): ?>
  214. <div><?= htmlspecialcharsFix($contact['alibaba_3']) ?></div>
  215. <?php endif; ?>
  216. </div>
  217. </div>
  218. <?php
  219. }
  220. } else {
  221. // 如果没有ID,则显示查询返回的基本联系信息
  222. ?>
  223. <div class="contact-block">
  224. <div class="tel"><?= htmlspecialcharsFix($row['cs_tel'] ?? '') ?></div>
  225. <div class="mail"><?= htmlspecialcharsFix($row['cs_email'] ?? '') ?></div>
  226. <div class="whatsapp"><?= htmlspecialcharsFix($row['cs_whatsapp'] ?? '') ?></div>
  227. <div class="wechat"><?= htmlspecialcharsFix($row['cs_wechat'] ?? '') ?></div>
  228. <div class="linkedin"><?= htmlspecialcharsFix($row['cs_linkedin'] ?? '') ?></div>
  229. <div class="facebook"><?= htmlspecialcharsFix($row['cs_facebook'] ?? '') ?></div>
  230. <div class="alibaba"><?= htmlspecialcharsFix($row['cs_alibaba'] ?? '') ?></div>
  231. </div>
  232. <?php
  233. }
  234. ?>
  235. </td>
  236. </tr>
  237. <?php
  238. $i++;
  239. }
  240. } else {
  241. if (empty($keywords)) {
  242. ?>
  243. <tr>
  244. <td colspan="8" align="center">暂无相关记录,可录入该客户,<a href="/customerAdd.php" class="highline">点击录入客户数据</a></td>
  245. </tr>
  246. <?php
  247. } else {
  248. ?>
  249. <tr>
  250. <td colspan="8" align="center">
  251. <a href="?">Sorry,没有找到"<?= htmlspecialcharsFix($keywords) ?>"相关的信息,点击返回</a>
  252. </td>
  253. </tr>
  254. <?php
  255. }
  256. }
  257. ?>
  258. </table>
  259. </div>
  260. </body>
  261. </html>