GoodTax.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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;use function Symfony\Component\String\b;
  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')
  19. ->bind(["in_tax_name"=>'cat_name',"in_tax_code"=>'cat_code',"in_tax_short"=>'short_name',"in_tax_merge"=>'merge_code']);
  20. }
  21. public function OutTax(){
  22. return $this->belongsTo(TaxCategory::class,'out_tax_id','id')
  23. ->bind(["out_tax_name"=>'cat_name',"out_tax_code"=>'cat_code',"out_tax_short"=>'short_name',"out_tax_merge"=>'merge_code']);
  24. }
  25. public function CgdTax(){
  26. return $this->belongsTo(TaxCategory::class,'cgd_tax_id','id')
  27. ->bind(['cgd_tax_name'=>'cat_name','cgd_tax_code'=>'cat_code','cgd_tax_short'=>'short_name','cgd_tax_merge'=>'merge_code']);
  28. }
  29. /**
  30. * @param $spuCode
  31. * @param int $type 1 进项票 2 销项票
  32. * @return array
  33. */
  34. public static function getInfobySpuCode($spuCode,$type=1){
  35. $item = (new GoodTax)->with(['Tax',"OutTax","CgdTax"])->where(['spuCode'=>$spuCode])->findOrEmpty();
  36. if($item->isEmpty()) return [];
  37. $temp=[];
  38. switch ($type){
  39. case 1:
  40. $temp['spuCode']=$item->spuCode;
  41. $temp['cat_code']=$item->in_tax_code;
  42. $temp['cat_name']=$item->in_tax_name;
  43. $temp['short_name']=$item->in_tax_short;
  44. $temp['merge_code']=$item->in_tax_merge;
  45. $temp['tax']= str_replace('%','',$item->tax);
  46. $temp['inv_good_name']=$item->inv_good_name;
  47. break;
  48. case 2:
  49. $temp['spuCode']=$item->spuCode;
  50. $temp['cat_code']=$item->out_tax_code??'';
  51. $temp['cat_name']=$item->out_tax_name??'';
  52. $temp['short_name']=$item->out_tax_short??'';
  53. $temp['merge_code']=$item->out_tax_merge;
  54. $temp['tax']= str_replace('%','',$item->out_tax);
  55. $temp['inv_good_name']=$item->inv_good_name;
  56. break;
  57. case 3:
  58. $temp['spuCode']=$item->spuCode;
  59. $temp['cat_code']=$item->cgd_tax_code??'';
  60. $temp['cat_name']=$item->cgd_tax_name??'';
  61. $temp['short_name']=$item->cgd_tax_short??'';
  62. $temp['merge_code']=$item->cgd_tax_merge;
  63. $temp['tax']= str_replace('%','',$item->cgd_tax);
  64. $temp['inv_good_name']=$item->inv_good_name;
  65. break;
  66. default:
  67. break;
  68. }
  69. return $temp;
  70. }
  71. public function SetTaxAttr($v){
  72. return str_replace('%','',$v);
  73. }
  74. public function SetOutTaxAttr($v){
  75. return str_replace('%','',$v);
  76. }
  77. public function SetCgdTaxAttr($v){
  78. return str_replace('%','',$v);
  79. }
  80. }