post(); $this->validate(request(), [ 'latitude' => 'numeric', 'longitude' => 'numeric', 'city_id' => 'integer', 'schedule_type' => 'integer', 'city_name' => 'max:50', ]); $user = $this->user; $schedule_type = !empty($req['schedule_type']) ? $req['schedule_type'] : 0; $distance_field = get_user_distance_field($user); $builder = Organization::with('docter')->select(['id', 'type', 'name', 'province_id', 'city_id', 'area_id', 'address', 'latitude', 'longitude','nurse_notice','vaccine_notice', DB::raw($distance_field)]); if (in_array($schedule_type, [2,3])) { $organization_ids = Schedule::where('schedule_type', $schedule_type)->where('schedule_day', '>=', date('Ymd'))->pluck('organization_id')->toArray(); $builder->whereIn('id', $organization_ids); } if (!empty($req['city_id'])) { $builder->where('city_id', $req['city_id']); } if (!empty($req['city_name'])) { $city_name = str_replace('市', '', $req['city_name']); $city_id = Area::where('name', 'like', $city_name.'%')->where('level', 2)->value('id'); $city_id = !empty($city_id) ? $city_id : ''; $builder->where('city_id', $city_id); } $data = $builder->orderBy('distance', 'asc')->paginate(); return out($data); } public function organizationCityList() { $city_ids = Organization::pluck('city_id')->toArray(); $data = Area::select(['id', 'name'])->whereIn('id', $city_ids)->get(); return out($data); } }