model=new \app\admin\model\DataChange(); } /** * @return \think\response\Json|void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function create(){ $param =$this->request->only(["code"=>'',"type"=>"",'oaCode'=>'',"change"=>"","apply_id"=>"","apply_name"=>""], "post","trim"); $valid =Validate::rule([ "code|订单编号"=>"require", "type|订单类型"=>"require|number|in:1,2,3", "apply_id|申请人"=>"require|number", "change|修改字段内容"=>"require|array"]); if($valid->check($param)==false) return error_show(1004,$valid->getError()); if($param['type']==1){ $orderinfo = Db::name("purchease_order")->where(["cgdNo"=>$param['code']])->find(); $fininfo =GetFin('admin/orderischeck',['token'=>$this->post['token'],'orderCode'=>$param['code'],'is_cgd_check'=>1]); if(!isset($fininfo['code'])||$fininfo['code']!=0 ){ return json_show(10005, $fininfo['message']??'结算校验失败',$fininfo['data']??[]); } } if($param['type']==2){ $orderinfo = Db::name('sale')->where(['orderCode'=>$param['code']])->find(); $fininfo =GetFin('admin/orderischeck',['token'=>$this->post['token'],'orderCode'=>$param['code'],'is_cgd_check'=>0]); if(!isset($fininfo['code'])||$fininfo['code']!=0 ){ return json_show(10005, $fininfo['message']??'结算校验失败',$fininfo['data']??[]); } } if($param['type']==3){ $orderinfo = Db::name('good_zixun')->where(['spuCode'=>$param['code']])->find(); } $ist =$this->model->where(["code"=>$param['code'],"status"=>1])->findOrEmpty(); if($ist->isEmpty()==false)return error_show(1004,"订单修改存在未完成得流程"); if($orderinfo==false) return error_show(1004,"订单数据未找到"); if($param['type']==1 && $orderinfo['order_source']!=2 )return error_show(1004,'供应商非咨询单订单不可修改'); $array_diff=array_diff($param['change'],$orderinfo); $order=[]; $userCommon= \app\admin\common\User::getIns(); foreach ($array_diff as $key=>$iten){ $order[$key] = $orderinfo[$key]??""; if($param['type']==1 && $key=='supplierNo'){ $persion =$userCommon->handle("sInfo",["code"=>$iten]); if(isset($persion['data'])&& !empty($persion['data'])){ $array_diff['cgder'] =$persion['data']['person']?:""; $array_diff['cgder_id'] =$persion['data']['personid']?:""; } } } $before = json_encode($order,JSON_UNESCAPED_UNICODE); $after = json_encode($array_diff,JSON_UNESCAPED_UNICODE); $data=[ "code"=>$param['code'], "type"=>$param['type'], "before"=>$before, "after"=>$after, "oaCode"=>$param['oaCode'], "apply_id"=>$param['apply_id'], "apply_name"=>$param['apply_name'], 'creater_id'=>$this->uid, 'creater'=>$this->uname, "status"=>1, ]; $in =$this->model->save($data); return $in? app_show(0,"新建成功"):error_show(1004,"新建失败"); } public function list(){ $param = $this->request->only(["code"=>"","oaCode"=>"","type"=>"","apply_name"=>"","status"=>"","page"=>1, "size"=>15],"post","trim"); $where=[["source","=",1]]; $param['code']==''?: $where[]=["code","like","%{$param['code']}%"]; $param['apply_name']==''?: $where[]=["apply_name","like","%{$param['apply_name']}%"]; $param['oaCode']==''?: $where[]=["oaCode","like","%{$param['oaCode']}%"]; $param['type']==''?: $where[]=["type","=",$param['type']]; $param['status']==''?: $where[]=["status","=",$param['status']]; $list = $this->model->where($where)->json(["before","after"])->order("id","desc")->paginate(["page"=>$param['page'], "list_rows"=>$param['size']]); return app_show(0,"获取成功",["list"=>$list->items(),"count"=>$list->total()]); } public function info(){ $param = $this->request->only(['id'],'post','trim'); $info = $this->model->json(['before','after'])->findOrEmpty($param['id']); return app_show(0,'获取成功',$info); } public function status(){ $param = $this->request->only(['id'=>"",'status'=>"",'remark'=>""],'post','trim'); $Valid =Validate::rule(["id|申请id"=>"require","status|状态"=>"require|number|in:2,3"]); if($Valid->check($param)==false) return error_show(1004,$Valid->getError()); $info = $this->model->findOrEmpty($param['id']); if($info->isEmpty())return error_show(1004,'未找到申请单数据'); if($info->status!=1) return error_show(1004,'申请单数据已审核'); $info->status=$param['status']; $info->remark=$param['remark']; if($info->status==2 && $info->type!=3){ if($info->type==1){ $fininfo =GetFin('admin/orderischeck',['token'=>$this->post['token'],'orderCode'=>$info->code,"is_cgd_check"=>1]); if(!isset($fininfo['code'])||$fininfo['code']!=0 ){ return json_show(10005, $fininfo['message']??'结算校验失败',$fininfo['data']??[]); } } if($info->type==2){ $fininfo =GetFin('admin/orderischeck',['token'=>$this->post['token'],'orderCode'=>$info->code,'is_cgd_check'=>0]); if(!isset($fininfo['code'])||$fininfo['code']!=0 ){ return json_show(10005, $fininfo['message']??'结算校验失败',$fininfo['data']??[]); } } } $this->model->startTrans(); try{ $up=$info->save(); if($up==false)throw new \Exception("申请单审核失败"); if($param['status']==2){ $this->model->updateOrder($info); } $this->model->commit(); }catch (\Exception $exception){ $this->model->rollback(); return error_show(1004,$exception->getMessage()); } return app_show(0,"申请数据处理完成"); } }