OwnerPriceDirectLogistic.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Support\Facades\DB;
  5. use App\Traits\ModelLogChanging;
  6. class OwnerPriceDirectLogistic extends Model
  7. {
  8. use ModelLogChanging;
  9. protected $fillable = [
  10. "name", //名称
  11. "base_km", //起步公里数
  12. "operation",//操作
  13. "target_id",//目标ID
  14. "tax_rate_id",//税率
  15. ];
  16. public function details()
  17. { //直发车计费对应车型费
  18. return $this->hasMany(OwnerPriceDirectLogisticCar::class,"owner_price_direct_logistic_id","id");
  19. }
  20. public function owners()
  21. { //货主中间表
  22. return $this->belongsToMany(Owner::class,"owner_price_direct_logistic_owner","owner_price_direct_logistic_id","owner_id");
  23. }
  24. public function taxRate()
  25. { //税率
  26. return $this->belongsTo(TaxRate::class);
  27. }
  28. public function getOwnerIdAttribute()
  29. { //获取货主ID数组
  30. return array_column(DB::select(DB::raw("SELECT * FROM owner_price_direct_logistic_owner WHERE owner_price_direct_logistic_id = ?"),[$this->id]),"owner_id");
  31. }
  32. }