|
@@ -0,0 +1,37 @@
|
|
|
+<?php
|
|
|
+require_once 'conn.php';
|
|
|
+checkLogin();
|
|
|
+
|
|
|
+header('Content-Type: application/json');
|
|
|
+
|
|
|
+// 如果请求中包含搜索参数
|
|
|
+if (isset($_GET['search'])) {
|
|
|
+ $search = mysqli_real_escape_string($conn, $_GET['search']);
|
|
|
+ $employee_id = $_SESSION['employee_id'];
|
|
|
+
|
|
|
+ // 构建SQL查询,搜索用户所属的客户,可以匹配客户编码或客户名称
|
|
|
+ $sql = "SELECT id, cs_company, cs_code
|
|
|
+ FROM customer
|
|
|
+ WHERE cs_belong = $employee_id
|
|
|
+ AND (cs_company LIKE '%$search%' OR cs_code LIKE '%$search%')
|
|
|
+ ORDER BY cs_company
|
|
|
+ LIMIT 15"; // 限制返回结果数量
|
|
|
+
|
|
|
+ $result = mysqli_query($conn, $sql);
|
|
|
+
|
|
|
+ $customers = [];
|
|
|
+ while ($row = mysqli_fetch_assoc($result)) {
|
|
|
+ $customers[] = [
|
|
|
+ 'id' => $row['id'],
|
|
|
+ 'cs_company' => htmlspecialcharsFix($row['cs_company']),
|
|
|
+ 'cs_code' => htmlspecialcharsFix($row['cs_code'])
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ echo json_encode(['customers' => $customers]);
|
|
|
+ exit;
|
|
|
+}
|
|
|
+
|
|
|
+// 如果没有任何有效请求,返回空结果
|
|
|
+echo json_encode(['customers' => []]);
|
|
|
+?>
|