1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- declare (strict_types = 1);
- namespace app\admin\model;
- use app\model\TaxCategory;
- use app\model\TaxRelation;use think\Model;
- use think\model\concern\SoftDelete;use function Symfony\Component\String\b;
- /**
- * @mixin \think\Model
- */
- class GoodTax extends Model
- {
- use SoftDelete;
- protected $createTime = 'createTime';
- protected $updateTime = 'updateTime';
- protected $deleteTime = 'delete_time';
- protected $autoWriteTimestamp = 'datetime';
- public function Tax(){
- return $this->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);
- }
- }
|