GoodTax.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\model;
  4. use app\model\TaxCategory;
  5. use app\model\TaxRelation;use think\Model;
  6. use think\model\concern\SoftDelete;
  7. /**
  8. * @mixin \think\Model
  9. */
  10. class GoodTax extends Model
  11. {
  12. use SoftDelete;
  13. protected $createTime = 'createTime';
  14. protected $updateTime = 'updateTime';
  15. protected $deleteTime = 'delete_time';
  16. protected $autoWriteTimestamp = 'datetime';
  17. public function Tax(){
  18. return $this->belongsTo(TaxCategory::class,'tax_id','id')->bind(['cat_name','cat_code','short_name','merge_code']);
  19. }
  20. /**
  21. * @param $spuCode
  22. * @param int $type 1 进项票 2 销项票
  23. * @return array
  24. */
  25. public static function getInfobySpuCode($spuCode,$type=1){
  26. $item = (new GoodTax)->with(['Tax'])->where(['spuCode'=>$spuCode])->findOrEmpty();
  27. if($item->isEmpty()) return [];
  28. $temp=[];
  29. if($type==1){
  30. $temp['spuCode']=$item->childCode;
  31. $temp['cat_code']=$item->merge_code;
  32. $temp['cat_name']=$item->short_name;
  33. $temp['tax']=$item->tax;
  34. $temp['inv_good_name']=$item->inv_good_name;
  35. }else{
  36. $taxRelation= TaxRelation::with(['outputInfo'])->where(['income_tax_id'=>$item->tax_id,'companyNo'=>$item->companyNo])->findOrEmpty();
  37. if($taxRelation->isEmpty())return [];
  38. $temp['spuCode']=$item->spuCode;
  39. $temp['cat_code']=$taxRelation->merge_code;
  40. $temp['cat_name']=$taxRelation->short_name;
  41. $temp['tax']=$taxRelation->output_bind_tax;
  42. $temp['inv_good_name']=$item->inv_good_name;
  43. }
  44. return $temp;
  45. }
  46. }