Files
zyt/server/app/common/model/ExpressTracking.php
2026-04-07 18:13:03 +08:00

102 lines
2.9 KiB
PHP

<?php
declare(strict_types=1);
namespace app\common\model;
use think\model\concern\SoftDelete;
/**
* 物流追踪模型
*/
class ExpressTracking extends BaseModel
{
use SoftDelete;
protected $name = 'express_tracking';
protected $deleteTime = 'delete_time';
// 物流状态常量
public const STATE_IN_TRANSIT = '0'; // 在途
public const STATE_COLLECTED = '1'; // 揽收
public const STATE_PROBLEM = '2'; // 疑难
public const STATE_SIGNED = '3'; // 签收
public const STATE_RETURN_SIGNED = '4'; // 退签
public const STATE_DELIVERING = '5'; // 派件
public const STATE_RETURNING = '6'; // 退回
public const STATE_FORWARDING = '7'; // 转投
public const STATE_CUSTOMS = '8'; // 清关
public const STATE_WAIT_CUSTOMS = '10'; // 待清关
public const STATE_IN_CUSTOMS = '11'; // 清关中
public const STATE_CUSTOMS_DONE = '12'; // 已清关
public const STATE_CUSTOMS_ERROR = '13'; // 清关异常
public const STATE_REJECTED = '14'; // 拒签
/**
* 获取状态文本
*/
public static function getStateText(string $state): string
{
$map = [
self::STATE_IN_TRANSIT => '在途',
self::STATE_COLLECTED => '揽收',
self::STATE_PROBLEM => '疑难',
self::STATE_SIGNED => '已签收',
self::STATE_RETURN_SIGNED => '退签',
self::STATE_DELIVERING => '派件中',
self::STATE_RETURNING => '退回',
self::STATE_FORWARDING => '转投',
self::STATE_CUSTOMS => '清关',
self::STATE_WAIT_CUSTOMS => '待清关',
self::STATE_IN_CUSTOMS => '清关中',
self::STATE_CUSTOMS_DONE => '已清关',
self::STATE_CUSTOMS_ERROR => '清关异常',
self::STATE_REJECTED => '拒签',
];
return $map[$state] ?? '未知';
}
/**
* 是否为终态(不再需要更新)
*/
public static function isFinalState(string $state): bool
{
return in_array($state, [
self::STATE_SIGNED,
self::STATE_RETURN_SIGNED,
self::STATE_REJECTED,
], true);
}
/**
* 是否为异常状态
*/
public static function isProblemState(string $state): bool
{
return in_array($state, [
self::STATE_PROBLEM,
self::STATE_CUSTOMS_ERROR,
self::STATE_REJECTED,
], true);
}
/**
* 关联轨迹明细
*/
public function traces()
{
return $this->hasMany(ExpressTrace::class, 'tracking_id', 'id')
->order('trace_time_stamp', 'desc');
}
/**
* 关联状态变更记录
*/
public function stateLogs()
{
return $this->hasMany(ExpressStateLog::class, 'tracking_id', 'id')
->order('change_time', 'desc');
}
}