post; $condition = "a.is_del!=0 "; $check = checkRole($this->roleid,49); if($check){ $condition .=" and `a`.`apply_id` = {$this->uid}"; } $startTime= isset($post['startTime'])&&$post['startTime']!="" ? trim($post['startTime']) :""; $endTime= isset($post['endTime'])&&$post['endTime']!="" ? trim($post['endTime']) :""; $supplierNo= isset($post['supplierNo'])&&$post['supplierNo']!="" ? trim($post['supplierNo']) :""; $payNo= isset($post['payNo'])&&$post['payNo']!="" ? trim($post['payNo']) :""; $apply= isset($post['apply_name'])&&$post['apply_name']!="" ? trim($post['apply_name']) :""; $paystatus= isset($post['status'])&&$post['status']!="" ? $post['status'] :""; // $inv_status= isset($post['inv_status'])&&$post['inv_status']!="" ? $post['inv_status'] :""; if($startTime!=""){ $condition.=" and `b`.`addtime` >= '{$startTime}'"; } if($endTime!=""){ $condition.=" and `b`.`addtime` <= '{$endTime}'"; } if($supplierNo!=""){ $condition.=" and `a`.`supplierNo` like '%{$supplierNo}%'"; } if($payNo!=""){ $condition.=" and `a`.`payNo` like '%{$payNo}%'"; } if($apply!=""){ $condition .=" and b.apply_name like '%{$apply}%'"; } if($paystatus!=""){ $condition .=" and `b`.`status` = {$paystatus}"; } // if($inv_status!=""){ // $condition .=" and `a`.`inv_status` = {$inv_status}"; // } $page = isset($post['page'])&&$post['page']!="" ? intval($post['page']) :1; $size = isset($post['size'])&&$post['size']!="" ? intval($post['size']) :10; $count = Db::name("pay")->alias('a') ->join("cfp_pay_payment b",'`a`.`payNo` = `b`.`payNo` AND ( `b.`is_del` = 0 ) ','left') ->where($condition)->count(); $total = ceil($count/$size)>1 ? ceil($count/$size) : 1; $page = $page>=$total?intval($total):$page; $list = Db::name("pay")->alias('a') ->join("cfp_pay_payment b",'`a`.`payNo` = `b`.`payNo` AND ( `b.`is_del` = 0 ) ','left') ->where($condition)->page(intval($page),$size)->order("b.addtime desc") ->field(" `b`.`id` AS `id`, `a`.`payNo` AS `payNo`, `a`.`supplierNo`, `a`.`apay_fee` , `a`.`total_fee` AS `total_fee`, `b`.`apply_name`, `b`.`apply_id`, `a`.`winv_fee` , `a`.`ainv_fee` , `a`.`wpay_fee` , `a`.`pay_status` , `a`.`inv_status` , `b`.`pay_fee` AS `dpay_fee`, `b`.`return_img`, `b`.`return_time`, `b`.`status` AS `dstatus`, `a`.`status`, `a`.`remark` AS `remark`, `b`.`addtime` , `a`.`companyNo` , `a`.`companyName` , `b`.`dzNo` AS `dzNo` ")->select(); $data=[]; foreach ($list as $key=>$value){ $value['ordeNum'] = Db::name("pay_info")->where([["payNo","=",$value["payNo"]],["is_del","=",0]])->count(); $data[]=$value; } return app_show(0,"获取成功",["list"=>$data,"count"=>$count]); } /** *对账单列表 * @return \think\Response */ public function payList() { $post = $this->post; $condition = [["is_del","=",0]]; $check = checkRole($this->roleid,49); if($check){ $condition[]=["apply_id","=",$this->uid]; } $startTime= isset($post['startTime'])&&$post['startTime']!="" ? trim($post['startTime']) :""; $endTime= isset($post['endTime'])&&$post['endTime']!="" ? trim($post['endTime']) :""; $supplierNo= isset($post['supplierNo'])&&$post['supplierNo']!="" ? trim($post['supplierNo']) :""; $payNo= isset($post['payNo'])&&$post['payNo']!="" ? trim($post['payNo']) :""; $paystatus= isset($post['pay_status'])&&$post['pay_status']!="" ? $post['pay_status'] :""; $inv_status= isset($post['inv_status'])&&$post['inv_status']!="" ? $post['inv_status'] :""; if($startTime!=""){ $condition[]=["addtime",">=",$startTime]; } if($endTime!=""){ $condition[]=["addtime","<=",$endTime]; } if($supplierNo!=""){ $condition[]=["supplierNo","like","%$supplierNo%"]; } if($payNo!=""){ $condition[]=["payNo","like","%$payNo%"]; } if($paystatus!=""){ $condition[]=["pay_status","=",$paystatus]; } if($inv_status!=""){ $condition[]=["inv_status","=",$inv_status]; } $page = isset($post['page'])&&$post['page']!="" ? intval($post['page']) :1; $size = isset($post['size'])&&$post['size']!="" ? intval($post['size']) :10; $count = Db::name("pay")->where($condition)->count(); $total = ceil($count/$size)>1 ? ceil($count/$size) : 1; $page = $page>=$total?intval($total):$page; $list = Db::name("pay")->where($condition)->page(intval($page),$size)->order("addtime desc")->select(); $data=[]; foreach ($list as $key=>$value){ $value['ordeNum'] = Db::name("pay_info")->where([["payNo","=",$value["payNo"]],["is_del","=",0]])->count(); $data[]=$value; } return app_show(0,"获取成功",["list"=>$data,"count"=>$count]); } /** * 新建对账付款数据 * @return \think\Response */ public function PayAdd() { $post = $this->post; $cids = isset($post['cids'])&&$post['cids']!="" ? trim($post['cids']) :""; if($cids==""){ return error_show(1003,"参数cids不能为空"); } $cgdall =Db::name("cgd_info")->where(["id"=>explode(",",$cids),"status"=>0])->select()->toArray(); if(empty($cgdall)){ return error_show(1003,"采购单数据不能为空"); } $supplierNo= array_column($cgdall,"supplierNo"); $supplierName= array_column($cgdall,"supplierName"); if(count(array_unique($supplierNo))>1){ return error_show(1003,"采购单数据供应商不一致"); } $companyNo= array_column($cgdall,"companyNo"); $companyName= array_column($cgdall,"companyName"); if(count(array_unique($companyNo))>1){ return error_show(1003,"采购单数据业务公司不一致"); } $payNo = makeNo("PAY"); Db::startTrans(); try { $data=[]; $paydata=[ "payNo"=>$payNo, "apply_id"=>$this->uid, "apply_name"=>$this->uname, "total_fee"=>0, "supplierNo"=>$supplierNo[0], "supplierName"=>$supplierName[0], "companyNo"=>$companyNo[0], "companyName"=>$companyName[0], "wpay_fee"=>0, "apay_fee"=>0, "ainv_fee"=>0, "winv_fee"=>0, "remark"=>"", "status"=>1, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s"), ]; foreach ($cgdall as $key=>$value){ $temp=[]; $temp['cgdNo']=$value['sequenceNo']; $temp['total_fee']=$value['totalPrice']; $temp['apay_fee']=round($value['apay_fee'],2); $temp['wpay_fee']=round($value['wpay_fee'],2); $temp['winv_fee']=round($value['winv_fee'],2); $temp['ainv_fee']=round($value['ainv_fee'],2); $temp['payNo']=$payNo; $temp['addtime']=date("Y-m-d H:i:s"); $temp['updatetime']=date("Y-m-d H:i:s"); $data[]=$temp; $paydata['total_fee']+= $temp['total_fee']; $paydata['apay_fee']+= $temp['apay_fee']; $paydata['wpay_fee']+= $temp['wpay_fee']; $paydata['ainv_fee']+= $temp['ainv_fee']; $paydata['winv_fee']+= $temp['winv_fee']; $report=ReportCode::find(["cgdNo"=>$value['sequenceNo']]); $report->setField("payNo",$payNo); } $paydata['total_fee']= round($paydata['total_fee'],2); $paydata['apay_fee']= round($paydata['apay_fee'],2); $paydata['wpay_fee']= round($paydata['wpay_fee'],2); $paydata['ainv_fee']= round($paydata['ainv_fee'],2); $paydata['winv_fee']= round($paydata['winv_fee'],2); $info = Db::name("pay_info")->insertAll($data); if($info!=0){ $payDA=Db::name("pay")->insert($paydata); if($payDA){ $cgddup= Db::name("cgd_info")->where("id","in",$cids)->save(['status'=>1,"updatetime"=>date("Y-m-d H:i:s")]); if($cgddup){ Db::commit(); return app_show(0,"添加成功",["payNo"=>$payNo]); } } } Db::rollback(); return error_show(1003,"添加失败"); }catch(\Exception $e){ Db::rollback(); return error_show(1003,$e->getMessage()); } } /**对账单未审核前可需改编辑 * @return \think\response\Json|void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function PaySave() { $post = $this->post; $cids = isset($post['cids'])&&$post['cids']!="" ? trim($post['cids']) :""; if($cids==""){ return error_show(1003,"参数cids不能为空"); } $payNo = isset($post['payNo'])&&$post['payNo']!="" ? trim($post['payNo']) :""; if($payNo==""){ return error_show(1003,"参数 payNo 不能为空"); } $payinfo = Db::name("pay")->where(["payNo"=>$payNo,"is_del"=>0])->find(); if($payinfo==false){ return error_show(1003,"未找到对账单数据"); } if($payinfo['status']!=1){ return error_show(1003,"对账单已提交审核"); } $cgdall =Db::name("cgd_info")->where(["id"=>explode(",",$cids)])->select()->toArray(); if(empty($cgdall)){ return error_show(1003,"采购单数据不能为空"); } $supplierNo= array_column($cgdall,"supplierNo"); $supplierName= array_column($cgdall,"supplierName"); if(count(array_unique($supplierNo))>1){ return error_show(1003,"采购单数据供应商不一致"); } $companyNo= array_column($cgdall,"companyNo"); $companyName= array_column($cgdall,"companyName"); if(count(array_unique($companyNo))>1){ return error_show(1003,"采购单数据业务公司不一致"); } $cgdArr=array_column($cgdall,"sequenceNo"); $cgdNo = Db::name("pay_info")->where([["payNo","=",$payNo],["is_del","=",0]])->column("cgdNo"); $add=[]; $remove=[]; if(!empty($cgdNo)){ $remove = array_diff($cgdNo,$cgdArr); $add = array_diff($cgdArr,$cgdNo); } Db::startTrans(); try { $data=[]; $paydata=[ "supplierNo"=>$supplierNo[0], "supplierName"=>$supplierName[0], "companyNo"=>$companyNo[0], "companyName"=>$companyName[0], "wpay_fee"=>0, "apay_fee"=>0, "ainv_fee"=>0, "winv_fee"=>0, "total_fee"=>0, "updatetime"=>date("Y-m-d H:i:s") ]; foreach ($cgdall as $key=>$value){ if(!empty($add)&& in_array($value['sequenceNo'],$add)){ $temp=[]; $temp['cgdNo']=$value['sequenceNo']; $temp['total_fee']=$value['totalPrice']; $temp['apay_fee']=round($value['apay_fee'],2); $temp['wpay_fee']=round($value['wpay_fee'],2); $temp['winv_fee']=round($value['winv_fee'],2); $temp['ainv_fee']=round($value['ainv_fee'],2); $temp['payNo']=$payNo; $temp['addtime']=date("Y-m-d H:i:s"); $temp['updatetime']=date("Y-m-d H:i:s"); $data[]=$temp; $report=ReportCode::where(["cgdNo"=>$value['sequenceNo']])->find(); $report->setField("payNo",$payNo); } $paydata['total_fee']+= $value['totalPrice']; $paydata['apay_fee']+= $value['apay_fee']; $paydata['wpay_fee']+= $value['wpay_fee']; $paydata['ainv_fee']+= $value['ainv_fee']; $paydata['winv_fee']+= $value['winv_fee']; } $paydata['total_fee']= round($paydata['total_fee'],2); $paydata['apay_fee']= round($paydata['apay_fee'],2); $paydata['wpay_fee']= round($paydata['wpay_fee'],2); $paydata['ainv_fee']= round($paydata['ainv_fee'],2); $paydata['winv_fee']= round($paydata['winv_fee'],2); $payDA=Db::name("pay")->where($payinfo)->update($paydata); if($payDA){ if(!empty($remove)){ foreach ($remove as $value){ $report=ReportCode::where(["cgdNo"=>$value])->find(); $report->rmField("payNo",$payNo); } $payrm = Db::name("pay_info")->where(["cgdNo"=>$remove,"is_del"=>0])->update(["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")]); if($payrm==false){ Db::rollback(); return error_show(1004,"修改失败"); } $cgdrm= Db::name("cgd_info")->where([["sequenceNo","in",$remove],["status","=",1]])->save(['status'=>0, "updatetime"=>date("Y-m-d H:i:s")]); if($cgdrm==false){ Db::rollback(); return error_show(1005,"修改失败"); } } if(!empty($add)){ $cgddup= Db::name("cgd_info")->where([["sequenceNo","in",$add],["status","=",0]])->save(['status'=>1, "updatetime"=>date("Y-m-d H:i:s")]); if($cgddup==false){ Db::rollback(); return error_show(1006,"修改失败"); } } if(!empty($data)){ $info = Db::name("pay_info")->insertAll($data); if($info==false){ Db::rollback(); return error_show(1003,"修改失败"); } } Db::commit(); return app_show(0,"修改成功",["payNo"=>$payNo]); } Db::rollback(); return error_show(1007,"添加失败"); }catch(\Exception $e){ Db::rollback(); return error_show(1003,$e->getMessage()); } } /** * 对账付款状态审核 status 0 待提交 1 待采购审核 2 待财务审核 3 审核成功 4 采购驳回 5 财务驳回 * @param \think\Request $request * @return \think\Response */ public function PayStatus() { $post = $this->post; $payNo = isset($post['payNo']) && $post['payNo']!="" ? trim($post['payNo']):""; if($payNo==""){ return error_show(1004,"参数payNo不能为空"); } $status= isset($post['status']) && $post['status']!=="" ? trim($post['status']):""; if($status===""){ return error_show(1004,"参数status不能为空"); } $data = Db::name("pay")->where([["payNo","=",$payNo],["is_del","=",0]])->find(); if($data==false){ return error_show(1004,"未能找到对应数据"); } $remark = isset($post['remark']) && $post['remark']!=""? trim($post['remark']):""; $cgdNo = Db::name("pay_info")->where(["payNo"=>$payNo,"is_del"=>0])->column("cgdNo"); if(empty($cgdNo)){ return error_show(1004,"未能找到对应采购单数据"); } Db::startTrans(); try{ $update=[ "status"=>$status, "remark"=>$remark, "updatetime"=>date("Y-m-d H:i:s") ]; $result = Db::name("pay")->where("payNo","=",$payNo)->update($update); if($result){ if($status==4 || $status==5){ $cgdup =Db::name("cgd_info")->where(["sequenceNo"=>$cgdNo,"status"=>1])->update(['status'=>0,"updatetime"=>date("Y-m-d H:i:s")]); if($cgdup==false){ Db::rollback(); return error_show(1004,"对账驳回失败"); } foreach ($cgdNo as $value){ $report=ReportCode::where(["cgdNo"=>$value])->find(); $report->rmField("payNo",$payNo); } } Db::commit(); return app_show(0,"状态更新成功"); } Db::rollback(); return error_show(1004,"状态更新失败"); }catch (\Exception $e){ Db::rollback(); return error_show(1004,$e->getMessage()); } } /**删除未审核完成的对账单 * @return \think\response\Json|void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function payDel(){ $post = $this->post; $payNo = isset($post['payNo']) && $post['payNo']!="" ? trim($post['payNo']):""; if($payNo==""){ return error_show(1004,"参数payNo不能为空"); } $data = Db::name("pay")->where([["payNo","=",$payNo],["is_del","=",0]])->find(); if($data==false){ return error_show(1004,"未能找到对应数据"); } if($data['status']==4){ return error_show(1004,"对账单已审核通过"); } $cgdNo = Db::name("pay_info")->where(["payNo"=>$payNo,"is_del"=>0])->column("cgdNo"); if(empty($cgdNo)){ return error_show(1004,"未能找到对应采购单数据"); } Db::startTrans(); try{ $payDel = ["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")]; $pay =Db::name("pay")->where($data)->update($payDel); if($pay){ $infoup =Db::name("pay_info")->where(["cgdNo"=>$cgdNo,"is_del"=>0])->update($payDel); if($infoup==false){ Db::rollback(); return error_show(1004,"对账删除失败"); } $cgdup =Db::name("cgd_info")->where(["sequenceNo"=>$cgdNo,"status"=>1])->update(['status'=>0,"updatetime"=>date("Y-m-d H:i:s")]); if($cgdup==false){ Db::rollback(); return error_show(1004,"对账删除失败"); } foreach ($cgdNo as $value){ $report=ReportCode::where(["cgdNo"=>$value])->find(); $report->rmField("payNo",$payNo); } Db::commit(); return error_show(0,"对账删除成功"); } Db::rollback(); return error_show(1004,"对账删除失败"); }catch (\Exception $e){} } /** * * @param int $id * @return \think\Response */ public function stageAdd() { $post = $this->post; $payNo = isset($post['payNo'])&& $post['payNo']!="" ? trim($post['payNo']) :""; if($payNo==""){ return error_show(1004,"参数payNo 不能为空"); } $payinfo =Db::name("pay")->where(["payNo"=>$payNo,"is_del"=>0])->find(); if($payinfo==false){ return error_show(1004,"未找到对账信息"); } $cgdNo =Db::name("pay_info")->where(["payNo"=>$payNo,"is_del"=>0])->column("cgdNo"); if(empty($cgdNo)) return error_show(1004,"未找到对账采购单信息"); if($payinfo['status']!=3){ return error_show(1004,"对账未审核完成"); } $pay_fee = isset($post['pay_fee'])&& $post['pay_fee']!="" ? floatval($post['pay_fee']) :""; if($pay_fee==""){ return error_show(1004,"参数 pay_fee 不能为空或零"); } if($payinfo['wpay_fee']< $pay_fee){ return error_show(1004,"对账单未付金额不足"); } $dzno=makeNo("DZ"); Db::startTrans(); try { $ment =[ "payNo"=>$payNo, "dzNo"=>$dzno, "apply_id"=>$this->uid, "apply_name"=>$this->uname, "pay_fee"=>$pay_fee, "return_img"=>'', "status"=>1, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s") ]; $payment =Db::name("pay_payment")->insert($ment); if($payment){ $update=[ "pay_fee"=> round($payinfo['pay_fee']+$pay_fee,2), "wpay_fee"=> round($payinfo['wpay_fee']-$pay_fee,2), "updatetime"=>date("Y-m-d H:i:s") ]; $payup = Db::name("pay")->where($payinfo)->update($update); if($payup){ foreach ($cgdNo as $value){ $report=ReportCode::where(["cgdNo"=>$value])->find(); $report->setField("DzNo",$dzno); } Db::commit(); return app_show(0,"付款申请添加成功",["dzNo"=>$dzno]); } } Db::rollback(); return error_show(1004,"付款申请添加失败"); }catch (\Exception $e){ Db::rollback(); return error_show(1005,$e->getMessage()); } } /** * 付款申请审核状态 * 付款审核状态 0待发起 1待业务审核 2 待财务审核 3待付款回执 4 付款回执 5 业务驳回 6 财务驳回 * @param int $id * @return \think\Response */ public function stageStatus() { $post = $this->post; $dzNo = isset($post['dzNo'])&& $post['dzNo']!="" ? trim($post['dzNo']) :""; if($dzNo==""){ return error_show(1004,"参数 dzNo 不能为空"); } $status = isset($post['status'])&& $post['status']!="" ? intval($post['status']) :""; if($status==""){ return error_show(1004,"参数status 不能为空"); } if(!in_array($status,[0,1,2,3,4,5,6])){ return error_show(1004,"参数status 无效值"); } $payment= Db::name("pay_payment")->where([['dzNo',"=",$dzNo],['is_del',"=",0]])->find(); if($payment==false){ return error_show(1005,"未找到付款申请信息"); } $payinfo= Db::name("pay")->where([['payNo',"=",$payment['payNo']],['is_del',"=",0]])->find(); if($payinfo==false){ return error_show(1005,"未找到对账信息"); } if($payinfo['status']!=3){ return error_show(1005,"对账信息未完成审核"); } $cgdNo =Db::name("pay_info")->where(["payNo"=>$payment['payNo'],"is_del"=>0])->column("cgdNo"); if(empty($cgdNo)) return error_show(1004,"未找到对账采购单信息"); $remark = isset($post['remark'])? trim($post['remark']) :""; $image = isset($post['return_image'])? trim($post['return_image']) :""; $return_time = isset($post['return_time'])? trim($post['return_time']) :""; if($status==4){ if($image=="")return error_show(1005,"付款回单图片不能为空"); if($return_time=="")return error_show(1005,"付款回单时间不能为空"); if($payinfo['pay_fee']< $payment['pay_fee'])return error_show(1005,"对账付款申请金额有误,请确认对账申请金额"); } Db::startTrans(); try{ $mentupdate =["status"=>$status,"remark"=>$remark,"return_img"=>$image,"updatetime"=>date("Y-m-d H:i:s")]; if($status==4) $mentupdate['return_time'] = $return_time; $payup=Db::name("pay_payment")->where($payment)->update($mentupdate); if($payup){ if (in_array($status,[4,5,6])){ if($status==4){ //审核通过 扣减对账付款中的金额 添加到已付金额 $payupdate =[ "apay_fee"=>$payinfo['apay_fee']+$payment['pay_fee'], "pay_fee"=>$payinfo['pay_fee']-$payment['pay_fee'], "pay_status" => ($payinfo['pay_fee']-$payment['pay_fee'])==0 && $payinfo['wpay_fee']==0 ?3:2, "updatetime" => date("Y-m-d H:i:s") ]; } if($status==5||$status==6){//审核驳回 扣减对账付款中的金额 返回到待付金额中 $payupdate =[ "wpay_fee"=>$payinfo['wpay_fee']+$payment['pay_fee'], "pay_fee"=>$payinfo['pay_fee']-$payment['pay_fee'], "pay_status" => $payinfo['apay_fee']==0 ?1:2, "updatetime" => date("Y-m-d H:i:s") ]; foreach ($cgdNo as $value){ $report=ReportCode::where(["cgdNo"=>$value])->find(); $report->rmField("DzNo",$dzNo); } } $pay = Db::name("pay")->where($payinfo)->update($payupdate); if($pay==false){ Db::rollback(); return error_show(1003,"对账状态修改失败"); } } Db::commit(); return app_show(0,"状态修改成功"); }else{ Db::rollback(); return error_show(1003,"状态修改失败"); } }catch (\Exception $e){ Db::rollback(); return error_show(1008,$e->getMessage()); } } /**对账申请删除 * @return \think\response\Json|void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function stageDel(){ $post = $this->post; $dzNo = isset($post['dzNo'])&& $post['dzNo']!="" ? trim($post['dzNo']) :""; if($dzNo==""){ return error_show(1004,"参数 dzNo 不能为空"); } $payment= Db::name("pay_payment")->where([['dzNo',"=",$dzNo],['is_del',"=",0]])->find(); if($payment==false){ return error_show(1005,"未找到付款申请信息"); } $payinfo= Db::name("pay")->where([['payNo',"=",$payment['payNo']],['is_del',"=",0]])->find(); if($payinfo==false){ return error_show(1005,"未找到付款信息"); } $cgdNo =Db::name("pay_info")->where(["payNo"=>$payment['payNo'],"is_del"=>0])->column("cgdNo"); if(empty($cgdNo)) return error_show(1004,"未找到对账采购单信息"); Db::startTrans(); try{ $paym = Db::name("pay_payment")->where($payment)->update(["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")]); if($paym){ if(in_array($payment['status'],[1,2,3,4])){ if(in_array($payment['status'],[1,2,3])){ $payinfo['wpay_fee']+=$payment['pay_fee']; $payinfo['pay_fee']-=$payment['pay_fee']; $payinfo['updatetime']=date("Y-m-d H:i:s"); } if($payment['status']==4){ $payinfo['wpay_fee']+=$payment['pay_fee']; $payinfo['apay_fee']-=$payment['pay_fee']; $payinfo['pay_status']=$payinfo['apay_fee']==0? 1 : 2 ; $payinfo['updatetime']=date("Y-m-d H:i:s"); foreach ($cgdNo as $value){ $report=ReportCode::where(["cgdNo"=>$value])->find(); $report->rmField("DzNo",$dzNo); } } $pay = Db::name("pay")->save($payinfo); if($pay==false){ Db::rollback(); return error_show(1003,"对账状态修改失败"); } } Db::commit(); return app_show(0,"对账申请删除成功"); } }catch (\Exception $e){ Db::rollback(); return error_show(1003,$e->getMessage()); } } /** * 采购单列表 * @param \think\Request $request * @param int $id * @return \think\Response */ public function CgdList() { $post = $this->post; $condition = []; $check = checkRole($this->roleid,46); // if($check){ // $condition []=["ownerid","=",$this->uid]; // } $sequenceNo = isset($post['sequenceNo']) && $post['sequenceNo']!='' ? trim($post['sequenceNo']) :""; if($sequenceNo!=""){ $condition []=["sequenceNo","like","%$sequenceNo%"]; } $status = isset($post['status']) && $post['status']!=='' ? intval($post['status']) :""; if($status!==""){ $condition []=["status","=",$status]; } $companyNo = isset($post['companyNo']) && $post['companyNo']!='' ? trim($post['companyNo']) :""; if($companyNo!=""){ $condition []=["companyNo","like","%$companyNo%"]; } $companyName = isset($post['companyName']) && $post['companyName']!='' ? trim($post['companyName']) :""; if($companyName!=""){ $condition []=["companyName","like","%$companyName%"]; } $bkCode = isset($post['bkCode']) && $post['bkCode']!='' ? trim($post['bkCode']) :""; if($bkCode!=""){ $condition []=["bkCode","like","%$bkCode%"]; } $goodNo = isset($post['goodNo']) && $post['goodNo']!='' ? trim($post['goodNo']) :""; if($goodNo!=""){ $condition []=["goodNo","like","%$goodNo%"]; } $goodName = isset($post['goodName']) && $post['goodName']!='' ? trim($post['goodName']) :""; if($goodName!=""){ $condition []=["goodName","like","%$goodName%"]; } $supplierName = isset($post['supplierName']) && $post['supplierName']!='' ? trim($post['supplierName']) :""; if($supplierName!=""){ $condition []=["supplierName","like","%$supplierName%"]; } $supplierNo = isset($post['supplierNo']) && $post['supplierNo']!='' ? trim($post['supplierNo']) :""; if($supplierNo!=""){ $condition []=["supplierNo","like","%$supplierNo%"]; } $page = isset($post['page'])&&$post['page']!="" ? intval($post['page']) :0; $size = isset($post['size'])&&$post['size']!="" ? intval($post['size']) :10; $count = Db::name("cgd_info")->where($condition)->count(); $total = ceil($count/$size); $page = $page>=$total?intval($total):$page; $list = Db::name("cgd_info")->where($condition)->page($page,$size)->order('createdTime desc')->select(); return app_show(0,"获取成功",["list"=>$list,"count"=>$count]); } //todo public function PayInfo() { $post = $this->post; $token = isset($post['token']) ? trim($post['token']) : ""; if($token==""){ return error_show(101,'token不能为空'); } $effetc = VerifyTokens($token); if(!empty($effetc) && $effetc['code']!=0){ return error_show($effetc['code'],$effetc['message']); } $sid = isset($post['sid'])&& $post['sid']!="" ? intval($post['sid']) :""; if($sid==""){ return error_show(1004,"参数sid 不能为空"); } $payinfo = Db::name("pay_ment")->where("sid","=",$sid)->field("id,payNo,contector,supplierNo,name,pay_method,pay_rate,dpay_fee,inv_rate,rate,dpay_rate,pay_stages,return_img,remark,pay_status,dstatus,pay_remark")->find(); if(empty($payinfo)){ return error_show(1004,"付款申请信息未找到"); } $payinfo['return_img'] = isset($payinfo['return_img']) && $payinfo['return_img']!="" ? explode(",",$payinfo['return_img']):""; $paylist = Db::name("pay_info")->where([["payNo","=",$payinfo['payNo']],["status","=",1]])->column("sequenceNo"); $payinfo['list']=[]; if($paylist){ $list = Db::name("cgd_info")->alias('a')->join('cfp_supplier_info b','a.ShortText1617861287265=b.code','left') ->join("cfp_cgd_inv c",'c.cgdNo=a.sequenceNo','left') ->where([["a.sequenceNo","in",$paylist],["a.status","=",1]])->field("a.id, `a`.`sequenceNo` AS `sequenceNo`, `a`.`ownerName` AS `ownerName`, `a`.`department` AS `department`, b.code as supplierNo, `a`.`ShortText1618315935182` AS `cgdNO`, `b`.`name` AS `name`, `b`.`contector` AS `contector`, `b`.`mobile` AS `mobile`, `a`.`ShortText1617861001482` AS `goodNo`, `a`.`ShortText1617861966146` AS `goodName`, `a`.`ShortText1617865626160` AS `goodType`, `a`.`ShortText1617865633070` AS `goodBank`, `a`.`ShortText1617865675342` AS `goodModel`, `a`.`ShortText1617865678025` AS `goodMaterial`, `a`.`ShortText1617865680605` AS `goodColor`, `a`.`text1618268357055` AS `goodDesc`, `a`.`ShortText1617865685744` AS `goodUnit`, `a`.`ShortText1618240134229` AS `goodCat`, ifnull( `a`.`Number1618240480148`, '0' ) AS `weight`, ifnull( `a`.`Number1618240458074`, '0' ) AS `price`, `a`.`ShortText1617866158120` AS `isDiff`, `a`.`number1618240356104` AS `workDay`, `a`.`ShortText1617865688485` AS `taxPoint`, `a`.`Number1617865804813` AS `nakedPrice`, `a`.`Number1617865807879` AS `markPrice`, `a`.`Number1617865810822` AS `packPrice`, `a`.`Number1617865813284` AS `certPrice`, `a`.`Number1617865816181` AS `openPrice`, `a`.`number1618240204358` AS `craftPrice`, `a`.`number1618240287778` AS `postPrice`, `a`.`Number1617865818517` AS `totalPrice`, `a`.`Number1618240685904` AS `purchasePrice`, `a`.`Number1618240600907` AS `orderNum`, `a`.`Number1618330470625` AS `pay_fee`, `a`.`Number1618330472961` AS `wait_fee`, `a`.`Number1618330541286` AS `inv_open_fee`, `a`.`Number1618330543270` AS `inv_wait_fee`, `a`.`ShortText1619463188366` AS `payinfo`, `a`.`ShortText1619463208482` AS `invinfo`, a.th_status as th_info, a.ShortText1618859321070 as send_info, `a`.`Number1619632826654` AS `diff_fee`, `a`.`Number1619632830397` AS `diff_info`, createdTime, a.Date1618315953443 as DownTime, IF (( `a`.`sequenceStatus` = 'COMPLETED' ), 2, 1 ) AS `order_status`, ifnull( `c`.`companyNo`, '' ) AS `inv_company`, ifnull( `c`.`status`, '0' ) AS `inv_status`, ifnull( `c`.`id`, '0' ) AS `invid`") ->select(); $data=[]; foreach ($list as $key=>$value){ $value['pay_price'] =sprintf( "%.2f",$value['totalPrice']*$value['orderNum']); if($value['inv_company']!=""){ $invcom = Db::name("company_info")->where([['companyNo',"=",$value['inv_company']],['status',"=",1]]) ->find(); $value['inv_company_name'] =isset($invcom['company_name']) ? $invcom['company_name']:""; }else{ $value['inv_company_name'] =""; } $data[]=$value; } $payinfo['list']=$data; } return app_show(0,"获取成功",$payinfo); } /**发票新建添加 * @return \think\response\Json|void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function invAdd(){ $post = $this->post; $payNo = isset($post['payNo'])&&$post['payNo']!='' ? $post['payNo']:""; if($payNo==""){ return error_show(1004,"参数 payNo 不能为空"); } $payinfo =Db::name("pay")->where(["payNo"=>$payNo,"is_del"=>0])->find(); if($payinfo==false){ return error_show(1004,"对账单数据未找到"); } if($payinfo['status']!=3){ return error_show(1004,"对账单数据未完成审核"); } $type = isset($post['invType']) && $post['invType']!="" ? intval($post['invType']):""; if($type==''){ return error_show(1004,"参数 invType 不能为空"); } $invNumber =isset($post['invNumber'])&& $post['invNumber']!='' ? trim($post['invNumber']):""; $invCode =isset($post['invCode'])&& $post['invCode']!='' ? trim($post['invCode']):""; $checkNumber =isset($post['checkNumber'])&& $post['checkNumber']!='' ? trim($post['checkNumber']):""; $openTime =isset($post['open_time'])&& $post['open_time']!='' ? trim($post['open_time']):""; if($type==1){ if($invNumber=="") return error_show(1004,"参数 invNumber 不能为空"); if($invCode=="") return error_show(1004,"参数 invCode 不能为空"); // if($checkNumber=="") return error_show(1004,"参数 checkNumber 不能为空"); if($openTime=="") return error_show(1004,"参数 open_time 不能为空"); } $invimg = isset($post['inv_img'])&& $post['inv_img']!='' ? trim($post['inv_img']):""; $invName = isset($post['invName'])&& $post['invName']!='' ? trim($post['invName']):""; if($type==2){ if($invimg=="")return error_show(1004,"参数 inv_img 不能为空"); if($invName=="")return error_show(1004,"参数 invName 不能为空"); } if ($type==3){ } $cgdNo =Db::name("pay_info")->where(["payNo"=>$payNo,"is_del"=>0])->column("cgdNo"); if(empty($cgdNo)) return error_show(1004,"未找到对账采购单信息"); Db::startTrans(); try{ $hpNo=makeNo("hp"); $data=[ "payNo"=>$payNo, "hpNo"=>$hpNo, "apply_id"=>$this->uid, "apply_name"=>$this->uname, "inv_fee"=> '', "invType"=> $type, "invoiceType"=>0, "inv_img"=>$invimg, "invName"=>$invName, "invoiceNumber"=>$invNumber, "invoiceCode"=>$invCode, "checkNumber"=>$checkNumber, "open_time"=>$openTime, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s") ]; $inadd =Db::name("pay_invoice")->insert($data); if ($inadd){ foreach ($cgdNo as $value){ $report=ReportCode::where(["cgdNo"=>$value])->find(); $report->setField("hpNo",$hpNo); } Db::commit(); return app_show(0,"回票新建成功",['hpNo'=>$hpNo]); } Db::rollback(); return error_show(1004,"回票申请新建失败"); }catch (\Exception $e){ Db::rollback(); return error_show(1004,$e->getMessage()); } } /** * 发票审核状态 * 0 上传发票,1待识别验证 2 待校验识别 3 待财务审核 6 待认证 7认证成功待确认完成 8回票完成 9识别失败 10 验证失败 11 财务驳回 12 认证失败 * @return \think\response\Json|void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function invStatus(){ $post = $this->post; $hpNo = isset($post['hpNo'])&& $post['hpNo']!="" ? $post['hpNo'] :""; if($hpNo==""){ return error_show(1004,"参数 hpNo 不能为空"); } $status = isset($post['status'])&& $post['status']!="" ? intval($post['status']) :""; if($status==""){ return error_show(1004,"参数status 不能为空"); } if(!in_array($status,[0,1,2,3,4,5,6,7,8,9,10,11,12])){ return error_show(1004,"参数status 无效值"); } $payment= Db::name("pay_invoice")->where([['hpNo',"=",$hpNo],['is_del',"=",0]])->find(); if($payment==false){ return error_show(1005,"未找到回票申请信息"); } $payinfo= Db::name("pay")->where([['payNo',"=",$payment['payNo']],['is_del',"=",0]])->find(); if($payinfo==false){ return error_show(1005,"未找到对账信息"); } if($payinfo['status']!=3){ return error_show(1005,"对账信息未完成审核"); } $cgdNo =Db::name("pay_info")->where(["payNo"=>$payment['payNo'],"is_del"=>0])->column("cgdNo"); if(empty($cgdNo)) return error_show(1004,"未找到对账采购单信息"); if($payinfo['inv_fee']< $payment['inv_fee'])return error_show(1005,"对账回票申请金额有误,请确认回票申请金额"); Db::startTrans(); try { $invup =["status"=>$status,"updatetime"=>date("Y-m-d H:i:s")]; $inv =Db::name("pay_invoice")->where($payment)->update($invup); if($inv){ if($status==8){ $payupdate =[ "ainv_fee"=>$payinfo['ainv_fee']+$payment['inv_fee'], "inv_fee"=>$payinfo['inv_fee']-$payment['inv_fee'], "inv_status" => ($payinfo['inv_fee']-$payment['inv_fee'])==0 && $payinfo['winv_fee']==0?3:2, "updatetime" => date("Y-m-d H:i:s") ]; $pay =Db::name("pay")->where($payinfo)->update($payupdate); if($pay==false){ Db::rollback(); return error_show(1003,"回票申请状态更新成功"); } } if($status==11){ $payupdate =[ "winv_fee"=>$payinfo['winv_fee']+$payment['inv_fee'], "inv_fee"=>$payinfo['inv_fee']-$payment['inv_fee'], "inv_status" => ($payinfo['inv_fee']-$payment['inv_fee'])==0 && $payinfo['ainv_fee']==0?1:2, "updatetime" => date("Y-m-d H:i:s") ]; $pay =Db::name("pay")->where($payinfo)->update($payupdate); if($pay==false){ Db::rollback(); return error_show(1003,"回票申请状态更新成功"); } foreach ($cgdNo as $value){ $report=ReportCode::where(["cgdNo"=>$value])->find(); $report->rmField("hpNo",$hpNo); } } Db::commit(); return app_show(0,"回票申请更新成功"); } Db::rollback(); return error_show(1003,"回票申请状态更新成功"); }catch (\Exception $e){ Db::rollback(); return error_show(1004,$e->getMessage()); } } /**发票列表识别 * @param int $id * @return \think\Response */ public function InvList() { $post = $this->post; $condition = [["is_del","=",0 ]]; $invtype = isset($post['invType'])&&$post['invType']!='' ? intval($post['invType']):""; if ($invtype!=''){ $condition[]=["invType","=",$invtype]; } $hpNo = isset($post['hpNo'])&&$post['hpNo']!='' ? trim($post['hpNo']):""; if ($hpNo!=''){ $condition[]=["hpNo","like","%$hpNo%"]; } $invoiceType = isset($post['invoiceType'])&&$post['invoiceType']!='' ? intval($post['invoiceType']):""; if ($invoiceType!=''){ $condition[]=["invoiceType","=",$invoiceType]; } $status = isset($post['status'])&&$post['status']!="" ? intval($post['status']):""; if($status!=""){ $condition[]=["status","=",$status]; } $invNumber = isset($post['invNumber'])&&$post['invNumber']!="" ? trim($post['invNumber']):""; if($invNumber!=''){ $condition[]=["invoiceNumber","=",$invNumber]; } $invCode = isset($post['invCode'])&&$post['invCode']!="" ? trim($post['invCode']):""; if($invCode!=''){ $condition[]=["invoiceCode","=",$invCode]; } $start = isset($post['start']) && $post['start']!="" ? $post['start'] :""; if($start!=""){ $condition[]=["addtime",">=",$start." 00:00:00"]; } $end = isset($post['end']) && $post['end']!="" ? $post['end'] :""; if($end!=""){ $condition[]=["addtime","<=",$end." 23:59:59"]; } $open_start = isset($post['open_start']) && $post['open_start']!="" ? $post['open_start'] :""; if($open_start!=""){ $condition[]=["open_time",">=",$open_start." 00:00:00"]; } $open_end = isset($post['open_end']) && $post['open_end']!="" ? $post['open_end'] :""; if($open_end!=""){ $condition[]=["open_time","<=",$open_end." 23:59:59"]; } $apply_id = isset($post['apply_id']) && $post['apply_id']!="" ? $post['apply_id'] :""; if($apply_id!=""){ $condition[]=["apply_id","=",$apply_id]; } $apply_name = isset($post['apply_name']) && $post['apply_name']!="" ? trim($post['apply_name']):""; if($apply_name!=""){ $condition[]=["apply_name","like","%$apply_name%"]; } $page = isset($post['page'])&&$post['page']!="" ? intval($post['page']):1; $size = isset($post['size'])&&$post['size']!="" ? intval($post['size']):10; $count =Db::name("pay_invoice")->where($condition)->count(); $total = ceil($count/$size); $page = $page>$total? intval($total):$page; $list = Db::name("pay_invoice")->where($condition)->page($page,$size)->select(); return app_show(0,"获取成功",["list"=>$list,"count"=>$count]); } /**发票删除 * @return \think\response\Json|void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function invDel(){ $post = $this->post; $hpNo = isset($post['hpNo'])&&$post['hpNo']!="" ? trim($post['hpNo']) :""; if ($hpNo==""){ return error_show(1004,"参数 hpNo 不能为空"); } $payinv =Db::name("pay_invoice")->where(["hpNo"=>$hpNo,"is_del"=>0])->find(); if($payinv==false){ return error_show(1004,"对账单回票申请未找到数据"); } $payinfo= Db::name("pay")->where([['payNo',"=",$payinv['payNo']],['is_del',"=",0]])->find(); if($payinfo==false){ return error_show(1005,"未找到对账信息"); } if($payinfo['status']!=3){ return error_show(1005,"对账信息未完成审核"); } $cgdNo =Db::name("pay_info")->where(["payNo"=>$payinv['payNo'],"is_del"=>0])->column("cgdNo"); if(empty($cgdNo)) return error_show(1004,"未找到对账采购单信息"); Db::startTrans(); try{ $update=["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")]; $invup =Db::name("pay_invoice")->where($payinv)->update($update); if($invup){ if($payinv['status']==8){ if($payinfo['ainv_fee']< $payinv['inv_fee']){ Db::rollback(); return error_show(1005,"对账回票申请金额有误,请确认回票申请金额"); } $payupdate =[ "ainv_fee"=>$payinfo['ainv_fee']-$payinv['inv_fee'], "winv_fee"=>$payinfo['winv_fee']+$payinv['inv_fee'], "inv_status" => ($payinfo['ainv_fee']-$payinv['inv_fee'])==0?1:2, "updatetime" => date("Y-m-d H:i:s") ]; $pay =Db::name("pay")->where($payinfo)->update($payupdate); if($pay==false){ Db::rollback(); return error_show(1003,"删除失败"); } foreach ($cgdNo as $value){ $report=ReportCode::where(["cgdNo"=>$value])->find(); $report->rmField("hpNo",$hpNo); } } Db::commit(); return app_show(0,"删除成功"); } }catch (\Exception $e){ Db::rollback(); return error_show(1003,$e->getMessage()); } } public function UnPay(){ $post = $this->post; $token = isset($post['token']) ? trim($post['token']) : ""; if($token==""){ return error_show(101,'token不能为空'); } $effetc = VerifyTokens($token); if(!empty($effetc) && $effetc['code']!=0){ return error_show($effetc['code'],$effetc['message']); } $codeNo = isset($post['id'])&&$post['id']!=="" ? trim($post['id']) :''; if($codeNo===""){ return error_show(1004,'参数id 不能为空'); } $update = Db::name('cgd_info')->where("id","in",$codeNo)->update(['status'=>2,"updatetime"=>date("Y-m-d H:i:s")]); // echo Db::name('cgd_info')->getLastSql(); if($update){ return app_show(0,'更新成功'); }else{ return error_show(1004,'更新失败'); } } }