Waybill.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. "district_id"
  21. ];
  22. public function district()
  23. { //区
  24. return $this->belongsTo(Region::class,"district_id","id")->where("type",3);
  25. }
  26. public function owner(){
  27. return $this->hasOne('App\Owner','id','owner_id');
  28. }
  29. public function logistic(){
  30. return $this->hasOne('App\Logistic','id','logistic_id');
  31. }
  32. public function originationCity(){
  33. return $this->hasOne('App\City','id','origination_city_id');
  34. }
  35. public function destinationCity(){
  36. return $this->hasOne('App\City','id','destination_city_id');
  37. }
  38. public function wmsCommodities(){
  39. return $this->hasMany('App\WMSWaybillOrder','OrderNo','wms_bill_number');
  40. }
  41. public function priceModel(){
  42. return $this->hasOne('App\WaybillPriceModel','id','waybill_price_model_id');
  43. }
  44. public function amountUnit(){
  45. return $this->hasOne('App\Unit','id','amount_unit_id');
  46. }
  47. public function warehouseWeightUnit(){
  48. return $this->hasOne('App\Unit','id','warehouse_weight_unit_id');
  49. }
  50. public function carrierWeightUnit(){
  51. return $this->hasOne('App\Unit','id','carrier_weight_unit_id');
  52. }
  53. public function warehouseWeightUnitOther(){
  54. return $this->hasOne('App\Unit','id','warehouse_weight_unit_id_other');
  55. }
  56. public function carrierWeightUnitOther(){
  57. return $this->hasOne('App\Unit','id','carrier_weight_unit_id_other');
  58. }
  59. public function carType(){
  60. return $this->hasOne('App\CarType','id','carType_id');
  61. }
  62. public function waybillAuditLogs(){
  63. return $this->hasMany('App\WaybillAuditLog','waybill_id','id');
  64. }
  65. public function uploadFile(){
  66. return $this->hasOne('App\UploadFile','table_id','id')->where('table_name','waybills');
  67. }
  68. // public function getOrderingRemarkAttribute($val){
  69. // return
  70. // }
  71. static public function setWeightByOrderCode($orderCode,$weight){
  72. if(empty($orderCode))return;
  73. $waybill=Waybill::query()->where('wms_bill_number',$orderCode)->where('status','!=','已完结')
  74. ->where('status','!=','无模型')->first();
  75. if ($waybill){
  76. $waybill->warehouse_weight_other=$weight;
  77. $waybill->warehouse_weight_unit_id_other=1;
  78. $waybill->update();
  79. }
  80. }
  81. /**
  82. * @return Builder
  83. */
  84. public static function filterAuthorities(){
  85. $owner_ids=app('UserService')->getPermittingOwnerIds(auth()->user());
  86. return (new static)->newQuery()->whereIn('owner_id',$owner_ids);
  87. }
  88. }