1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?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;
- /**
- * @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(['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;
- }
- }
|