- 근무 설정 API (GET/PUT /settings/work) - 근무유형, 소정근로시간, 연장근로시간, 근무요일, 출퇴근시간, 휴게시간 - 출퇴근 설정 API (GET/PUT /settings/attendance) - GPS 출퇴근, 허용 반경, 본사 위치 설정 - 현장 관리 API (CRUD /sites) - 현장 등록/수정/삭제, 활성화된 현장 목록(셀렉트박스용) - GPS 좌표 기반 위치 관리 마이그레이션: work_settings, attendance_settings, sites 테이블 모델: WorkSetting, AttendanceSetting, Site (BelongsToTenant, SoftDeletes) 서비스: WorkSettingService, SiteService Swagger 문서 및 i18n 메시지 키 추가
101 lines
2.4 KiB
PHP
101 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Tenants;
|
|
|
|
use App\Traits\BelongsToTenant;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* 출퇴근 설정 모델
|
|
*
|
|
* @property int $id
|
|
* @property int $tenant_id
|
|
* @property bool $use_gps
|
|
* @property int $allowed_radius
|
|
* @property string|null $hq_address
|
|
* @property float|null $hq_latitude
|
|
* @property float|null $hq_longitude
|
|
*/
|
|
class AttendanceSetting extends Model
|
|
{
|
|
use BelongsToTenant;
|
|
|
|
protected $table = 'attendance_settings';
|
|
|
|
protected $fillable = [
|
|
'tenant_id',
|
|
'use_gps',
|
|
'allowed_radius',
|
|
'hq_address',
|
|
'hq_latitude',
|
|
'hq_longitude',
|
|
];
|
|
|
|
protected $casts = [
|
|
'use_gps' => 'boolean',
|
|
'allowed_radius' => 'integer',
|
|
'hq_latitude' => 'decimal:8',
|
|
'hq_longitude' => 'decimal:8',
|
|
];
|
|
|
|
protected $attributes = [
|
|
'use_gps' => false,
|
|
'allowed_radius' => 100,
|
|
];
|
|
|
|
// =========================================================================
|
|
// 헬퍼 메서드
|
|
// =========================================================================
|
|
|
|
/**
|
|
* GPS 설정 완료 여부
|
|
*/
|
|
public function isGpsConfigured(): bool
|
|
{
|
|
return $this->use_gps
|
|
&& $this->hq_latitude !== null
|
|
&& $this->hq_longitude !== null;
|
|
}
|
|
|
|
/**
|
|
* 좌표가 허용 범위 내인지 확인
|
|
*/
|
|
public function isWithinRadius(float $latitude, float $longitude): bool
|
|
{
|
|
if (! $this->isGpsConfigured()) {
|
|
return true; // GPS 미설정 시 항상 허용
|
|
}
|
|
|
|
$distance = $this->calculateDistance(
|
|
$this->hq_latitude,
|
|
$this->hq_longitude,
|
|
$latitude,
|
|
$longitude
|
|
);
|
|
|
|
return $distance <= $this->allowed_radius;
|
|
}
|
|
|
|
/**
|
|
* 두 좌표 간 거리 계산 (미터)
|
|
* Haversine 공식 사용
|
|
*/
|
|
private function calculateDistance(float $lat1, float $lon1, float $lat2, float $lon2): float
|
|
{
|
|
$earthRadius = 6371000; // 지구 반경 (미터)
|
|
|
|
$lat1Rad = deg2rad($lat1);
|
|
$lat2Rad = deg2rad($lat2);
|
|
$deltaLat = deg2rad($lat2 - $lat1);
|
|
$deltaLon = deg2rad($lon2 - $lon1);
|
|
|
|
$a = sin($deltaLat / 2) * sin($deltaLat / 2) +
|
|
cos($lat1Rad) * cos($lat2Rad) *
|
|
sin($deltaLon / 2) * sin($deltaLon / 2);
|
|
|
|
$c = 2 * atan2(sqrt($a), sqrt(1 - $a));
|
|
|
|
return $earthRadius * $c;
|
|
}
|
|
}
|