|
@@ -0,0 +1,103 @@
|
|
|
|
+<?php
|
|
|
|
+declare (strict_types = 1);
|
|
|
|
+
|
|
|
|
+namespace app\admin\controller;
|
|
|
|
+
|
|
|
|
+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'=>'','supplierNo'=>'',
|
|
|
|
+ 'creater'=>'','isZx'=>'',"cat_diff"=>"","tax_diff"=>"",'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["supplierNo"]==""?? $where[]=['supplierNo','like',"%{$param['supplierNo']}%"];
|
|
|
|
+ $param["creater"]==""?? $where[]=['creater','like',"%{$param['creater']}%"];
|
|
|
|
+ $param["status"]===""?? $where[]=['status','=',$param['status']];
|
|
|
|
+ $param["isZx"]==""?? $where[]=['isZx','=',$param['isZx']];
|
|
|
|
+ $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"=>""],"post","trim");
|
|
|
|
+ $valid=Validate::rule(["list|审核数据集"=>"require|array","status|状态"=>"require|number|in:1,2"]);
|
|
|
|
+ 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(["cat_code"=>array_unique(array_column($param['list'],"cat_code"))])
|
|
|
|
+ ->column('tax,merge_code,short_name', 'cat_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(!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))$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]."不可修改");
|
|
|
|
+ $item['tax'] = bcdiv(str_replace('%', '', $item['tax']), "100", 2);
|
|
|
|
+ if($param['status']==1){
|
|
|
|
+ if($good->cgd_to_pay)$this->error("商品{$item['spuCode']}已参与采购付款回票对账");
|
|
|
|
+ $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){
|
|
|
|
+ if($good->qrd_to_pay)$this->error("商品{$item['spuCode']}已参与销售回款开票结算");
|
|
|
|
+ $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']= $item['tax']==$good->cgd_inv_tax?1:2;
|
|
|
|
+ $temp['cat_diff']= $temp['inv_cat_code']==$good->cgd_inv_cat_code?1:2;
|
|
|
|
+ }
|
|
|
|
+ $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;
|
|
|
|
+ }
|
|
|
|
+ $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("商品信息不存在");
|
|
|
|
+ $this->success("获取成功",$info);
|
|
|
|
+ }
|
|
|
|
+}
|