CaiWuXiTong/app/Models/Business/CourierQuoteVersion.php
limeng 9a25db91cc feat(报价管理): 存量报价整本批量录入及签署原图归档 (#346)
保留各家工作表报价原文、公式、独立执行日期及签署原件;审核后按执行日期管理版本。33项测试、336项断言通过。生产业务迁移已获明确授权,服务器私有备份已完成并逐条校验。
2026-10-16 14:56:44 +08:00

74 lines
2.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Models\Business;
use App\Abstracts\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasOne;
class CourierQuoteVersion extends Model
{
protected $table = 'business_courier_quote_versions';
protected $fillable = [
'company_id', 'version_code', 'source_quote_id', 'source_change_id', 'sheet_name', 'company_name',
'carrier_name', 'courier_expcode', 'billing_rules', 'quote_type', 'effective_date', 'end_date', 'source_range', 'values_json', 'formulas_json',
'status', 'signature_status', 'created_by', 'approved_by', 'void_reason', 'voided_at', 'voided_by',
];
public const STATUS_APPROVED = 'approved';
/** 发错作废:不再参与生效判断,原件和回签单保留。 */
public const STATUS_VOIDED = 'voided';
protected $casts = [
'company_id' => 'integer',
'effective_date' => 'date',
'end_date' => 'date',
'voided_at' => 'datetime',
];
/** 短期(临时)变价:有结束日期,到期后回到原来的长期报价。 */
public function isTemporary(): bool
{
return $this->end_date !== null;
}
/** 某一天是否在这一版的执行期间内(开始 ≤ 日期 ≤ 结束;长期版本没有结束)。 */
public function coversDate(\DateTimeInterface $date): bool
{
$day = \Illuminate\Support\Carbon::instance($date)->startOfDay();
return $this->effective_date !== null
&& $this->effective_date->lte($day)
&& ($this->end_date === null || $this->end_date->gte($day));
}
/** 执行期间文字,如「2026-10-12 至 2026-10-15(临时)」或「2026-10-01 起」。 */
public function periodLabel(): string
{
if ($this->effective_date === null) {
return '-';
}
return $this->end_date !== null
? $this->effective_date->toDateString() . ' 至 ' . $this->end_date->toDateString() . '(临时)'
: $this->effective_date->toDateString() . ' 起';
}
public function isVoided(): bool
{
return $this->status === self::STATUS_VOIDED;
}
public function change(): BelongsTo
{
return $this->belongsTo(CourierQuoteChange::class, 'source_change_id');
}
public function signature(): HasOne
{
return $this->hasOne(CourierQuoteSignature::class, 'quote_version_id');
}
}