TaxCompany.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. 'in_status' =>'tinyint',//进项关联状态
  15. 'out_status' =>'tinyint',//销项关联状态
  16. 'createTime' =>'datetime',//
  17. 'updateTime' =>'datetime',//
  18. 'delete_time' =>'datetime',//
  19. ];
  20. protected $createTime='createTime';
  21. protected $updateTime='updateTime';
  22. protected $deleteTime='delete_time';
  23. public static $useType=["未设置","可用","不可用"];
  24. public static $inStatus=["未设置","关联","未关联"];
  25. public function company(){
  26. return $this->belongsTo(Headquarters::class,'companyNo','code')->bind(['companyName'=>'name']);
  27. }
  28. public function tax(){
  29. return $this->belongsTo(TaxCategory::class,'tax_id','id')->bind(["cat_name","cat_code","short_name","merge_code"]);
  30. }
  31. public static function taxCheck($comapnyNo,$taxIds,$type='in'){
  32. $taxType=['in'=>'进项','out'=>'销项'];
  33. if($type=='in'){
  34. $where=[['companyNo','=',$comapnyNo],['income','=',1],['tax_id','in',$taxIds]];
  35. }else{
  36. $where=[['companyNo','=',$comapnyNo],['output','=',1],["tax_id","=",$taxIds]];
  37. }
  38. $list=self::with(['tax'])->where($where)->select();
  39. if($list->isEmpty())throw new \Exception($taxType[$type].'税目不可用');
  40. if($type=='in'){
  41. $Ids=array_column($list->toArray(),'tax_id');
  42. $diff=array_diff($taxIds,$Ids);
  43. if(!empty($diff)){
  44. $tax=TaxCategory::where('id','in',$diff)->column("cat_name");
  45. throw new \Exception($taxType[$type].'税目不可用:'.implode(',',$tax));
  46. }
  47. }
  48. return true;
  49. }
  50. }