belongsTo(TaxCategory::class,'tax_id','id')->bind(['cat_name','cat_code','short_name','merge_code']); } /** * @param $spuCode * @param int $type 1 进项票 2 销项票 * @return array */ public static function getInfobySpuCode($spuCode,$type=1){ $item = (new GoodTax)->with(['Tax'])->where(['spuCode'=>$spuCode])->findOrEmpty(); if($item->isEmpty()) return []; $temp=[]; if($type==1){ $temp['spuCode']=$item->childCode; $temp['cat_code']=$item->merge_code; $temp['cat_name']=$item->short_name; $temp['tax']=$item->tax; $temp['inv_good_name']=$item->inv_good_name; }else{ $taxRelation= TaxRelation::with(['outputInfo'])->where(['income_tax_id'=>$item->tax_id,'companyNo'=>$item->companyNo])->findOrEmpty(); if($taxRelation->isEmpty())return []; $temp['spuCode']=$item->spuCode; $temp['cat_code']=$taxRelation->merge_code; $temp['cat_name']=$taxRelation->short_name; $temp['tax']=$taxRelation->output_bind_tax; $temp['inv_good_name']=$item->inv_good_name; } return $temp; } }