diff --git a/app/Console/Commands/UpdateCourseUrls.php b/app/Console/Commands/UpdateCalendar.php similarity index 99% rename from app/Console/Commands/UpdateCourseUrls.php rename to app/Console/Commands/UpdateCalendar.php index 80363c8..c5d2647 100644 --- a/app/Console/Commands/UpdateCourseUrls.php +++ b/app/Console/Commands/UpdateCalendar.php @@ -9,7 +9,7 @@ use Illuminate\Support\Facades\DB; use Maatwebsite\Excel\Facades\Excel; use PhpOffice\PhpSpreadsheet\IOFactory; -class UpdateCourseUrls extends Command +class UpdateCalendar extends Command { /** * The name and signature of the console command. @@ -398,7 +398,7 @@ class UpdateCourseUrls extends Command try { // 处理Excel数字格式的日期时间 if (is_numeric($dateTimeString)) { - $excelDate = (float) $dateTimeString; + $excelDate = (float)$dateTimeString; // Excel日期从1900年1月1日开始计算天数 // 需要减去2是因为Excel错误地认为1900年是闰年 diff --git a/app/Http/Controllers/Mobile/OtherController.php b/app/Http/Controllers/Mobile/OtherController.php index 90fc56c..86797b3 100755 --- a/app/Http/Controllers/Mobile/OtherController.php +++ b/app/Http/Controllers/Mobile/OtherController.php @@ -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); } diff --git a/课程台账.xlsx b/课程台账.xlsx index 4a2659a..b1e5186 100644 Binary files a/课程台账.xlsx and b/课程台账.xlsx differ