diff --git a/app/Models/Company.php b/app/Models/Company.php index eb076ae..778e43a 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -71,10 +71,32 @@ class Company extends SoftDeletesModel $hasSuzhouOut = in_array('苏州市外', $company_area); if ($hasSuzhouOut) { - // 如果包含"苏州市外",查询所有不等于"苏州"的记录 - return $query->where('company_area', '!=', '苏州') - ->whereNotNull('company_area') - ->where('company_area', '!=', ''); + // 苏州市外:排除 company_area 参数接口返回的苏州市内选项,以及虎丘区 + $excludeAreas = Parameter::where('number', 'company_area') + ->with(['detail' => fn ($q) => $q->orderBy('sort', 'asc')]) + ->first(); + $excludeList = []; + if ($excludeAreas && $excludeAreas->detail) { + foreach ($excludeAreas->detail as $d) { + $v = trim((string) ($d->value ?? '')); + if ($v !== '' && $v !== '苏州市外') { + $excludeList[] = $v; + // 高新区映射为虎丘(数据库可能存虎丘) + if ($v === '高新区') { + $excludeList[] = '虎丘'; + } + } + } + } + $excludeList = array_unique(array_merge($excludeList, ['虎丘区'])); + + $query->whereNotNull('company_area')->where('company_area', '!=', ''); + if (!empty($excludeList)) { + foreach ($excludeList as $v) { + $query->where('company_area', 'not like', '%' . $v . '%'); + } + } + return $query; } else { // 将搜索参数转换为数据库值 $company_area = array_map(function ($v) use ($areaMapping) {