83 lines
2.6 KiB
PHP
83 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Business;
|
|
|
|
use App\Abstracts\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
|
|
class CourierQuoteChange extends Model
|
|
{
|
|
public const STATUS_DRAFT = 'draft';
|
|
public const STATUS_PENDING_REVIEW = 'pending_review';
|
|
public const STATUS_RETURNED = 'returned';
|
|
public const STATUS_APPROVED = 'approved';
|
|
|
|
public const RECALCULATION_NOT_REQUIRED = 'not_required';
|
|
public const RECALCULATION_PENDING = 'pending';
|
|
public const RECALCULATION_BLOCKED = 'blocked';
|
|
|
|
protected $table = 'business_courier_quote_changes';
|
|
|
|
protected $fillable = [
|
|
'company_id', 'number', 'source_quote_id', 'source_sheet_name', 'carrier_name', 'quote_type',
|
|
'change_type', 'status', 'effective_date', 'is_retrospective', 'recalculation_status',
|
|
'recalculation_note', 'summary', 'created_by', 'submitted_by', 'submitted_at', 'approved_by',
|
|
'approved_at', 'new_quote_version_id',
|
|
];
|
|
|
|
protected $casts = [
|
|
'company_id' => 'integer',
|
|
'effective_date' => 'date',
|
|
'is_retrospective' => 'boolean',
|
|
'submitted_at' => 'datetime',
|
|
'approved_at' => 'datetime',
|
|
];
|
|
|
|
public function items(): HasMany
|
|
{
|
|
return $this->hasMany(CourierQuoteChangeItem::class, 'quote_change_id')->orderBy('position');
|
|
}
|
|
|
|
public function events(): HasMany
|
|
{
|
|
return $this->hasMany(CourierQuoteChangeEvent::class, 'quote_change_id')->orderBy('created_at');
|
|
}
|
|
|
|
public function version(): HasOne
|
|
{
|
|
return $this->hasOne(CourierQuoteVersion::class, 'source_change_id');
|
|
}
|
|
|
|
public function isEditable(): bool
|
|
{
|
|
return in_array($this->status, [self::STATUS_DRAFT, self::STATUS_RETURNED], true);
|
|
}
|
|
|
|
public function isRetrospective(): bool
|
|
{
|
|
return (bool) $this->is_retrospective;
|
|
}
|
|
|
|
public function recalculationStatusLabel(): string
|
|
{
|
|
return match ($this->recalculation_status) {
|
|
self::RECALCULATION_NOT_REQUIRED => '无需追溯',
|
|
self::RECALCULATION_PENDING => '待追溯核算',
|
|
self::RECALCULATION_BLOCKED => '核算受阻',
|
|
default => $this->recalculation_status,
|
|
};
|
|
}
|
|
|
|
public function statusLabel(): string
|
|
{
|
|
return match ($this->status) {
|
|
self::STATUS_DRAFT => '草稿',
|
|
self::STATUS_PENDING_REVIEW => '待审核',
|
|
self::STATUS_RETURNED => '已退回',
|
|
self::STATUS_APPROVED => '已审核',
|
|
default => $this->status,
|
|
};
|
|
}
|
|
}
|