WaybillPriceModel.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. use App\Traits\ModelTimeFormat;
  5. use App\Traits\ModelLogChanging;
  6. class WaybillPriceModel extends Model
  7. {
  8. use ModelLogChanging;
  9. use ModelTimeFormat;
  10. protected $fillable=[
  11. 'logistic_id','province_id','city_id','unit_id','range_min','range_max','unit_price','base_fee','initial_weight'
  12. ];
  13. protected $appends=[
  14. 'carrier_name',
  15. 'province_name',
  16. 'city_name',
  17. 'unit_name',
  18. ];
  19. public function logistic(){
  20. return $this->belongsTo('App\Logistic','logistic_id','id');
  21. }
  22. public function province()
  23. { //省份
  24. return $this->belongsTo(Region::class,'province_id','id');
  25. }
  26. public function city()
  27. { //城市
  28. return $this->belongsTo(Region::class,'city_id','id');
  29. }
  30. public function unit(){
  31. return $this->belongsTo('App\Unit','unit_id','id');
  32. }
  33. public function getCarrierNameAttribute(){
  34. return $this['carrier']? $this['carrier']['name']:null;
  35. }
  36. public function getProvinceNameAttribute(){
  37. return $this['province']? $this['province']['name']:null;
  38. }
  39. public function getCityNameAttribute(){
  40. return $this['city']? $this['city']['name']:null;
  41. }
  42. public function getUnitNameAttribute(){
  43. return $this['unit']? $this['unit']['name']:null;
  44. }
  45. }