Waybill.php 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace App;
  3. use App\Services\UserService;
  4. use Illuminate\Database\Eloquent\Builder;
  5. use Illuminate\Database\Eloquent\Model;
  6. use App\Traits\ModelTimeFormat;
  7. use Illuminate\Database\Eloquent\SoftDeletes;
  8. use Illuminate\Support\Facades\Auth;
  9. use App\Traits\LogModelChanging;
  10. class Waybill extends Model
  11. {
  12. use LogModelChanging;
  13. use ModelTimeFormat;
  14. use SoftDeletes;
  15. protected $fillable=[
  16. 'status','type','waybill_number','owner_id','wms_bill_number','origination','destination','recipient','recipient_mobile','charge','ordering_remark',
  17. 'logistic_id','carrier_bill','origination_city_id','destination_city_id','warehouse_weight','warehouse_weight_unit_id','carrier_weight','carrier_weight_unit_id','carType_id',
  18. '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'
  19. ,'carrier_weight_other','carrier_weight_unit_id_other','source_bill','mileage','amount','inquire_tel','amount_unit_id','other_charge','other_charge_remark','deliver_at'
  20. ];
  21. public function owner(){
  22. return $this->hasOne('App\Owner','id','owner_id');
  23. }
  24. public function logistic(){
  25. return $this->hasOne('App\Logistic','id','logistic_id');
  26. }
  27. public function originationCity(){
  28. return $this->hasOne('App\City','id','origination_city_id');
  29. }
  30. public function destinationCity(){
  31. return $this->hasOne('App\City','id','destination_city_id');
  32. }
  33. public function wmsCommodities(){
  34. return $this->hasMany('App\WMSWaybillOrder','OrderNo','wms_bill_number');
  35. }
  36. public function priceModel(){
  37. return $this->hasOne('App\WaybillPriceModel','id','waybill_price_model_id');
  38. }
  39. public function amountUnit(){
  40. return $this->hasOne('App\Unit','id','amount_unit_id');
  41. }
  42. public function warehouseWeightUnit(){
  43. return $this->hasOne('App\Unit','id','warehouse_weight_unit_id');
  44. }
  45. public function carrierWeightUnit(){
  46. return $this->hasOne('App\Unit','id','carrier_weight_unit_id');
  47. }
  48. public function warehouseWeightUnitOther(){
  49. return $this->hasOne('App\Unit','id','warehouse_weight_unit_id_other');
  50. }
  51. public function carrierWeightUnitOther(){
  52. return $this->hasOne('App\Unit','id','carrier_weight_unit_id_other');
  53. }
  54. public function carType(){
  55. return $this->hasOne('App\CarType','id','carType_id');
  56. }
  57. public function waybillAuditLogs(){
  58. return $this->hasMany('App\WaybillAuditLog','waybill_id','id');
  59. }
  60. public function uploadFile(){
  61. return $this->hasOne('App\UploadFile','table_id','id')->where('table_name','waybills');
  62. }
  63. // public function getOrderingRemarkAttribute($val){
  64. // return
  65. // }
  66. static public function setWeightByOrderCode($orderCode,$weight){
  67. if(empty($orderCode))return;
  68. $waybill=Waybill::query()->where('wms_bill_number',$orderCode)->where('status','!=','已完结')
  69. ->where('status','!=','无模型')->first();
  70. if ($waybill){
  71. $waybill->warehouse_weight_other=$weight;
  72. $waybill->warehouse_weight_unit_id_other=1;
  73. $waybill->update();
  74. }
  75. }
  76. /**
  77. * @return Builder
  78. */
  79. public static function filterAuthorities(){
  80. $owner_ids=app('UserService')->getPermittingOwnerIds(auth()->user());
  81. return (new static)->newQuery()->whereIn('owner_id',$owner_ids);
  82. }
  83. }