wugg 2 years ago
parent
commit
34893d08d9
1 changed files with 56 additions and 11 deletions
  1. 56 11
      app/admin/controller/Payment.php

+ 56 - 11
app/admin/controller/Payment.php

@@ -5,7 +5,7 @@ namespace app\admin\controller;
 
 use app\admin\BaseController;
 use app\admin\model\ReportCode;
-use think\App;use think\facade\Db;use think\facade\Validate;
+use think\App;use think\Exception;use think\facade\Db;use think\facade\Validate;
 
 class Payment extends BaseController
 {
@@ -458,7 +458,7 @@ class Payment extends BaseController
     }
 
     /**
-     * 对账付款状态审核 status 0 待提交 1 待买方审核 2 审核成功 3驳回
+     * 对账付款状态审核 status 0 待提交 1 待买方审核 2 审核成功 3驳回 4 退款
      * @param  \think\Request  $request
      * @return \think\Response
      */
@@ -1043,7 +1043,7 @@ class Payment extends BaseController
 
     /**
 	 * 发票审核状态
-	 *  1待系统验证 2 买方公司审核3带买方公司认证 4 认证成功 5验证失败 6买方审核驳回 7 认证失败 8 回票流程终止 9 验证超次数
+	 *  1待系统验证 2 买方公司审核3带买方公司认证 4 认证成功 5验证失败 6买方审核驳回 7 认证失败 8 回票流程终止 9 验证超次数 10 回票已退
      * @return \think\response\Json|void
      * @throws \think\db\exception\DataNotFoundException
      * @throws \think\db\exception\DbException
@@ -1467,6 +1467,26 @@ class Payment extends BaseController
 		if($valide->check($param)==false)return error_show(1004,$valide->getError());
 		$returninfo =Db::name("pay_return")->where(["is_del"=>0,"returnCode"=>$param['returnCode']])->findOrEmpty();
 		if(empty($returninfo))return error_show(1004,"退票详情未找到");
+		Db::startTrans();
+		try{
+			if($param['status']==2){
+			$invinfo =Db::name("pay_invoice")->where(["hpNo"=>$returninfo['orderCode'],"is_del"=>0])->findOrEmpty();
+			if(empty($invinfo))throw new Exception("回票详情未找到");
+			$pay =Db::name("pay")->where(["payNo"=>$returninfo['payNo'],"is_del"=>0])->findOrEmpty();
+			if(empty($pay))throw new Exception("对账详情未找到");
+			$invup =Db::name("pay_invoice")->where($invinfo)->update(["status"=>10,"updatetime"=>date("Y-m-d H:i:s")]);
+			if($invup==false)throw new Exception("回票更新失败");
+
+			$paydata=[
+				 "ainv_fee"=>$pay['ainv_fee']-$invinfo['inv_fee'],
+                  "winv_fee"=>$pay['winv_fee']+$invinfo['inv_fee'],
+                  "inv_status" => $pay['inv_fee']==0 &&($pay['ainv_fee']-$invinfo['inv_fee'])==0?1:2,
+                   "updatetime" => date("Y-m-d H:i:s")
+			];
+			$oayup =Db::name("pay")->where($pay)->update($paydata);
+			if($oayup==false)throw new Exception("对账更新失败");
+
+		}
 		$update=[
 			"status"=>$param['status'],
 			"remark"=>$param['remark'],
@@ -1474,11 +1494,14 @@ class Payment extends BaseController
 			"updatetime"=>date("Y-m-d H:i:s")
 			];
 		$up =Db::name("pay_return")->where($returninfo)->update($update);
-		if($up){
-			return app_show(0,"退票申请审核成功");
-		}else{
-			return error_show(1004,"退票申请审核失败");
+		if($up==false)throw new Exception("退票申请审核失败");
+		Db::commit();
+		return app_show(0,"退票申请审核成功");
+		}catch (\Exception $e){
+			Db::rollback();
+			return error_show(1005,$e->getMessage());
 		}
+
     }
 
      public function hpinvReturnInfo(){
@@ -1568,6 +1591,26 @@ class Payment extends BaseController
 		if($valide->check($param)==false)return error_show(1004,$valide->getError());
 		$returninfo =Db::name("pay_return")->where(["is_del"=>0,"returnCode"=>$param['returnCode']])->findOrEmpty();
 		if(empty($returninfo))return error_show(1004,"退票详情未找到");
+		Db::startTrans();
+		try{
+			if($param['status']==2){
+			$invinfo =Db::name("pay_payment")->where(["dzNo"=>$returninfo['orderCode'],"is_del"=>0])->findOrEmpty();
+			if(empty($invinfo))throw new Exception("付款详情未找到");
+			$pay =Db::name("pay")->where(["payNo"=>$returninfo['payNo'],"is_del"=>0])->findOrEmpty();
+			if(empty($pay))throw new Exception("对账详情未找到");
+			$invup =Db::name("pay_payment")->where($invinfo)->update(["status"=>4,"updatetime"=>date("Y-m-d H:i:s")]);
+			if($invup==false)throw new Exception("付款更新失败");
+
+			$paydata=[
+				 "apay_fee"=>$pay['apay_fee']-$invinfo['pay_fee'],
+                  "wpay_fee"=>$pay['wpay_fee']+$invinfo['pay_fee'],
+                  "pay_status" => $pay['pay_fee']==0 &&($pay['apay_fee']-$invinfo['pay_fee'])==0?1:2,
+                   "updatetime" => date("Y-m-d H:i:s")
+			];
+			$oayup =Db::name("pay")->where($pay)->update($paydata);
+			if($oayup==false)throw new Exception("对账更新失败");
+
+		}
 		$update=[
 			"status"=>$param['status'],
 			"remark"=>$param['remark'],
@@ -1575,10 +1618,12 @@ class Payment extends BaseController
 			"updatetime"=>date("Y-m-d H:i:s")
 			];
 		$up =Db::name("pay_return")->where($returninfo)->update($update);
-		if($up){
-			return app_show(0,"退款申请审核成功");
-		}else{
-			return error_show(1004,"退款申请审核失败");
+		if($up==false)throw new Exception("退款申请审核失败");
+		Db::commit();
+		return app_show(0,"退款申请审核成功");
+		}catch (\Exception $e){
+			Db::rollback();
+			return error_show(1005,$e->getMessage());
 		}
     }