wugg 2 years ago
parent
commit
3624d34f5c
2 changed files with 63 additions and 5 deletions
  1. 62 5
      app/admin/controller/Payment.php
  2. 1 0
      app/admin/route/app.php

+ 62 - 5
app/admin/controller/Payment.php

@@ -490,6 +490,12 @@ class Payment extends BaseController
         $cgdNo = Db::name("pay_info")->where(["payNo"=>$payNo,"is_del"=>0])->column("cgdNo");
        if(empty($cgdNo)){
            return error_show(1004,"未能找到对应采购单数据");
+       }
+       if($status==4){
+       	    $stages = Db::name("pay_payment")->where(['status'=>[0,1,2,3],"payNo"=>$payNo,"is_del"=>0])->findOrEmpty();
+       	    if(!empty($stages)) return error_show(1004,"对账单存在未解除的付款申请单");
+       	    $hpinv = Db::name("pay_invoice")->where(['status'=>[0,1,2,3,4,9],"payNo"=>$payNo,"is_del"=>0])->findOrEmpty();
+       	    if(!empty($hpinv)) return error_show(1004,"对账单存在未解除的回票申请单");
        }
         Db::startTrans();
         try{
@@ -806,7 +812,7 @@ class Payment extends BaseController
         $post = $this->post;
         $condition = [["cgdSource|cgdType","<>",1],['is_del',"=",0]];
 
-        $check = checkRole($this->roleid,46);
+//        $check = checkRole($this->roleid,46);
 //        if($check){
 //            $condition []=["ownerid","=",$this->uid];
 //        }
@@ -1110,7 +1116,7 @@ class Payment extends BaseController
                         $pay =Db::name("pay")->where($payinfo)->update($payupdate);
                         if($pay==false){
                             Db::rollback();
-                            return error_show(1003,"回票申请状态更新成功");
+                            return error_show(1003,"回票申请状态更新失败");
                         }
                 }
                 if($status==6 || $status==5|| $status==7){
@@ -1123,7 +1129,7 @@ class Payment extends BaseController
                     $pay =Db::name("pay")->where($payinfo)->update($payupdate);
                         if($pay==false){
                             Db::rollback();
-                            return error_show(1003,"回票申请状态更新成功");
+                            return error_show(1003,"回票申请状态更新失败");
                         }
                     foreach ($cgdNo as $value){
                        $report=ReportCode::where(["cgdNo"=>$value])->find();
@@ -1134,7 +1140,7 @@ class Payment extends BaseController
                 return app_show(0,"回票申请更新成功");
             }
                      Db::rollback();
-                    return error_show(1003,"回票申请状态更新成功");
+                    return error_show(1003,"回票申请状态更新失败");
         }catch (\Exception $e){
             Db::rollback();
             return error_show(1004,$e->getMessage());
@@ -1532,7 +1538,7 @@ class Payment extends BaseController
 		return app_show(0,"退票申请获取成功",$info);
     }
 
-
+	//付款退回
     public function stageReturn(){
     	$param =$this->request->only(["dzNo"=>"","reason"=>""],"post","trim");
 		$valide=Validate::rule([
@@ -1656,4 +1662,55 @@ class Payment extends BaseController
 		->findOrEmpty();
 		return app_show(0,"退款申请获取成功",$info);
     }
+    /**批量上传待认证发票
+    * @param hpNo array 回票申请编号集合 必传
+    * @param relaComNo string 业务公司编号  企业账户
+    * @param companyNo string 业务公司编号 超管账户
+	* @return \think\response\Json|void
+	*/
+
+    public function hpBatchImport(){
+    	$post=$this->request->only(["hpNo"=>[],"relaComNo"=>"","companyNo"=>""],"post");
+    	$valid =Validate::rule([
+    		"hpNo|回票申请编号集合"=>"require|array",
+    		"relaComNo|关联公司"=>"max:255",
+    		"companyNo|公司编号"=>"max:255",
+    		]);
+    	if($valid->check($post)==false)return error_show(1004,$valid->getError());
+		if(empty($post['hpNo'])) return error_show(1004,'回票申请编号集合不能为空');
+		$companyNo = $post["relaComNo"]??$post['companyNo'];
+		if($companyNo =="") return error_show(1004,'业务公司编号不能为空');
+		$payArr=Db::name("pay_invoice")->alias("a")
+		->leftJoin("pay b","a.payNo=b.payNo and b.is_del=0 and b.status=2")->where(["b.hpNo"=>$post['hpNo'],
+		"b.is_del"=>0])->column("a.id,a.payNo,a.hpNo,a.invoiceType,a.inv_fee as invoice_fee,a.status,b.inv_status,b.inv_fee,b.companyNo,b.ainv_fee,b.winv_fee");
+		if(empty($payArr))return error_show(1004,'回票申请数据未找到');
+		Db::startTrans();
+		try{
+			$invIdArr=[];
+			foreach ($payArr as $value){
+				if($value['companyNo']=='') throw new Exception("{$value['hpNo']}对账信息有误");
+				if($value['companyNo']!=$companyNo) throw new Exception("{$value['hpNo']}不属于当前业务公司发票");
+				if($value['status']!='3') throw new Exception("{$value['hpNo']}状态有误");
+				if($value['invoice_fee']>$value['inv_fee']) throw new Exception("{$value['hpNo']}对账单开票中金额不足");
+				$payupdate =[
+	                            "ainv_fee"=>$value['ainv_fee']+$value['invoice_fee'],
+	                            "inv_fee"=>$value['inv_fee']-$value['invoice_fee'],
+	                             "inv_status" => ($value['inv_fee']-$value['invoice_fee'])==0 && $value['winv_fee']==0?3:2,
+	                             "updatetime" => date("Y-m-d H:i:s")
+	                        ];
+				$where=	['payNo'=>$value['payNo'],"inv_status"=>$value['inv_status'],"companyNo"=>$companyNo,"status"=>2,"is_del"=>0];
+				$pay =Db::name("pay")->where($where)->update($payupdate);
+	             if($pay==false) throw new Exception("{$value['hpNo']}回票申请对账单状态更新失败");
+	             $invIdArr[]=$value['id'];
+			}
+			$update = Db::name("pay_invoice")->where(["id"=>$invIdArr,"status"=>3,"is_del"=>0])->update(["status"=>4,"updatetime"=>date("Y-m-d H:i:s")]);
+			if($update==false) throw new Exception("回票申请状态更新更新失败");
+			Db::commit();
+		    return app_show(0,"回票申请认证成功");
+		}catch (\Exception $e){
+			Db::rollback();
+			return error_show(1004,$e->getMessage());
+		}
+
+	}
 }

+ 1 - 0
app/admin/route/app.php

@@ -90,6 +90,7 @@ Route::rule("invstatus","admin/Payment/invStatus");
 Route::rule("invlist","admin/Payment/InvList");
 Route::rule("invdel","admin/Payment/invDel");
 Route::rule("cgdticket","admin/Payment/ticketInfo");
+Route::rule("hpbatchimport","admin/Payment/hpBatchImport");
 
 Route::rule("orderinvadd","admin/OrderInv/create");
 Route::rule("orderinvstatus","admin/OrderInv/status");