value, TechnicianLocationType::COMMON->value]), $code, $message ); } /** * 验证经纬度 * 检查经纬度的有效性 * * @param float $latitude 纬度 * @param float $longitude 经度 * @param int $code HTTP状态码 * @param string $latMessage 纬度错误消息 * @param string $lngMessage 经度错误消息 * @throws \Exception 当经纬度无效时抛出异常 */ protected function validateCoordinates( $latitude, $longitude, int $code = 422, string $latMessage = '无效的纬度坐标', string $lngMessage = '无效的经度坐标' ): void { // 验证纬度 (-90° to 90°) abort_if( !is_numeric($latitude) || !($latitude >= -90 && $latitude <= 90), $code, $latMessage ); // 验证经度 (-180° to 180°) abort_if( !is_numeric($longitude) || !($longitude >= -180 && $longitude <= 180), $code, $lngMessage ); } /** * 获取有效的位置类型列表 * * @return array 位置类型列表 */ protected function getValidLocationTypes(): array { return [ TechnicianLocationType::CURRENT->value, TechnicianLocationType::COMMON->value ]; } /** * 检查是否为有效的位置类型 * * @param int|null $type 位置类型 * @return bool */ protected function isValidLocationType(?int $type): bool { return in_array($type, $this->getValidLocationTypes()); } }