?"; $params[] = $fVal; break; case 'starts_with': $filterConds[] = "$fField LIKE ?"; $params[] = "$fVal%"; break; case 'ends_with': $filterConds[] = "$fField LIKE ?"; $params[] = "%$fVal"; break; case 'gt': $filterConds[] = "$fField > ?"; $params[] = $fVal; break; case 'lt': $filterConds[] = "$fField < ?"; $params[] = $fVal; break; case 'gte': $filterConds[] = "$fField >= ?"; $params[] = $fVal; break; case 'lte': $filterConds[] = "$fField <= ?"; $params[] = $fVal; break; case 'is_empty': $filterConds[] = "($fField IS NULL OR $fField = '')"; break; case 'is_not_empty': $filterConds[] = "($fField IS NOT NULL AND $fField <> '')"; break; default: break; } } } } if ($filterConds) { $where[] = '(' . implode(" $filterLogic ", $filterConds) . ')'; } if ($keyword !== '') { if ($field !== '' && in_array($field, $searchableFields, true)) { $where[] = "$field LIKE ?"; $params[] = "%$keyword%"; } else { // 全部字段:匹配常用字段 $where[] = '(name_zh LIKE ? OR display_name LIKE ? OR registration_number LIKE ? OR legal_representative LIKE ? OR industry LIKE ? OR industry_subdivision LIKE ? OR website LIKE ? OR source_detail LIKE ? OR stock_code LIKE ?)'; $like = "%$keyword%"; array_push($params, $like, $like, $like, $like, $like, $like, $like, $like, $like, $like); } } if ($industry !== '') { $where[] = 'industry = ?'; $params[] = $industry; } if ($companyType !== '') { $where[] = 'legal_form = ?'; $params[] = $companyType; } $whereSql = implode(' AND ', $where); $pdo = DB::getInstance()->getPdo(); $stmt = $pdo->prepare("SELECT COUNT(*) FROM companies WHERE $whereSql"); $stmt->execute($params); $total = (int)$stmt->fetchColumn(); $offset = ($page - 1) * $limit; $stmt = $pdo->prepare( "SELECT id, name_zh, display_name, business_role, legal_form, country, registration_number, address, legal_representative, industry, industry_subdivision, website, latest_employee_count, latest_annual_revenue, is_listed, stock_code, source_channel, source_detail, is_active, created_at, updated_at FROM companies WHERE $whereSql ORDER BY id DESC LIMIT $limit OFFSET $offset" ); $stmt->execute($params); $list = $stmt->fetchAll(); Response::success(['list' => $list, 'total' => $total, 'page' => $page, 'limit' => $limit]);