hasOne('App\Owner','id','id_owner'); } function logistic(){ return $this->hasOne('App\Logistic','id','id_logistic_return'); } function items(){ return $this->hasMany('App\RejectedBillItem','id_rejected_bill','id'); } function rejectedBillItems(){ return $this->items(); } function wmsReflectReceive(){ return $this->belongsTo('App\WMSReflectReceive','id','id_rejected_bill'); } function logisticName(){ $logistic=$this->hasOne('App\Logistic','id','id_logistic_return')->first(); return $logistic?$logistic['name']:''; } function makeCheckedNumbers(){ $owner = $this->owner()->first(); if(!$owner)return ''; $pinyinOwnerName=Pinyin::convert($owner->name); $pinyinArr=array_map(function($pinyin){ return $pinyin[0]; },$pinyinOwnerName); $initials=implode("", $pinyinArr); $this['checked_numbers']=$initials.Carbon::now()->format('Ymd').$owner->getIncreasedCheckingCount(); return $this['checked_numbers']; } function update(array $attributes = [], array $options = []) { (new LogisticNumberFeatureController())->createFeatures($this['logistic_number_return'],$this['id_logistic_return']); return parent::update($attributes, $options); } function save(array $options = []) { (new LogisticNumberFeatureController())->createFeatures($this['logistic_number_return'],$this['id_logistic_return']); return parent::save($options); } public function getOwnerNameAttribute(){ $id_owner=$this['id_owner']??0; $owner=Owner::find($id_owner); return $this['owner_name']=$owner['name']; } public function getLogisticNameAttribute(){ $id_logistic=$this['id_logistic_return']??0; $logistic=Logistic::find($id_logistic); return $this['logistic_name']=$logistic['name']; } public function getIsLoadedStrAttribute(){ $val=$this['is_loaded']===null?'null':$this['is_loaded']; $val=$val===0?'0':$val; switch ($val){ case 'null':return '无需入库'; case '0':return '否'; case 1:return '是'; case 2:return '待推单'; } return ''; } public function getCreatedAtShortAttribute(){ return $this['created_at']?$this['created_at_short']=$this['created_at']->format('m-d H:i:s'):''; } public function getGoodsAmountAttribute(){ $amount=0; $this->items()->get()->each(function (RejectedBillItem $item)use(&$amount){ $amount+=$item['amount']; }); return $amount; } public function getOperatorNameAttribute(){ if(!$this['id_operator']){return '';} $user=User::find($this['id_operator']); return $user['name']; } public function getIsLoadedNullAttribute(){ if($this['is_loaded']===null) return 'null'; return $this['is_loaded']; } public function changeIsLoaded_ifItemsAllLoaded(){ $allItemsAreLoaded=true; $this->items->each(function (RejectedBillItem $item)use(&$allItemsAreLoaded){ if($item['is_loaded']=='未入库'){ $allItemsAreLoaded=false; return false; } }); if($allItemsAreLoaded){ $this['is_loaded']=1; }else{ $this['is_loaded']=0; } $this->update(); return $this['is_loaded']; } }