belongsTo(TaxCategory::class,'tax_id','id') ->bind(["in_tax_name"=>'cat_name',"in_tax_code"=>'cat_code',"in_tax_short"=>'short_name',"in_tax_merge"=>'merge_code']); } public function OutTax(){ return $this->belongsTo(TaxCategory::class,'out_tax_id','id') ->bind(["out_tax_name"=>'cat_name',"out_tax_code"=>'cat_code',"out_tax_short"=>'short_name',"out_tax_merge"=>'merge_code']); } /** * @param $spuCode * @param int $type 1 进项票 2 销项票 * @return array */ public static function getInfobySpuCode($spuCode,$type=1){ $item = (new GoodTax)->with(['Tax',"OutTax"])->where(['spuCode'=>$spuCode])->findOrEmpty(); if($item->isEmpty()) return []; $temp=[]; if($type==1){ $temp['spuCode']=$item->spuCode; $temp['cat_code']=$item->in_tax_merge; $temp['cat_name']=$item->in_tax_name; $temp['short_name']=$item->in_tax_short; $temp['merge_code']=$item->in_tax_merge; $temp['tax']= str_replace("%","",$item->tax); $temp['inv_good_name']=$item->inv_good_name; }else{ $temp['spuCode']=$item->spuCode; $temp['cat_code']=$item->out_tax_merge??""; $temp['cat_name']=$item->out_tax_name??""; $temp['short_name']=$item->out_tax_short??""; $temp['merge_code']=$item->out_tax_merge; $temp['tax']= str_replace('%','',$item->out_tax); $temp['inv_good_name']=$item->inv_good_name; } return $temp; } }