From 2e97359fdeec69054352263d768d4263bb7b1148 Mon Sep 17 00:00:00 2001
From: weiz <736250432@qq.com>
Date: Mon, 19 Feb 2024 10:57:48 +0800
Subject: [PATCH] update

---
 app/adminapi/logic/oa/FlowApproveLogic.php | 117 +++++++--------------
 1 file changed, 38 insertions(+), 79 deletions(-)

diff --git a/app/adminapi/logic/oa/FlowApproveLogic.php b/app/adminapi/logic/oa/FlowApproveLogic.php
index 61c5a605b..fe3eae23f 100644
--- a/app/adminapi/logic/oa/FlowApproveLogic.php
+++ b/app/adminapi/logic/oa/FlowApproveLogic.php
@@ -132,6 +132,8 @@ class FlowApproveLogic extends BaseLogic
 		}
 		//获取当前审批信息的审批步骤
 		$current_step = FlowStep::where('approve_id',$params['id'])->where('is_active',1)->findOrEmpty();
+		//获取下一步步骤
+		$next_step = FlowStep::where('approve_id',$params['id'])->where('sort',$current_step['sort']+1)->findOrEmpty();
 		$current_check_user = explode(',',$current_step['flow_user']);
 		//获取当前审批信息的步骤总数
 		$step_count = FlowStep::where('approve_id',$params['id'])->count();
