1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace App\Traits;
- use App\Enums\TechnicianLocationType;
- trait LocationValidationTrait
- {
-
- protected function validateLocationType(?int $type, int $code = 422, string $message = '无效的位置类型'): void
- {
- abort_if(
- !in_array($type, [TechnicianLocationType::CURRENT->value, TechnicianLocationType::COMMON->value]),
- $code,
- $message
- );
- }
-
- protected function validateCoordinates(
- $latitude,
- $longitude,
- int $code = 422,
- string $latMessage = '无效的纬度坐标',
- string $lngMessage = '无效的经度坐标'
- ): void {
-
- abort_if(
- !is_numeric($latitude) || !($latitude >= -90 && $latitude <= 90),
- $code,
- $latMessage
- );
-
- abort_if(
- !is_numeric($longitude) || !($longitude >= -180 && $longitude <= 180),
- $code,
- $lngMessage
- );
- }
-
- protected function getValidLocationTypes(): array
- {
- return [
- TechnicianLocationType::CURRENT->value,
- TechnicianLocationType::COMMON->value
- ];
- }
-
- protected function isValidLocationType(?int $type): bool
- {
- return in_array($type, $this->getValidLocationTypes());
- }
- }
|