|
|
|
@ -132,14 +132,14 @@ class OtherController extends CommonController
|
|
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$longitude = $all['company_longitude'];
|
|
|
|
|
$latitude = $all['company_latitude'];
|
|
|
|
|
$pageSize = $all['page_size'] ?? 10;
|
|
|
|
|
$page = $all['page'] ?? 1;
|
|
|
|
|
$longitude = floatval($all['company_longitude']);
|
|
|
|
|
$latitude = floatval($all['company_latitude']);
|
|
|
|
|
$pageSize = intval($all['page_size'] ?? 10);
|
|
|
|
|
$page = intval($all['page'] ?? 1);
|
|
|
|
|
$sortName = $all['sort_name'] ?? 'distance';
|
|
|
|
|
$sortType = $all['sort_type'] ?? 'asc';
|
|
|
|
|
|
|
|
|
|
// 使用 Haversine 公式计算距离
|
|
|
|
|
// 使用 Haversine 公式计算距离,确保经纬度数据有效
|
|
|
|
|
$distanceFormula = "
|
|
|
|
|
(6371 * acos(
|
|
|
|
|
cos(radians(?)) *
|
|
|
|
@ -150,16 +150,21 @@ class OtherController extends CommonController
|
|
|
|
|
)) AS distance
|
|
|
|
|
";
|
|
|
|
|
|
|
|
|
|
$query = Company::select('*')
|
|
|
|
|
$query = Company::with('users')->select('*')
|
|
|
|
|
->selectRaw($distanceFormula, [$latitude, $longitude, $latitude])
|
|
|
|
|
->whereNotNull('company_longitude')
|
|
|
|
|
->whereNotNull('company_latitude')
|
|
|
|
|
->where('company_longitude', '!=', '')
|
|
|
|
|
->where('company_latitude', '!=', '');
|
|
|
|
|
->where('company_latitude', '!=', '')
|
|
|
|
|
->whereRaw('company_longitude REGEXP \'^-?[0-9]+\.?[0-9]*$\'')
|
|
|
|
|
->whereRaw('company_latitude REGEXP \'^-?[0-9]+\.?[0-9]*$\'')
|
|
|
|
|
->whereRaw('CAST(company_longitude AS DECIMAL(10,8)) BETWEEN -180 AND 180')
|
|
|
|
|
->whereRaw('CAST(company_latitude AS DECIMAL(10,8)) BETWEEN -90 AND 90');
|
|
|
|
|
|
|
|
|
|
// 根据排序字段进行排序
|
|
|
|
|
if ($sortName === 'distance') {
|
|
|
|
|
$query->orderBy('distance', $sortType);
|
|
|
|
|
// 距离排序始终按升序(从近到远)
|
|
|
|
|
$query->orderBy('distance', 'asc');
|
|
|
|
|
} else {
|
|
|
|
|
$query->orderBy($sortName, $sortType);
|
|
|
|
|
}
|
|
|
|
|