This commit is contained in:
weiz 2024-02-18 15:23:26 +08:00
parent 2d65f10046
commit c2602efd8f
4 changed files with 139 additions and 121 deletions

View File

@ -65,7 +65,7 @@ class FlowApproveLogic extends BaseLogic
$data['copy_user'] = implode(',',$copy);
$data['step'] = $step;
$data['record'] = $record;
unset($data['flow_id'],$data['content_model'],$data['content_logic']);
unset($data['flow_id']);
return $data->toArray();
}
@ -118,6 +118,10 @@ class FlowApproveLogic extends BaseLogic
$str = $params['check_status'] == 1 ? '通过' : '拒绝';
$check_user = Admin::field('name')->where('id',$admin_id)->findOrEmpty();
$approve_data = FlowApprove::where('id',$params['id'])->findOrEmpty();
if($approve_data->isEmpty()){
self::setError('当前审批信息不存在');
return false;
}
if($approve_data['check_status'] == 2 || $approve_data['check_status'] == 3){
self::setError('当前审批信息已审核');
return false;
@ -136,104 +140,71 @@ class FlowApproveLogic extends BaseLogic
return false;
}
//判断当前用户是否审核过该条记录
$check_record = FlowRecord::where('approve_id',$params['id'])->where('step_id',$current_step['id'])->where('check_user_id',$admin_id)->findOrEmpty();
$check_record = FlowRecord::where('approve_id',$params['id'])->where('step_id',$current_step['id'])->where('check_user_id',$admin_id)->where('is_invalid',0)->findOrEmpty();
if(!$check_record->isEmpty()){
self::setError('你已经审核过该条信息,无需重复审核');
return false;
}
//审批时间
$check_time = time();
//获取审批流程信息
$flow_data = Flow::where('id',$approve_data['flow_id'])->findOrEmpty();
Db::startTrans();
try {
//判断当前审批步骤类型
switch($current_step['flow_step']){
case 1://当前部门负责人审批
//判断当前审核步骤是否是最后一步;
//1、如果是最后一步如果当前用户审核通过则将该记录设置为审核通过如果当前用户未审核通过则则将该记录设置为审核不通过流程结束
//2、如果不是最后一步如果当前用户审核通过则将该记录设置为审核中流程进入下一步如果当前用户未审核通过则则将该记录设置为审核不通过流程结束
if(($current_step['sort']+1) == $step_count){
FlowApprove::where('id',$params['id'])->update([
'check_status' => $params['check_status'] == 1 ? 2 : 3,
'update_time' => $check_time,
]);
}else{
FlowApprove::where('id',$params['id'])->update([
'check_status' => $params['check_status'] == 1 ? 1 : 3,
'update_time' => $check_time,
]);
//设置下一步
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]);
}
}
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'])->count();
//获取但前记录的已经通过的记录
$check_record_pass = FlowRecord::where('approve_id',$params['id'])->where('step_id',$current_step['id'])->where('status',1)->findOrEmpty();
//判断当前记录除当前用户外,是否都审批了,
if(count($current_check_user)-1 == $check_record_count){
//判断有没有审核通过的
if($check_record_pass->isEmpty()){//没有审核通过的
if($flow_data['check_type'] == 1){
//判断当前审批步骤类型
switch($current_step['flow_step']){
case 1://当前部门负责人审批
//判断当前审核步骤是否是最后一步;
//1、如果是最后一步如果当前用户审核通过则将该记录设置为审核通过如果当前用户未审核通过则则将该记录设置为审核不通过流程结束
//2、如果不是最后一步如果当前用户审核通过则将该记录设置为审核中流程进入下一步如果当前用户未审核通过则则将该记录设置为审核不通过流程结束
if(($current_step['sort']+1) == $step_count){
FlowApprove::where('id',$params['id'])->update([
'check_status' => $params['check_status'] == 1 ? 2 : 3,
'update_time' => $check_time,
]);
}else{
FlowApprove::where('id',$params['id'])->update([
'check_status' => $params['check_status'] == 1 ? 1 : 3,
'update_time' => $check_time,
]);
//设置下一步
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]);
}
}
}else{
//没审批完,该记录都设置为审批中
$approve_check_status = 1;
}
FlowApprove::where('id',$params['id'])->update([
'check_status' => $approve_check_status,
'update_time' => $check_time,
]);
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'])->count();
//获取但前记录的未通过的记录
$check_record_not_pass = FlowRecord::where('approve_id',$params['id'])->where('step_id',$current_step['id'])->where('status',2)->findOrEmpty();
//判断当前记录除当前用户外,是否都审批了,
if(count($current_check_user)-1 == $check_record_count){
//判断有没有审核不通过的
if($check_record_not_pass->isEmpty()){//没有审核不通过的
if($params['check_status'] == 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'])->count();
//获取但前记录的已经通过的记录
$check_record_pass = FlowRecord::where('approve_id',$params['id'])->where('step_id',$current_step['id'])->where('status',1)->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{
@ -242,21 +213,75 @@ class FlowApproveLogic extends BaseLogic
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{
}
}else{
//没审批完,该记录都设置为审批中
$approve_check_status = 1;
}
FlowApprove::where('id',$params['id'])->update([
'check_status' => $approve_check_status,
'update_time' => $check_time,
]);
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'])->count();
//获取但前记录的未通过的记录
$check_record_not_pass = FlowRecord::where('approve_id',$params['id'])->where('step_id',$current_step['id'])->where('status',2)->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;
}
}else{//有审核不通过的
$approve_check_status = 3;
}else{
//没审批完,则判断当前用户是否审批通过,如果当前用户审批通过,则将记录设置为审批中,如果当前用户审批不通过,则将记录设置为审批不通过
$approve_check_status = $params['check_status'] == 1 ? 1 : 3;
}
}else{
//没审批完,则判断当前用户是否审批通过,如果当前用户审批通过,则将记录设置为审批中,如果当前用户审批不通过,则将记录设置为审批不通过
$approve_check_status = $params['check_status'] == 1 ? 1 : 3;
}
FlowApprove::where('id',$params['id'])->update([
'check_status' => $approve_check_status,
'update_time' => $check_time,
]);
break;
}
}else{
if(($current_step['sort']+1) == $step_count){
FlowApprove::where('id',$params['id'])->update([
'check_status' => $approve_check_status,
'check_status' => $params['check_status'] == 1 ? 2 : 3,
'update_time' => $check_time,
]);
break;
}else{
FlowApprove::where('id',$params['id'])->update([
'check_status' => $params['check_status'] == 1 ? 1 : 3,
'update_time' => $check_time,
]);
//设置下一步
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]);
}
}
}
//添加审批数据记录
FlowRecord::create([

View File

@ -42,6 +42,15 @@ class FlowLogic extends BaseLogic
*/
public static function add(array $params): bool
{
if($params['check_type'] == 1){
foreach ($params['flow_list'] as &$v){
if($v['flow_step'] == 1){
$flow_cate_data = FlowType::where('id',$params['flow_cate'])->findOrEmpty();
$dept_leaders = Dept::where('id','in',$flow_cate_data['department_ids'])->column('leader');
$v['flow_user'] = $dept_leaders;
}
}
}
Db::startTrans();
try {
Flow::create([
@ -49,7 +58,7 @@ class FlowLogic extends BaseLogic
'flow_cate' => $params['flow_cate'],
'check_type' => $params['check_type'],
'remark' => $params['remark'] ?? '',
'flow_list' => $params['check_type'] != 2 ? json_encode($params['flow_list']) : null,
'flow_list' => json_encode($params['flow_list']),
'status' => 2,
'copy_uids' => implode(',',$params['copy_uids']),
]);
@ -79,7 +88,7 @@ class FlowLogic extends BaseLogic
'flow_cate' => $params['flow_cate'],
'check_type' => $params['check_type'],
'remark' => $params['remark'] ?? '',
'flow_list' => $params['check_type'] != 2 ? json_encode($params['flow_list']) : null,
'flow_list' => json_encode($params['flow_list']),
'status' => $params['status'],
'copy_uids' => implode(',',$params['copy_uids']),
]);

View File

@ -38,7 +38,7 @@ class FlowValidate extends BaseValidate
'name' => 'require',
'flow_cate' => 'require|checkFlowCate',
'check_type' => 'require|checkCheckType',
'flow_list' => 'requireCallback:check_require|checkFlowList',
'flow_list' => 'require|checkFlowList',
'status' => 'require|checkStatus',
'copy_uids' => 'array|checkCopyUids',
];
@ -127,14 +127,6 @@ class FlowValidate extends BaseValidate
return true;
}
public function check_require($value, $data): bool
{
if($data['check_type'] != 2){
return true;
}
return false;
}
public function checkFlowList($value,$rule,$data): bool|string
{
if(!is_array($value)){
@ -167,7 +159,7 @@ class FlowValidate extends BaseValidate
}
}
}
if($data['check_type'] == 3){
if($data['check_type'] == 2){
foreach($value as $k=>$v){
if(empty($v['flow_step'])){
return '请填写审批步骤名称';

View File

@ -360,7 +360,8 @@ function daysBetweenDates($start_date,$end_date): bool|int
return $interval->days;
}
function addApprove($title,$content_id,$content_model,$content_logic,$path,$flow_type_id,$flow_id,$create_user_id){
function addApprove($title,$content_id,$content_model,$path,$flow_id,$create_user_id): bool
{
$createUser = Admin::field('name,dept_id')->where('id',$create_user_id)->findOrEmpty();
//获取审批流程信息
$flowData = Flow::where('id',$flow_id)->findOrEmpty();
@ -371,34 +372,25 @@ function addApprove($title,$content_id,$content_model,$content_logic,$path,$flow
'title' => $title,
'content_id' => $content_id,
'content_model' => $content_model,
'content_logic' => $content_logic,
'path' => $path,
'flow_type_id' => $flow_type_id,
'flow_id' => $flow_id,
'create_user' => $create_user_id,
'check_status' => 0,
]);
$flowStepData = [];
foreach($flowData['flow_list'] as $k=>$v){
//获取部门负责人id
if($v['flow_step'] == 1){
$dept = Dept::field('leader')->where('id',$createUser['dept_id'])->findOrEmpty();
$flow_user = !$dept->isEmpty() ? $dept['leader'] : 0;
}else{
$flow_user = implode(',',$v['flow_user']);
}
$flowStepData[] = [
'approve_id' => $approveRes->id,
'flow_name' => $flowData['name'],
'flow_step' => $v['flow_step'],
'flow_user' => $flow_user,
'flow_name' => $flowData['check_type'] == 1 ? '' : $v['flow_step'],
'flow_step' => $flowData['check_type'] == 1 ? $v['flow_step'] : 0,
'flow_user' => implode(',',$v['flow_user']),
'sort' => $k+1,
'is_active' => $k==0 ? 1 : 0,
];
}
array_unshift($flowStepData, [
'approve_id' => $approveRes->id,
'flow_name' => $flowData['name'],
'flow_name' => '',
'flow_step' => 0,
'flow_user' => 0,
'sort' => 0,