@@ -155,10 +157,7 @@ class FlowApproveLogic extends BaseLogic
 				//判断当前审批步骤类型
 				switch($current_step['flow_step']){
 					case 1://当前部门负责人审批
-						//判断当前审核步骤是否是最后一步;
-						//1、如果是最后一步,如果当前用户审核通过则将该记录设置为审核通过,如果当前用户未审核通过则则将该记录设置为审核不通过,流程结束
-						//2、如果不是最后一步,如果当前用户审核通过则将该记录设置为审核中,流程进入下一步,如果当前用户未审核通过则则将该记录设置为审核不通过,流程结束
-						if(($current_step['sort']+1) == $step_count){
+						if($next_step->isEmpty()){
 							FlowApprove::where('id',$params['id'])->update([
 								'check_status' => $params['check_status'] == 1 ? 2 : 3,
 								'update_time' => $check_time,
@@ -171,52 +170,31 @@ class FlowApproveLogic extends BaseLogic
 							//设置下一步
 							if($params['check_status'] == 1){
 								FlowStep::where('id',$current_step['id'])->update(['is_active'=>0]);
-								FlowStep::where('approve_id',$params['id'])->where('sort',$current_step['sort']+1)->update(['is_active'=>1]);
+								FlowStep::where('id',$next_step['id'])->update(['is_active'=>1]);
 							}
 						}
 						break;
 					case 2: //指定人或签
-						//判断当前记录除当前用户外,是否都审批了,
-						//1、如果都审批了,则判断其他用户是否有审批通过的
-						//1-1、如果其他用户都没有审批通过,则判断当前用户是否审批通过通过,如果当前用户审批通过,则判断当前审核步骤是否是最后一步,
-						//1-1-1-1、如果是最后一步,则该记录审批通过,流程结束
-						//1-1-1-2、如果不是最后一步,则该记录设置为审批中,流程设置为下一步
-						//1-1-2、如果当前用户审批不通过,则该记录审批不通过,流程结束
-						//1-2、如果其他用户有一位审批通过,则不管当前用户是否审批通过,则判断当前审核步骤是否是最后一步,如果是最后一步,该记录设置为审核通过,如果不是最后一步,该记录设置为审核中,流程设置为下一步
-						//2、如果没审批完,则不管当前用户是否审批通过也不管当前审核步骤是否是最后一步,该记录都设置为审批中,不设置下一步操作
-						//获取当前记录的审核记录数
-						$check_record_count = FlowRecord::where('approve_id',$params['id'])->where('step_id',$current_step['id'])->where('is_invalid',0)->where('status','<>',0)->count();
-						//获取但前记录的已经通过的记录
-						$check_record_pass = FlowRecord::where('approve_id',$params['id'])->where('step_id',$current_step['id'])->where('status',1)->where('is_invalid',0)->findOrEmpty();
-						//判断当前记录除当前用户外,是否都审批了,
-						if(count($current_check_user)-1 == $check_record_count){
-							//判断有没有审核通过的
-							if($check_record_pass->isEmpty()){//没有审核通过的
-								if($params['check_status'] == 1){
-									if(($current_step['sort']+1) == $step_count){
-										$approve_check_status = 2;
-									}else{
-										$approve_check_status = 1;
-										//设置下一步
-										FlowStep::where('id',$current_step['id'])->update(['is_active'=>0]);
-										FlowStep::where('approve_id',$params['id'])->where('sort',$current_step['sort']+1)->update(['is_active'=>1]);
-									}
-								}else{
-									$approve_check_status = 3;
-								}
-							}else{//有审核通过的
-								if(($current_step['sort']+1) == $step_count){
-									$approve_check_status = 2;
-								}else{
-									$approve_check_status = 1;
-									//设置下一步
-									FlowStep::where('id',$current_step['id'])->update(['is_active'=>0]);
-									FlowStep::where('approve_id',$params['id'])->where('sort',$current_step['sort']+1)->update(['is_active'=>1]);
-								}
+						//判断当前审核状态
+						if($params['check_status'] == 1){
+							$approve_check_status = $next_step->isEmpty() ? 2 : 1;
+							if(!$next_step->isEmpty()){
+								FlowStep::where('id',$current_step['id'])->update(['is_active'=>0]);
+								FlowStep::where('id',$next_step['id'])->update(['is_active'=>1]);
 							}
 						}else{
-							//没审批完,该记录都设置为审批中
-							$approve_check_status = 1;
+							//获取当前记录的审核记录数
+							$check_record_count = FlowRecord::where('approve_id',$params['id'])->where('step_id',$current_step['id'])->where('is_invalid',0)->where('status','<>',0)->count();
+							//判断当前记录除当前用户外,是否都审批了
+							if(count($current_check_user)-1 == $check_record_count){
+								$approve_check_status = 3;
+								if(!$next_step->isEmpty()){
+									FlowStep::where('id',$current_step['id'])->update(['is_active'=>0]);
+									FlowStep::where('id',$next_step['id'])->update(['is_active'=>1]);
+								}
+							}else{
+								$approve_check_status = 1;
+							}
 						}
 						FlowApprove::where('id',$params['id'])->update([
 							'check_status' => $approve_check_status,
@@ -224,40 +202,21 @@ class FlowApproveLogic extends BaseLogic
 						]);
 						break;
 					case 3: //指定人会签
-						//判断当前记录除当前用户外,是否都审批了,
-						//1、如果都审批了,则判断其他用户是否有未审批通过的
-						//1-1、如果其他用户都审批通过,则判断当前用户是否审批通过通过,如果当前用户审批通过,则判断当前审核步骤是否是最后一步,
-						//1-1-1-1、如果是最后一步,则该记录审批通过,流程结束
-						//1-1-1-2、如果不是最后一步,则该记录设置为审批中,流程设置为下一步
-						//1-1-2、如果当前用户审批不通过,则该记录审批不通过,流程结束
-						//1-2、如果其他用户有一位审批不通过,则不管当前用户是否审批通过,该记录设置为审核不通过,流程结束
-						//2、如果没审批完,则判断当前用户是否审批通过,如果当前用户审批通过,则将记录设置为审批中,如果当前用户审批不通过,则将记录设置为审批不通过
-						//获取当前记录的审核记录数
-						$check_record_count = FlowRecord::where('approve_id',$params['id'])->where('step_id',$current_step['id'])->where('is_invalid',0)->where('status','<>',0)->count();
-						//获取但前记录的未通过的记录
-						$check_record_not_pass = FlowRecord::where('approve_id',$params['id'])->where('step_id',$current_step['id'])->where('status',2)->where('is_invalid',0)->findOrEmpty();
-						//判断当前记录除当前用户外,是否都审批了,
-						if(count($current_check_user)-1 == $check_record_count){
-							//判断有没有审核不通过的
-							if($check_record_not_pass->isEmpty()){//没有审核不通过的
-								if($params['check_status'] == 1){
-									if(($current_step['sort']+1) == $step_count){
-										$approve_check_status = 2;
-									}else{
-										$approve_check_status = 1;
-										//设置下一步
-										FlowStep::where('id',$current_step['id'])->update(['is_active'=>0]);
-										FlowStep::where('approve_id',$params['id'])->where('sort',$current_step['sort']+1)->update(['is_active'=>1]);
-									}
-								}else{
-									$approve_check_status = 3;
-								}
-							}else{//有审核不通过的
-								$approve_check_status = 3;
-							}
+						if($params['check_status'] == 2){
+							$approve_check_status = 3;
 						}else{
-							//没审批完,则判断当前用户是否审批通过,如果当前用户审批通过,则将记录设置为审批中,如果当前用户审批不通过,则将记录设置为审批不通过
-							$approve_check_status = $params['check_status'] == 1 ? 1 : 3;
+							//获取当前记录的审核记录数
+							$check_record_count = FlowRecord::where('approve_id',$params['id'])->where('step_id',$current_step['id'])->where('is_invalid',0)->where('status','<>',0)->count();
+							//判断当前记录除当前用户外,是否都审批了,
+							if(count($current_check_user)-1 == $check_record_count){
+								$approve_check_status = 2;
+								if(!$next_step->isEmpty()){
+									FlowStep::where('id',$current_step['id'])->update(['is_active'=>0]);
+									FlowStep::where('id',$next_step['id'])->update(['is_active'=>1]);
+								}
+							}else{
+								$approve_check_status = 1;
+							}
 						}
 						FlowApprove::where('id',$params['id'])->update([
 							'check_status' => $approve_check_status,
@@ -266,7 +225,7 @@ class FlowApproveLogic extends BaseLogic
 						break;
 				}
 			}else{
-				if(($current_step['sort']+1) == $step_count){
+				if($next_step->isEmpty()){
 					FlowApprove::where('id',$params['id'])->update([
 						'check_status' => $params['check_status'] == 1 ? 2 : 3,
 						'update_time' => $check_time,
@@ -279,7 +238,7 @@ class FlowApproveLogic extends BaseLogic
 					//设置下一步
 					if($params['check_status'] == 1){
 						FlowStep::where('id',$current_step['id'])->update(['is_active'=>0]);
-						FlowStep::where('approve_id',$params['id'])->where('sort',$current_step['sort']+1)->update(['is_active'=>1]);
+						FlowStep::where('id',$next_step['id'])->update(['is_active'=>1]);
 					}
 				}
 			}