Files
x-server-mobile/backend/app/model/BusinessTripItinerary.php
T
root 66b61eada4 refactor: 使用官方support\Db和support\Model
- 创建 support/Db.php 和 support/Model.php
- 在 bootstrap.php 中自动初始化数据库
- 移除 app/util/Db.php
- 更新所有模型和控制器使用官方类

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 18:15:17 +08:00

60 lines
1.3 KiB
PHP

<?php
namespace app\model;
use support\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;
}
}