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']); } public function CgdTax(){ return $this->belongsTo(TaxCategory::class,'cgd_tax_id','id') ->bind(['cgd_tax_name'=>'cat_name','cgd_tax_code'=>'cat_code','cgd_tax_short'=>'short_name','cgd_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","CgdTax"])->where(['spuCode'=>$spuCode])->findOrEmpty(); if($item->isEmpty()) return []; $temp=[]; switch ($type){ case 1: $temp['spuCode']=$item->spuCode; $temp['cat_code']=$item->in_tax_code; $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; break; case 2: $temp['spuCode']=$item->spuCode; $temp['cat_code']=$item->out_tax_code??''; $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; break; case 3: $temp['spuCode']=$item->spuCode; $temp['cat_code']=$item->cgd_tax_code??''; $temp['cat_name']=$item->cgd_tax_name??''; $temp['short_name']=$item->cgd_tax_short??''; $temp['merge_code']=$item->cgd_tax_merge; $temp['tax']= str_replace('%','',$item->cgd_tax); $temp['inv_good_name']=$item->inv_good_name; break; default: break; } return $temp; } public function SetTaxAttr($v){ return str_replace('%','',$v); } public function SetOutTaxAttr($v){ return str_replace('%','',$v); } public function SetCgdTaxAttr($v){ return str_replace('%','',$v); } }