<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use App\Traits\ModelTimeFormat;

use App\Traits\ModelLogChanging;

class WaybillPriceModel extends Model
{
    use ModelLogChanging;

    use ModelTimeFormat;

    protected $fillable=[
        'logistic_id','province_id','city_id','unit_id','range_min','range_max','unit_price','base_fee','initial_weight'
    ];

    protected $appends=[
        'carrier_name',
        'province_name',
        'city_name',
        'unit_name',
    ];

    public function logistic(){
        return $this->belongsTo('App\Logistic','logistic_id','id');
    }

    public  function province()
    {   //省份
        return $this->belongsTo(Region::class,'province_id','id');
    }

    public  function city()
    {   //城市
        return $this->belongsTo(Region::class,'city_id','id');
    }

    public function unit(){
        return $this->belongsTo('App\Unit','unit_id','id');
    }

    public function getCarrierNameAttribute(){
        return $this['carrier']? $this['carrier']['name']:null;
    }
    public function getProvinceNameAttribute(){
        return $this['province']? $this['province']['name']:null;
    }
    public function getCityNameAttribute(){
        return $this['city']? $this['city']['name']:null;
    }
    public function getUnitNameAttribute(){
        return $this['unit']? $this['unit']['name']:null;
    }
}
