master
cody 2 months ago
parent 7a03dd90e5
commit 5b335240ee

@ -9,7 +9,7 @@ use Illuminate\Support\Facades\DB;
use Maatwebsite\Excel\Facades\Excel; use Maatwebsite\Excel\Facades\Excel;
use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\IOFactory;
class UpdateCourseUrls extends Command class UpdateCalendar extends Command
{ {
/** /**
* The name and signature of the console command. * The name and signature of the console command.
@ -398,7 +398,7 @@ class UpdateCourseUrls extends Command
try { try {
// 处理Excel数字格式的日期时间 // 处理Excel数字格式的日期时间
if (is_numeric($dateTimeString)) { if (is_numeric($dateTimeString)) {
$excelDate = (float) $dateTimeString; $excelDate = (float)$dateTimeString;
// Excel日期从1900年1月1日开始计算天数 // Excel日期从1900年1月1日开始计算天数
// 需要减去2是因为Excel错误地认为1900年是闰年 // 需要减去2是因为Excel错误地认为1900年是闰年

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

Binary file not shown.
Loading…
Cancel
Save