belongsTo('App\RejectedBill', 'id_rejected_bill', 'id'); } public function wmsReflectSku(){ $bill=$this->rejectedBill()->first(); $wmsReflectReceive=$bill->wmsReflectReceive()->first(); if(!$wmsReflectReceive){ $wmsReflectReceive=WMSReflectReceive::where('ASNREFERENCE3',$bill['logistic_number_return'])->orderBy('id','desc')->first(); if(!$wmsReflectReceive)return null; } return $wmsReflectReceive->skus()->where('ALTERNATE_SKU1',$this['barcode_goods']); } public function injectCommodityName(){ if(!$this['name_goods'])return; $barcode=$this['barcode_goods']; $name=$this['name_goods']; $commodity=Commodity::where('barcode', $barcode)->first(); if($commodity){ if($commodity['name']!=$name){ $commodity['name']=$name; } if(!$commodity['owner_name']){ $commodity['owner_name']=$this->rejectedBill->owner->name; } $commodity->update(); } else{ $commodity = new Commodity(); $commodity['barcode']=$barcode; $commodity['name']=$name; $commodity['owner_name']=$this->rejectedBill->owner->name; $commodity->save(); } } public function getQualityLabelAttribute(){ $label=QualityLabel::find($this['id_quality_label']); return $label['name']; } }