$city_code, 'status' => \E_BASE_STATUS::Normal, ]; if ($county_code) { $where["county_code"] = $county_code; } $subQuery = $this->field("*,round(st_distance_sphere (point($lng_lat[0],$lng_lat[1]),point ( `lng`, `lat` ))) distance") ->where($where) ->where("lng IS NOT NULL") ->where("lat IS NOT NULL"); if ($search_text) $subQuery->where("name", "like", "%$search_text%"); $query = $this->table($subQuery->buildSql() . ' distance') ->where($where) ->where("lng IS NOT NULL") ->where("lat IS NOT NULL"); if ($search_text) $query->where("name", "like", "%$search_text%"); if ($hot) $query->where('hot', 1); return $query ->order('distance', 'ASC') ->page($page) ->paginate($size); } }