Waybill.php 3.3 KB

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