CaiWuXiTong/app/Models/Business/CourierStockQuoteEntry.php

39 lines
1.3 KiB
PHP

<?php
namespace App\Models\Business;
use App\Abstracts\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class CourierStockQuoteEntry extends Model
{
protected $table = 'business_courier_stock_quote_entries';
protected $fillable = [
'company_id', 'courier_expcode', 'courier_name', 'courier_name_key', 'quote_type', 'source_change_id',
'sheet_name', 'source_range', 'values_json', 'formulas_json', 'files', 'created_by',
];
protected $casts = ['company_id' => 'integer', 'files' => 'array'];
public function change(): BelongsTo
{
return $this->belongsTo(CourierQuoteChange::class, 'source_change_id');
}
public function sourceQuote(): array
{
return [
'id' => 'STOCK-' . $this->id,
'courier_expcode' => $this->courier_expcode,
'billing_rules' => data_get($this->change?->quote_payload, 'billing_rules'),
'company_name' => $this->courier_name,
'sheet_name' => $this->sheet_name,
'quote_type' => $this->quote_type,
'source_range' => $this->source_range,
'values' => json_decode($this->values_json, true, 512, JSON_THROW_ON_ERROR),
'formulas' => json_decode($this->formulas_json, true, 512, JSON_THROW_ON_ERROR),
];
}
}