Waybill.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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','amount_unit_id','other_charge','other_charge_remark','deliver_at'
  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. 'amount_unit_name',
  26. 'upload_file_url',
  27. 'upload_file_type',
  28. 'destination_province_name'
  29. ];
  30. public function owner(){
  31. return $this->belongsTo('App\Owner','owner_id','id');
  32. }
  33. public function carrier(){
  34. return $this->belongsTo('App\Carrier','carrier_id','id');
  35. }
  36. public function origination_city(){
  37. return $this->belongsTo('App\City','origination_city_id','id');
  38. }
  39. public function destination_city(){
  40. return $this->belongsTo('App\City','destination_city_id','id');
  41. }
  42. public function wmsCommodities(){
  43. return $this->hasMany('App\WMSWaybillOrder','OrderNo','wms_bill_number');
  44. }
  45. public function warehouse_weight_unit(){
  46. return $this->belongsTo('App\Unit','warehouse_weight_unit_id','id');
  47. }
  48. public function carrier_weight_unit(){
  49. return $this->belongsTo('App\Unit','carrier_weight_unit_id','id');
  50. }
  51. public function warehouse_weight_unit_other(){
  52. return $this->belongsTo('App\Unit','warehouse_weight_unit_id_other','id');
  53. }
  54. public function carrier_weight_unit_other(){
  55. return $this->belongsTo('App\Unit','carrier_weight_unit_id_other','id');
  56. }
  57. public function carType(){
  58. return $this->belongsTo('App\CarType','carType_id','id');
  59. }
  60. public function waybillAuditLogs(){
  61. return $this->hasMany('App\WaybillAuditLog','waybill_id','id');
  62. }
  63. public function uploadFile(){
  64. return $this->hasOne('App\UploadFile','table_id','id')->where('table_name','waybills');
  65. }
  66. public function waybill_on_top(){
  67. return $this->belongsTo('App\WaybillOnTop','waybill_id','id');
  68. }
  69. public function amount_unit(){
  70. return $this->belongsTo('App\Unit','amount_unit_id','id');
  71. }
  72. static public function setWeightByOrderCode($orderCode,$weight){
  73. if(empty($orderCode))return;
  74. $waybill=Waybill::where('wms_bill_number',$orderCode)->where('status','!=','已完结')
  75. ->where('status','!=','无模型')->first();
  76. if ($waybill){
  77. $waybill->warehouse_weight_other=$weight;
  78. $waybill->warehouse_weight_unit_id_other=1;
  79. $waybill->update();
  80. }
  81. }
  82. public function getUploadFileUrlAttribute(){
  83. return $this['uploadFile']? asset('/storage'.$this['uploadFile']['url']):null;
  84. }
  85. public function getUploadFileTypeAttribute(){
  86. return $this['uploadFile']? $this['uploadFile']['type']:null;
  87. }
  88. public function getOwnerNameAttribute(){
  89. return $this['owner']? $this['owner']['name']:null;
  90. }
  91. public function getCarrierNameAttribute(){
  92. return $this['carrier']? $this['carrier']['name']:null;
  93. }
  94. public function getOriginationCityNameAttribute(){
  95. return $this['origination_city']? $this['origination_city']['name']:null;
  96. }
  97. public function getDestinationCityNameAttribute(){
  98. return $this['destination_city']? $this['destination_city']['name']:null;
  99. }
  100. function getDestinationProvinceNameAttribute(){
  101. return $this['destination_city'] ? $this['destination_city']['province_name']:null;
  102. }
  103. public function getWarehouseWeightUnitNameAttribute(){
  104. return $this['warehouse_weight_unit']? $this['warehouse_weight_unit']['name']:null;
  105. }
  106. public function getCarrierWeightUnitNameAttribute(){
  107. return $this['carrier_weight_unit']? $this['carrier_weight_unit']['name']:null;
  108. }
  109. public function getWarehouseWeightUnitOtherNameAttribute(){
  110. return $this['warehouse_weight_unit_other']? $this['warehouse_weight_unit_other']['name']:null;
  111. }
  112. public function getCarrierWeightUnitOtherNameAttribute(){
  113. return $this['carrier_weight_unit_other']? $this['carrier_weight_unit_other']['name']:null;
  114. }
  115. public function getAmountUnitNameAttribute(){
  116. return $this['amount_unit']? $this['amount_unit']['name']:null;
  117. }
  118. }