123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- namespace app\user\model;
- use think\model\concern\SoftDelete;
- class TaxCompany extends Base
- {
- use SoftDelete;
- //设置字段信息
- protected $schema = [
- 'id' =>'bigint',//
- 'tax_id' =>'int',//税目id
- 'companyNo' =>'varchar',//公司编号
- 'income' =>'tinyint',//进项是否可用
- 'output' =>'tinyint',//销项是否可用
- 'createTime' =>'datetime',//
- 'updateTime' =>'datetime',//
- 'delete_time' =>'datetime',//
- ];
- protected $createTime='createTime';
- protected $updateTime='updateTime';
- protected $deleteTime='delete_time';
- public static $useType=["未设置","可用","不可用"];
- public function company(){
- return $this->belongsTo(Headquarters::class,'companyNo','code')->bind(['companyName'=>'name']);
- }
- public function tax(){
- return $this->belongsTo(TaxCategory::class,'tax_id','id')->bind(["cat_name","cat_code","short_name","merge_code"]);
- }
- public static function taxCheck($comapnyNo,$taxIds,$type='in'){
- $taxType=['in'=>'进项','out'=>'销项'];
- if($type=='in'){
- $where=[['companyNo','=',$comapnyNo],['income','=',1],['tax_id','in',$taxIds]];
- }else{
- $where=[['companyNo','=',$comapnyNo],['output','=',1],["tax_id","=",$taxIds]];
- }
- $list=self::with(['tax'])->where($where)->select();
- if($list->isEmpty())throw new \Exception($taxType[$type].'税目不可用');
- if($type=='in'){
- $Ids=array_column($list->toArray(),'tax_id');
- $diff=array_diff($taxIds,$Ids);
- if(!empty($diff)){
- $tax=TaxCategory::where('id','in',$diff)->column("cat_name");
- throw new \Exception($taxType[$type].'税目不可用:'.implode(',',$tax));
- }
- }
- return true;
- }
- }
|