<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

use App\Traits\ModelLogChanging;

class OwnerPriceDirectLogistic extends Model
{
    use ModelLogChanging;

    protected $fillable = [
        "name",     //名称
        "base_km",  //起步公里数
        "operation",//操作
        "target_id",//目标ID
        "tax_rate_id",//税率
    ];

    public function details()
    {   //直发车计费对应车型费
        return $this->hasMany(OwnerPriceDirectLogisticCar::class,"owner_price_direct_logistic_id","id");
    }
    public function owners()
    {   //货主中间表
        return $this->belongsToMany(Owner::class,"owner_price_direct_logistic_owner","owner_price_direct_logistic_id","owner_id");
    }
    public function taxRate()
    {   //税率
        return $this->belongsTo(TaxRate::class);
    }

    public function getOwnerIdAttribute()
    {   //获取货主ID数组
        return array_column(DB::select(DB::raw("SELECT * FROM owner_price_direct_logistic_owner WHERE owner_price_direct_logistic_id = ?"),[$this->id]),"owner_id");
    }
}
