Waybill.php 3.3 KB

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