60 lines
1.3 KiB
PHP
60 lines
1.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Model;
|
||
|
|
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
|
||
|
|
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;
|
||
|
|
}
|
||
|
|
}
|