Waybill.php 4.3 KB

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