2026-02-25 15:22:12 +08:00
|
|
|
<?php
|
|
|
|
|
|
2026-02-25 18:09:04 +08:00
|
|
|
namespace app\model;
|
2026-02-25 15:22:12 +08:00
|
|
|
|
2026-02-25 18:15:17 +08:00
|
|
|
use support\Model;
|
2026-02-25 15:22:12 +08:00
|
|
|
|
|
|
|
|
class BusinessTripItinerary extends Model
|
|
|
|
|
{
|
|
|
|
|
protected $table = 'business_trip_itinerary';
|
|
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'business_trip_id',
|
|
|
|
|
'start_time',
|
|
|
|
|
'end_time',
|
|
|
|
|
'departure',
|
|
|
|
|
'destination',
|
|
|
|
|
'transport',
|
|
|
|
|
'trip_type',
|
|
|
|
|
'remark',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'business_trip_id' => 'integer',
|
|
|
|
|
'start_time' => 'datetime',
|
|
|
|
|
'end_time' => 'datetime',
|
|
|
|
|
'created_at' => 'datetime',
|
|
|
|
|
'updated_at' => 'datetime',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 行程类型常量
|
|
|
|
|
*/
|
|
|
|
|
const TRIP_TYPE_ONEWAY = 'oneway'; // 单程
|
|
|
|
|
const TRIP_TYPE_ROUNDTRIP = 'roundtrip'; // 往返
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 关联出差申请
|
|
|
|
|
*/
|
|
|
|
|
public function businessTrip()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(BusinessTrip::class, 'business_trip_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 计算天数
|
|
|
|
|
*/
|
|
|
|
|
public function getDurationDays(): int
|
|
|
|
|
{
|
|
|
|
|
if (!$this->start_time || !$this->end_time) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
$start = \DateTime::createFromFormat('Y-m-d H:i:s', $this->start_time);
|
|
|
|
|
$end = \DateTime::createFromFormat('Y-m-d H:i:s', $this->end_time);
|
|
|
|
|
if (!$start || !$end) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return $end->diff($start)->days + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|