'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; } }