get_customer_search.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. require_once 'conn.php';
  3. checkLogin();
  4. header('Content-Type: application/json');
  5. // 如果请求中包含搜索参数
  6. if (isset($_GET['search'])) {
  7. $search = mysqli_real_escape_string($conn, $_GET['search']);
  8. $employee_id = $_SESSION['employee_id'];
  9. // 构建SQL查询,搜索用户所属的客户,可以匹配客户编码或客户名称
  10. $sql = "SELECT id, cs_company, cs_code
  11. FROM customer
  12. WHERE cs_belong = $employee_id
  13. AND (cs_company LIKE '%$search%' OR cs_code LIKE '%$search%')
  14. ORDER BY cs_company
  15. LIMIT 15"; // 限制返回结果数量
  16. $result = mysqli_query($conn, $sql);
  17. $customers = [];
  18. while ($row = mysqli_fetch_assoc($result)) {
  19. $customers[] = [
  20. 'id' => $row['id'],
  21. 'cs_company' => htmlspecialcharsAjaxFix($row['cs_company']),
  22. 'cs_code' => htmlspecialcharsAjaxFix($row['cs_code'])
  23. ];
  24. }
  25. echo json_encode(['customers' => $customers]);
  26. exit;
  27. }
  28. // 如果没有任何有效请求,返回空结果
  29. echo json_encode(['customers' => []]);
  30. ?>