Waybill.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. use App\Traits\ModelTimeFormat;
  5. class Waybill extends Model
  6. {
  7. use ModelTimeFormat;
  8. protected $fillable=[
  9. 'status','type','waybill_number','owner_id','wms_bill_number','origination','destination','recipient','recipient_mobile','charge','ordering_remark',
  10. 'carrier_id','carrier_bill','origination_city_id','destination_city_id','warehouse_weight','warehouse_weight_unit_id','carrier_weight','carrier_weight_unit_id','carType_id',
  11. 'car_owner_info','fee','pick_up_fee','other_fee','collect_fee','dispatch_remark','waybill_price_model_id','warehouse_weight_other','warehouse_weight_unit_id_other'
  12. ,'carrier_weight_other','carrier_weight_unit_id_other','source_bill','mileage','amount','inquire_tel',
  13. ];
  14. protected $appends=[
  15. 'origination_city_name',
  16. 'carrier_name',
  17. 'owner_name',
  18. 'destination_city_name',
  19. 'warehouse_weight_unit_name',
  20. 'carrier_weight_unit_name',
  21. 'warehouse_weight_unit_other_name',
  22. 'carrier_weight_unit_other_name',
  23. 'upload_file_url',
  24. 'upload_file_type',
  25. ];
  26. public function owner(){
  27. return $this->belongsTo('App\Owner','owner_id','id');
  28. }
  29. public function carrier(){
  30. return $this->belongsTo('App\Carrier','carrier_id','id');
  31. }
  32. public function origination_city(){
  33. return $this->belongsTo('App\City','origination_city_id','id');
  34. }
  35. public function destination_city(){
  36. return $this->belongsTo('App\City','destination_city_id','id');
  37. }
  38. public function wmsCommodities(){
  39. return $this->hasMany('App\WMSWaybillOrder','OrderNo','wms_bill_number');
  40. }
  41. public function warehouse_weight_unit(){
  42. return $this->belongsTo('App\Unit','warehouse_weight_unit_id','id');
  43. }
  44. public function carrier_weight_unit(){
  45. return $this->belongsTo('App\Unit','carrier_weight_unit_id','id');
  46. }
  47. public function warehouse_weight_unit_other(){
  48. return $this->belongsTo('App\Unit','warehouse_weight_unit_id_other','id');
  49. }
  50. public function carrier_weight_unit_other(){
  51. return $this->belongsTo('App\Unit','carrier_weight_unit_id_other','id');
  52. }
  53. public function carType(){
  54. return $this->belongsTo('App\CarType','carType_id','id');
  55. }
  56. public function waybillAuditLogs(){
  57. return $this->hasMany('App\WaybillAuditLog','waybill_id','id');
  58. }
  59. public function uploadFile(){
  60. return $this->hasOne('App\UploadFile','table_id','id')->where('table_name','waybills');
  61. }
  62. public function getUploadFileUrlAttribute(){
  63. return $this['uploadFile']? asset('/storage'.$this['uploadFile']['url']):null;
  64. }
  65. public function getUploadFileTypeAttribute(){
  66. return $this['uploadFile']? $this['uploadFile']['type']:null;
  67. }
  68. public function getOwnerNameAttribute(){
  69. return $this['owner']? $this['owner']['name']:null;
  70. }
  71. public function getCarrierNameAttribute(){
  72. return $this['carrier']? $this['carrier']['name']:null;
  73. }
  74. public function getOriginationCityNameAttribute(){
  75. return $this['origination_city']? $this['origination_city']['name']:null;
  76. }
  77. public function getDestinationCityNameAttribute(){
  78. return $this['destination_city']? $this['destination_city']['name']:null;
  79. }
  80. public function getWarehouseWeightUnitNameAttribute(){
  81. return $this['warehouse_weight_unit']? $this['warehouse_weight_unit']['name']:null;
  82. }
  83. public function getCarrierWeightUnitNameAttribute(){
  84. return $this['carrier_weight_unit']? $this['carrier_weight_unit']['name']:null;
  85. }
  86. public function getWarehouseWeightUnitOtherNameAttribute(){
  87. return $this['warehouse_weight_unit_other']? $this['warehouse_weight_unit_other']['name']:null;
  88. }
  89. public function getCarrierWeightUnitOtherNameAttribute(){
  90. return $this['carrier_weight_unit_other']? $this['carrier_weight_unit_other']['name']:null;
  91. }
  92. }