|
|
|
|
@ -140,24 +140,27 @@ class OtherController extends CommonController
|
|
|
|
|
$sortName = $all['sort_name'] ?? 'distance';
|
|
|
|
|
$sortType = $all['sort_type'] ?? 'asc';
|
|
|
|
|
|
|
|
|
|
// 使用标准的 Haversine 公式计算距离
|
|
|
|
|
// 使用更稳定的距离计算公式
|
|
|
|
|
$distanceFormula = "
|
|
|
|
|
(6371 * acos(
|
|
|
|
|
cos(radians(?)) *
|
|
|
|
|
cos(radians(CAST(company_latitude AS DECIMAL(10,8)))) *
|
|
|
|
|
cos(radians(CAST(company_longitude AS DECIMAL(10,8))) - radians(?)) +
|
|
|
|
|
sin(radians(?)) *
|
|
|
|
|
sin(radians(CAST(company_latitude AS DECIMAL(10,8))))
|
|
|
|
|
(6371 * 2 * asin(
|
|
|
|
|
sqrt(
|
|
|
|
|
pow(sin(radians((CAST(company_latitude AS DECIMAL(10,8)) - ?) / 2)), 2) +
|
|
|
|
|
cos(radians(?)) * cos(radians(CAST(company_latitude AS DECIMAL(10,8)))) *
|
|
|
|
|
pow(sin(radians((CAST(company_longitude AS DECIMAL(10,8)) - ?) / 2)), 2)
|
|
|
|
|
)
|
|
|
|
|
)) AS distance
|
|
|
|
|
";
|
|
|
|
|
|
|
|
|
|
$query = Company::with('users')
|
|
|
|
|
->whereHas('users', function ($query) {
|
|
|
|
|
$query->where('is_schoolmate', 1)->with(['courseSigns' => function ($query) {
|
|
|
|
|
$query->with('course.typeDetail')->orderBy('fee_status', 'desc');
|
|
|
|
|
}]);
|
|
|
|
|
})->select('*')
|
|
|
|
|
->selectRaw($distanceFormula, [$latitude, $longitude, $latitude])
|
|
|
|
|
$query->where('is_schoolmate', 1)->with([
|
|
|
|
|
'courseSigns' => function ($query) {
|
|
|
|
|
$query->with('course')->orderBy('fee_status', 'desc');
|
|
|
|
|
}
|
|
|
|
|
]);
|
|
|
|
|
})
|
|
|
|
|
->select('*')
|
|
|
|
|
->selectRaw($distanceFormula, [$latitude, $latitude, $longitude])
|
|
|
|
|
->where(function ($query) use ($all) {
|
|
|
|
|
if (isset($all['company_name'])) {
|
|
|
|
|
$query->where('company_name', 'like', '%' . $all['company_name'] . '%');
|
|
|
|
|
|