Waybill.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. use App\Traits\ModelTimeFormat;
  5. use Illuminate\Database\Eloquent\SoftDeletes;
  6. use Illuminate\Support\Facades\Auth;
  7. class Waybill extends Model
  8. {
  9. use ModelTimeFormat;
  10. use SoftDeletes;
  11. protected $fillable=[
  12. 'status','type','waybill_number','owner_id','wms_bill_number','origination','destination','recipient','recipient_mobile','charge','ordering_remark',
  13. 'carrier_id','carrier_bill','origination_city_id','destination_city_id','warehouse_weight','warehouse_weight_unit_id','carrier_weight','carrier_weight_unit_id','carType_id',
  14. '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'
  15. ,'carrier_weight_other','carrier_weight_unit_id_other','source_bill','mileage','amount','inquire_tel','amount_unit_id','other_charge','other_charge_remark','deliver_at'
  16. ];
  17. protected $appends=[
  18. 'origination_city_name',
  19. 'carrier_name',
  20. 'owner_name',
  21. 'destination_city_name',
  22. 'warehouse_weight_unit_name',
  23. 'carrier_weight_unit_name',
  24. 'warehouse_weight_unit_other_name',
  25. 'carrier_weight_unit_other_name',
  26. 'amount_unit_name',
  27. 'upload_file_url',
  28. 'upload_file_type',
  29. 'destination_province_name'
  30. ];
  31. public function owner(){
  32. return $this->belongsTo('App\Owner','owner_id','id');
  33. }
  34. public function carrier(){
  35. return $this->belongsTo('App\Carrier','carrier_id','id');
  36. }
  37. public function origination_city(){
  38. return $this->belongsTo('App\City','origination_city_id','id');
  39. }
  40. public function destination_city(){
  41. return $this->belongsTo('App\City','destination_city_id','id');
  42. }
  43. public function wmsCommodities(){
  44. return $this->hasMany('App\WMSWaybillOrder','OrderNo','wms_bill_number');
  45. }
  46. public function warehouse_weight_unit(){
  47. return $this->belongsTo('App\Unit','warehouse_weight_unit_id','id');
  48. }
  49. public function carrier_weight_unit(){
  50. return $this->belongsTo('App\Unit','carrier_weight_unit_id','id');
  51. }
  52. public function warehouse_weight_unit_other(){
  53. return $this->belongsTo('App\Unit','warehouse_weight_unit_id_other','id');
  54. }
  55. public function carrier_weight_unit_other(){
  56. return $this->belongsTo('App\Unit','carrier_weight_unit_id_other','id');
  57. }
  58. public function carType(){
  59. return $this->belongsTo('App\CarType','carType_id','id');
  60. }
  61. public function waybillAuditLogs(){
  62. return $this->hasMany('App\WaybillAuditLog','waybill_id','id');
  63. }
  64. public function uploadFile(){
  65. return $this->hasOne('App\UploadFile','table_id','id')->where('table_name','waybills');
  66. }
  67. public function waybill_on_top(){
  68. return $this->belongsTo('App\WaybillOnTop','waybill_id','id');
  69. }
  70. public function amount_unit(){
  71. return $this->belongsTo('App\Unit','amount_unit_id','id');
  72. }
  73. static public function setWeightByOrderCode($orderCode,$weight){
  74. if(empty($orderCode))return;
  75. $waybill=Waybill::where('wms_bill_number',$orderCode)->where('status','!=','已完结')
  76. ->where('status','!=','无模型')->first();
  77. if ($waybill){
  78. $waybill->warehouse_weight_other=$weight;
  79. $waybill->warehouse_weight_unit_id_other=1;
  80. $waybill->update();
  81. }
  82. }
  83. public function getUploadFileUrlAttribute(){
  84. return $this['uploadFile']? asset('/storage'.$this['uploadFile']['url']):null;
  85. }
  86. public function getUploadFileTypeAttribute(){
  87. return $this['uploadFile']? $this['uploadFile']['type']:null;
  88. }
  89. public function getOwnerNameAttribute(){
  90. return $this['owner']? $this['owner']['name']:null;
  91. }
  92. public function getCarrierNameAttribute(){
  93. return $this['carrier']? $this['carrier']['name']:null;
  94. }
  95. public function getOriginationCityNameAttribute(){
  96. return $this['origination_city']? $this['origination_city']['name']:null;
  97. }
  98. public function getDestinationCityNameAttribute(){
  99. return $this['destination_city']? $this['destination_city']['name']:null;
  100. }
  101. function getDestinationProvinceNameAttribute(){
  102. return $this['destination_city'] ? $this['destination_city']['province_name']:null;
  103. }
  104. public function getWarehouseWeightUnitNameAttribute(){
  105. return $this['warehouse_weight_unit']? $this['warehouse_weight_unit']['name']:null;
  106. }
  107. public function getCarrierWeightUnitNameAttribute(){
  108. return $this['carrier_weight_unit']? $this['carrier_weight_unit']['name']:null;
  109. }
  110. public function getWarehouseWeightUnitOtherNameAttribute(){
  111. return $this['warehouse_weight_unit_other']? $this['warehouse_weight_unit_other']['name']:null;
  112. }
  113. public function getCarrierWeightUnitOtherNameAttribute(){
  114. return $this['carrier_weight_unit_other']? $this['carrier_weight_unit_other']['name']:null;
  115. }
  116. public function getAmountUnitNameAttribute(){
  117. return $this['amount_unit']? $this['amount_unit']['name']:null;
  118. }
  119. public static function filterAuthorities(){
  120. $user = Auth::user();
  121. $owner_ids=$user->getPermittingOwnerIdsAttribute();
  122. return (new static)->newQuery()->whereIn('owner_id',$owner_ids);
  123. }
  124. }