123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- <?php
- declare (strict_types = 1);
- namespace app\admin\controller;
- use app\admin\model\GoodChange;use app\admin\model\GoodCombind;use think\App;use think\facade\Validate;
- class Good extends Base
- {
- protected $model=null;
- public function __construct(App $app) {
- parent::__construct($app);
- $this->model=new \app\admin\model\Good();
- }
- /** 商品列表
- * @throws \think\db\exception\DbException
- * @throws \think\exception\DbException
- */
- public function list(){
- $param=$this->request->param(["spuCode"=>"","status"=>"","good_name"=>"",'companyNo'=>'','relaComNo'=>'',
- 'supplierNo'=>'','cgd_supplierNo'=>'','creater'=>'','isZx'=>'','isChild'=>0,'isCombind'=>'','isChange'=>'',"cat_diff"=>"",
- "tax_diff"=>"","is_diff"=>"","start"=>"",'end'=>'','page'=>'1','size'=>'15'],"post","trim");
- $where=[];
- $param["spuCode"]==""?: $where[]=['spuCode','like',"%{$param['spuCode']}%"];
- $param["good_name"]==""?: $where[]=['good_name','like',"%{$param['good_name']}%"];
- $param["companyNo"]==""?: $where[]=['companyNo','like',"%{$param['companyNo']}%"];
- $param["relaComNo"]==""?: $where[]=['companyNo|supplierNo','like',"%{$param['relaComNo']}%"];
- $param["supplierNo"]==""?: $where[]=['supplierNo|cgd_supplierNo','like',"%{$param['supplierNo']}%"];
- $param['cgd_supplierNo']==''?: $where[]=['cgd_supplierNo','like',"%{$param['cgd_supplierNo']}%"];
- $param["creater"]==""?: $where[]=['creater','like',"%{$param['creater']}%"];
- $param["status"]===""?: $where[]=['status','=',$param['status']];
- $param["isZx"]===""?: $where[]=['isZx','=',$param['isZx']];
- $param["isChild"]==""?: $where[]=['isChild','=',$param['isChild']];
- $param["isCombind"]==""?: $where[]=['isCombind','=',$param['isCombind']];
- $param["isChange"]===""?: $where[]=['isChange','=',$param['isChange']];
- $param["is_diff"]==""?: $where[]=['cat_diff|tax_diff','=',2];
- $param["cat_diff"]==""?: $where[]=['cat_diff','=',$param['cat_diff']];
- $param["tax_diff"]==""?: $where[]=['tax_diff','=',$param['tax_diff']];
- $param["start"]==""?: $where[]=['addtime','>=',date("Y-m-d 00:00:00",strtotime($param['start']))];
- $param["end"]==""?: $where[]=['addtime','<=',date("Y-m-d 23:59:59",strtotime($param['end']))];
- $list= $this->model
- ->where($where)
- ->order("id desc")
- ->paginate(["page"=>$param['page'],"list_rows"=>$param["size"]]);
- $this->success("获取成功",["list"=>$list->items(),"count"=>$list->total()]);
- }
- //批量更新数据状态审核
- public function exam(){
- $param=$this->request->param(["list"=>[],"status"=>"","isZx"=>0],"post","trim");
- $valid=Validate::rule([
- "list|审核数据集"=>"require|array",
- "status|状态"=>"require|number|in:1,2",
- "isZx|商品类型"=>"require|number|in:0,1"
- ]);
- if($valid->check($param)==false)$this->error($valid->getError());
- $validList=Validate::rule([
- 'spuCode|商品编号' => 'require|max:255',
- 'tax|税率' => 'require|max:4',
- 'cat_code|类目编号简写' => 'require|max:255',
- 'inv_good_name|开票商品名称' => 'require|max:255',
- 'inv_tag|税率标识' => 'requireIf:status,2|between:0,3',
- 'is_discount|是否有优惠政策' => 'requireIf:status,2|in:0,1',
- 'addTax|增值税管理内容' => 'max:255']);
- $goodUpdate=[];
- $catArr = \app\admin\model\InvCat::where(["merge_code"=>array_unique(array_column($param['list'],"cat_code"))])
- ->column('tax,merge_code,short_name', 'merge_code');
- foreach ($param['list'] as $item){
- $temp=[];
- $item['status'] = $param['status'];
- if($validList->check($item)==false) $this->error("商品{$item['spuCode']}".$validList->getError());
- $good=$this->model->where(["spuCode"=>$item['spuCode']])->findOrEmpty();
- if($good->isEmpty())$this->error("商品信息{$item['spuCode']}不存在");
- if($good->isZx!= $param['isZx'])$this->error("商品{$item['spuCode']}类型与当前操作商品类型不一致");
- if(!isset($catArr[$item['cat_code']]))$this->error("商品{$item['spuCode']}所选类目不存在");
- $tax = $catArr[$item['cat_code']]['tax']==""?[]:explode('、', $catArr[$item['cat_code']]['tax']);
- if(!in_array($item['tax'],$tax) && $param['status']==2 && $good['companyNo'] =='GS2203161855277894')$this->error("商品{$item['spuCode']}所选税率与类目包含税率不一致");
- //采购端修改 只能在待财务设置税务类目状态 切该商品未参与采购付款回票对账
- //销售端修改 只要没参与销售回款开票结算
- $temp['id']=$good->id;
- $temp['status']=$param['status'];
- if($param['status']<$good->status) $this->error("商品{$item['spuCode']}当前状态".\app\admin\model\Good::$status[$good->status]."不可修改");
- $tax= $item['tax'];
- $item['tax'] = bcdiv(str_replace('%', '', $item['tax']), "100", 2);
- if($param['status']==1){
- $temp["cgd_inv_cat_code"]=$catArr[$item['cat_code']]['merge_code'];
- $temp["cgd_inv_cat_name"]=$catArr[$item['cat_code']]['short_name'];
- $temp["cgd_inv_good_name"]= $item['inv_good_name'];
- $temp["cgd_inv_tax"]= $item['tax'];
- }
- if($param['status']==2){
- $check = CheckTax($item['is_discount'],$item['tax'],$item['inv_tag'],$item['addTax'],$message);
- if($check==false)$this->error("商品{$item['spuCode']}{$message}");
- $temp['inv_cat_code']=$catArr[$item['cat_code']]['merge_code'];
- $temp['inv_cat_name']=$catArr[$item['cat_code']]['short_name'];
- $temp['inv_good_name']= $item['inv_good_name'];
- $temp['inv_tax']= $item['tax'];
- $temp['is_discount']= $item['is_discount'];
- $temp['addTax']= $item['addTax'];
- $temp['inv_tag']= $item['inv_tag'];
- $temp['tax_diff']= $tax==$good->cgd_inv_tax?1:2;
- $temp['cat_diff']=intval($catArr[$item['cat_code']]['merge_code'])==intval($good->cgd_inv_cat_code)?1:2;
- }
- $check = $this->checkChange($good,$temp);
- if(!empty($check)){
- GoodChange::create($check);
- $temp['isChange']=1;
- }
- $examinfo=$good->exam_info;
- $examinfo[]=['apply_name'=>$this->uname,'exam_status'=>$item['status'],"updatetime"=>date("Y-m-d H:i:s")];
- $temp['exam_info'] = json_encode($examinfo,JSON_UNESCAPED_UNICODE);
- $goodUpdate[]=$temp;
- }
- $up=$this->model->saveAll($goodUpdate);
- $this->success("更新成功");
- }
- //商品信息
- public function info(){
- $param=$this->request->param(['spuCode'=>''],'post','trim');
- $valid=Validate::rule(['spuCode|商品成本编号'=>'require|max:255']);
- if($valid->check($param)==false)$this->error($valid->getError());
- $info = $this->model->where(["spuCode"=>$param['spuCode']])->findOrEmpty();
- if($info->isEmpty())$this->error("商品信息不存在");
- $info->combind=[];
- if($info->isCombind==1){
- $good = GoodCombind::with(['child'])->where(['spuCode'=>$info->spuCode,'is_del'=>0])->select();
- $info->combind = $good->isEmpty()?[]:$good->toArray();
- }
- $this->success("获取成功",$info);
- }
- //导出列表
- public function exportDiff(){
- $param=$this->request->param(['spuCode'=>'','status'=>'','good_name'=>'','companyNo'=>'','supplierNo'=>'','relaComNo'=>'',
- 'cgd_supplierNo'=>'','creater'=>'','isZx'=>'','cat_diff'=>'','tax_diff'=>'','isChild'=>0,"start"=>"",'end'=>'','is_diff'=>''],
- 'post','trim');
- ini_set('memory_limit' , '-1');
- $where=[];
- $param['spuCode']==''?: $where[]=['spuCode','like',"%{$param['spuCode']}%"];
- $param['good_name']==''?: $where[]=['good_name','like',"%{$param['good_name']}%"];
- $param['companyNo']==''?: $where[]=['companyNo','like',"%{$param['companyNo']}%"];
- $param['supplierNo']==''?: $where[]=['supplierNo|cgd_supplierNo','like',"%{$param['supplierNo']}%"];
- $param['relaComNo']==''?: $where[]=['companyNo|supplierNo','like',"%{$param['relaComNo']}%"];
- $param['cgd_supplierNo']==''?: $where[]=['cgd_supplierNo','like',"%{$param['cgd_supplierNo']}%"];
- $param['creater']==''?: $where[]=['creater','like',"%{$param['creater']}%"];
- $param['status']===''?: $where[]=['status','=',$param['status']];
- $param['isZx']==''?: $where[]=['isZx','=',$param['isZx']];
- $param['isChild']==''?: $where[]=['isChild','=',$param['isChild']];
- $param['is_diff']==''?: $where[]=['cat_diff|tax_diff','=',2];
- $param['cat_diff']==''?: $where[]=['cat_diff','=',$param['cat_diff']];
- $param['tax_diff']==''?: $where[]=['tax_diff','=',$param['tax_diff']];
- $param['start']==''?: $where[]=['addtime','>=',date('Y-m-d 00:00:00',strtotime($param['start']))];
- $param['end']==''?: $where[]=['addtime','<=',date('Y-m-d 23:59:59',strtotime($param['end']))];
- $field=["spuCode","cat_name","good_name","isZx","inv_cat_name","inv_good_name","inv_tax","cgd_inv_cat_name","
- cgd_inv_good_name","cgd_inv_tax","cat_diff","tax_diff","addtime"];
- $list= $this->model->export($where,$field);
- $header=["商品编码","商品分类","商品名称",'商品类型','采购商品类目','采购商品名称','采购商品税率','财务商品类目','财务商品名称','财务商品税率',
- '类目是否一致','税率是否一致','创建时间'];
- excelExport("商品税率异常记录", $header, $list);
- }
-
-
- public function export(){
- ini_set('memory_limit' , '-1');
- $param=$this->request->param(['spuCode'=>'','status'=>'','good_name'=>'','companyNo'=>'','supplierNo'=>'',
- 'cgd_supplierNo'=>'','relaComNo'=>'','creater'=>'','isZx'=>'','isChild'=>0,'isChange'=>'','cat_diff'=>'','tax_diff'=>'',
- 'is_diff'=>'','start'=>'','end'=>''],'post','trim');
- $where=[];
- $param['spuCode']==''?: $where[]=['spuCode','like',"%{$param['spuCode']}%"];
- $param['good_name']==''?: $where[]=['good_name','like',"%{$param['good_name']}%"];
- $param['companyNo']==''?: $where[]=['companyNo','like',"%{$param['companyNo']}%"];
- $param['supplierNo']==''?: $where[]=['supplierNo|cgd_supplierNo','like',"%{$param['supplierNo']}%"];
- $param['relaComNo']==''?: $where[]=['companyNo|supplierNo','like',"%{$param['relaComNo']}%"];
- $param['cgd_supplierNo']==''?: $where[]=['cgd_supplierNo','like',"%{$param['cgd_supplierNo']}%"];
- $param['creater']==''?: $where[]=['creater','like',"%{$param['creater']}%"];
- $param['status']===''?: $where[]=['status','=',$param['status']];
- $param['isZx']==''?: $where[]=['isZx','=',$param['isZx']];
- $param['isChild']===''?: $where[]=['isChild','=',$param['isChild']];
- $param['isChange']===''?: $where[]=['isChange','=',$param['isChange']];
- $param['is_diff']==''?: $where[]=['cat_diff|tax_diff','=',2];
- $param['cat_diff']==''?: $where[]=['cat_diff','=',$param['cat_diff']];
- $param['tax_diff']==''?: $where[]=['tax_diff','=',$param['tax_diff']];
- $param['start']==''?: $where[]=['addtime','>=',date('Y-m-d 00:00:00',strtotime($param['start']))];
- $param['end']==''?: $where[]=['addtime','<=',date('Y-m-d 23:59:59',strtotime($param['end']))];
- $header=['商品编码','卖出方公司编号','卖出方公司','买入方公司编号','买入方公司',"源头供应商编号","源头供应商名称",'商品名称','采购类目编码','采购类目名称','采购开票商品名称',
- "采购类目税率",'财务类目编码','财务类目名称','财务开票商品名称',"财务类目税率",'状态','增值税管理内容','创建人','创建时间'];
- $field=['spuCode','supplierNo','supplierName','companyNo','companyName','cgd_supplierNo','cgd_supplierName','good_name','cgd_inv_cat_code','cgd_inv_cat_name','
- cgd_inv_good_name','cgd_inv_tax','inv_cat_code','inv_cat_name','inv_good_name','inv_tax','status','addTax','creater','addtime'];
- $list= $this->model->export($where,$field);
- excelExport('结算类目设置导出表',$header,$list);
- }
- /**
- * @param $good
- * @param $check
- * @return array
- */
- private function checkChange($good,$check){
- $temp=[];
- if($check['status']==1){
- $before=[];
- $after=[];
- if($good->cgd_inv_cat_code!=""&&intval($check['cgd_inv_cat_code'])!=intval($good->cgd_inv_cat_code)){
- $before['inv_cat_code'] = $good->cgd_inv_cat_code;
- $after['inv_cat_code'] = $check['cgd_inv_cat_code'];
- }
- if($good->cgd_inv_cat_name!=''&&$check['cgd_inv_cat_name']!=$good->cgd_inv_cat_name){
- $before['inv_cat_name'] = $good->cgd_inv_cat_name;
- $after['inv_cat_name'] = $check['cgd_inv_cat_name'];
- }
- if($good->cgd_inv_good_name!=''&&$check['cgd_inv_good_name']!=$good->cgd_inv_good_name){
- $before['inv_good_name'] = $good->cgd_inv_good_name;
- $after['inv_good_name'] = $check['cgd_inv_good_name'];
- }
- if($good->cgd_inv_tax!=''){
- $cgd_inv_tax = bcdiv(str_replace('%', '', $good->cgd_inv_tax), '100', 2);
- if($check['cgd_inv_tax']!=$cgd_inv_tax){
- $before['inv_tax'] = $cgd_inv_tax;
- $after['inv_tax'] = $check['cgd_inv_tax'];
- }
- }
-
- if(!empty($before))$temp['before'] = json_encode($before,JSON_UNESCAPED_UNICODE);
- if(!empty($after))$temp['after'] = json_encode($after,JSON_UNESCAPED_UNICODE);
- }
-
- if($check['status']==2){
- $before=[];
- $after=[];
- if($good->inv_cat_code!=''&&$check['inv_cat_code']!=$good->inv_cat_code){
- $before['inv_cat_code'] = $good->inv_cat_code;
- $after['inv_cat_code'] = $check['inv_cat_code'];
- }
- if($good->inv_cat_name!=''&&$check['inv_cat_name']!=$good->inv_cat_name){
- $before['inv_cat_name'] = $good->inv_cat_name;
- $after['inv_cat_name'] = $check['inv_cat_name'];
- }
- if($good->inv_good_name!=''&&$check['inv_good_name']!=$good->inv_good_name){
- $before['inv_good_name'] = $good->inv_good_name;
- $after['inv_good_name'] = $check['inv_good_name'];
- }
- if($good->inv_tax!=''){
- $inv_tax = bcdiv(str_replace('%', '', $good->inv_tax), '100', 2);
- if($check['inv_tax']!=$inv_tax){
- $before['inv_tax'] = $inv_tax;
- $after['inv_tax'] = $check['inv_tax'];
- }
- }
-
- if($good->status==2&&$check['inv_tag']!=$good->inv_tag){
- $before['inv_tag'] = $good->inv_tag;
- $after['inv_tag'] = $check['inv_tag'];
- }
- if($good->status==2&&$check['is_discount']!=$good->is_discount){
- $before['is_discount'] = $good->is_discount;
- $after['is_discount'] = $check['is_discount'];
- }
- if($good->status==2&&$check['addTax']!=$good->addTax){
- $before['addTax'] = $good->addTax;
- $after['addTax'] = $check['addTax'];
- }
- if(!empty($before))$temp['before'] = json_encode($before,JSON_UNESCAPED_UNICODE);
- if(!empty($after))$temp['after'] = json_encode($after,JSON_UNESCAPED_UNICODE);
- }
- if(!empty($temp)){
- $temp['spuCode'] = $good->spuCode;
- $temp['good_name'] = $good->good_name;
- $temp['apply_id'] = $this->uid;
- $temp['apply_name'] = $this->uname;
- $temp['exam_status'] =$check['status'];
- }
- return $temp;
- }
- }
|