| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- namespace App;
- use App\Services\UserService;
- use Illuminate\Database\Eloquent\Builder;
- use Illuminate\Database\Eloquent\Model;
- use App\Traits\ModelTimeFormat;
- use Illuminate\Database\Eloquent\SoftDeletes;
- use Illuminate\Support\Facades\Auth;
- use App\Traits\LogModelChanging;
- class Waybill extends Model
- {
- use LogModelChanging;
- use ModelTimeFormat;
- use SoftDeletes;
- protected $fillable=[
- 'status','type','waybill_number','owner_id','wms_bill_number','origination','destination','recipient','recipient_mobile','charge','ordering_remark',
- 'logistic_id','carrier_bill','origination_city_id','destination_city_id','warehouse_weight','warehouse_weight_unit_id','carrier_weight','carrier_weight_unit_id','carType_id',
- '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'
- ,'carrier_weight_other','carrier_weight_unit_id_other','source_bill','mileage','amount','inquire_tel','amount_unit_id','other_charge','other_charge_remark','deliver_at',
- "district_id"
- ];
- public function district()
- { //区
- return $this->belongsTo(Region::class,"district_id","id")->where("type",3);
- }
- public function owner(){
- return $this->hasOne('App\Owner','id','owner_id');
- }
- public function logistic(){
- return $this->hasOne('App\Logistic','id','logistic_id');
- }
- public function originationCity(){
- return $this->hasOne('App\City','id','origination_city_id');
- }
- public function destinationCity(){
- return $this->hasOne('App\City','id','destination_city_id');
- }
- public function wmsCommodities(){
- return $this->hasMany('App\WMSWaybillOrder','OrderNo','wms_bill_number');
- }
- public function priceModel(){
- return $this->hasOne('App\WaybillPriceModel','id','waybill_price_model_id');
- }
- public function amountUnit(){
- return $this->hasOne('App\Unit','id','amount_unit_id');
- }
- public function warehouseWeightUnit(){
- return $this->hasOne('App\Unit','id','warehouse_weight_unit_id');
- }
- public function carrierWeightUnit(){
- return $this->hasOne('App\Unit','id','carrier_weight_unit_id');
- }
- public function warehouseWeightUnitOther(){
- return $this->hasOne('App\Unit','id','warehouse_weight_unit_id_other');
- }
- public function carrierWeightUnitOther(){
- return $this->hasOne('App\Unit','id','carrier_weight_unit_id_other');
- }
- public function carType(){
- return $this->hasOne('App\CarType','id','carType_id');
- }
- public function waybillAuditLogs(){
- return $this->hasMany('App\WaybillAuditLog','waybill_id','id');
- }
- public function uploadFile(){
- return $this->hasOne('App\UploadFile','table_id','id')->where('table_name','waybills');
- }
- // public function getOrderingRemarkAttribute($val){
- // return
- // }
- static public function setWeightByOrderCode($orderCode,$weight){
- if(empty($orderCode))return;
- $waybill=Waybill::query()->where('wms_bill_number',$orderCode)->where('status','!=','已完结')
- ->where('status','!=','无模型')->first();
- if ($waybill){
- $waybill->warehouse_weight_other=$weight;
- $waybill->warehouse_weight_unit_id_other=1;
- $waybill->update();
- }
- }
- /**
- * @return Builder
- */
- public static function filterAuthorities(){
- $owner_ids=app('UserService')->getPermittingOwnerIds(auth()->user());
- return (new static)->newQuery()->whereIn('owner_id',$owner_ids);
- }
- }
|