TaxCompany.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace app\user\model;
  3. use think\model\concern\SoftDelete;
  4. class TaxCompany extends Base
  5. {
  6. use SoftDelete;
  7. //设置字段信息
  8. protected $schema = [
  9. 'id' =>'bigint',//
  10. 'tax_id' =>'int',//税目id
  11. 'companyNo' =>'varchar',//公司编号
  12. 'income' =>'tinyint',//进项是否可用
  13. 'output' =>'tinyint',//销项是否可用
  14. 'createTime' =>'datetime',//
  15. 'updateTime' =>'datetime',//
  16. 'delete_time' =>'datetime',//
  17. ];
  18. protected $createTime='createTime';
  19. protected $updateTime='updateTime';
  20. protected $deleteTime='delete_time';
  21. public static $useType=["未设置","可用","不可用"];
  22. public function company(){
  23. return $this->belongsTo(Headquarters::class,'companyNo','code')->bind(['companyName'=>'name']);
  24. }
  25. public function tax(){
  26. return $this->belongsTo(TaxCategory::class,'tax_id','id')->bind(["cat_name","cat_code","short_name","merge_code"]);
  27. }
  28. public static function taxCheck($comapnyNo,$taxIds,$type='in'){
  29. $taxType=['in'=>'进项','out'=>'销项'];
  30. if($type=='in'){
  31. $where=[['companyNo','=',$comapnyNo],['income','=',1],['tax_id','in',$taxIds]];
  32. }else{
  33. $where=[['companyNo','=',$comapnyNo],['output','=',1],["tax_id","=",$taxIds]];
  34. }
  35. $list=self::with(['tax'])->where($where)->select();
  36. if($list->isEmpty())throw new \Exception($taxType[$type].'税目不可用');
  37. if($type=='in'){
  38. $Ids=array_column($list->toArray(),'tax_id');
  39. $diff=array_diff($taxIds,$Ids);
  40. if(!empty($diff)){
  41. $tax=TaxCategory::where('id','in',$diff)->column("cat_name");
  42. throw new \Exception($taxType[$type].'税目不可用:'.implode(',',$tax));
  43. }
  44. }
  45. return true;
  46. }
  47. }