whereIn('id', (array)$user_ids)->where('status', 1)->pluck('id')->toArray(); $continue = true; $nouser = intval($step['nouser']); // 找不到匹配的办理人 if (empty($step['user_ids'])) { if ($nouser == 0) { $step['select_org'] = 1; } else if ($nouser == 1) { // 不跳过节点继续寻找下一个节点 $continue = false; $step['hide'] = true; } else if ($nouser == 2) { $step['user_ids'] = [$step['nouser_user_id']]; } } return ['step' => $step, 'continue' => $continue]; } /** * 条件测试 */ public static function testCondition($a, $b, $t) { if($t == '==') { return $a == $b; } if($t == '<>') { return $a <> $b; } if($t == '>') { return $a > $b; } if($t == '<') { return $a < $b; } if($t == '>=') { return $a >= $b; } if($t == '<=') { return $a <= $b; } } /** * 检查转入条件 */ public static function checkCondition($run_step, $next_steps, $gets) { $form_data = static::formDataCondition($gets); $step_condition = false; $null_condition = 0; $next_steps_count = count($next_steps); if ($next_steps_count > 0) { // 流程转交条件检查 $conditions = json_decode($run_step['condition'], true); foreach ($next_steps as $step) { $condition = $conditions[$step['step_id']]; if (empty($condition)) { $null_condition ++; continue; } $test = static::testCheckCondition($form_data, $condition, $gets); // 条件满足记录步骤数组 if ($test) { $step_condition = true; } } // 有一种情况,多个转入步骤都是空条件, 或单转入步骤条件为空 if ($next_steps_count == $null_condition) { $step_condition = true; } } return $step_condition; } /** * * 检查条件的表单字段 */ public static function formDataCondition($gets) { $master = $gets['master']; // 获取单据创建者ID if ($master['created_id'] > 0) { $created_id = $master['created_id']; } else { $created_id = Auth::id(); } // 创建人 $start_user = static::getMacroUser($created_id); // 经办人 $current_user = static::getMacroUser(Auth::id()); $form_data = []; $form_data['[start_user_id]'] = $start_user['user_id']; $form_data['[start_role_id]'] = $start_user['role_id']; $form_data['[start_department_id]'] = $start_user['department_id']; $form_data['[start_user]'] = $start_user['user_name']; $form_data['[start_position]'] = $start_user['position_name']; $form_data['[start_group]'] = $start_user['group_name']; $form_data['[start_role]'] = $start_user['role_name']; $form_data['[start_department]'] = $start_user['department_name']; $form_data['[edit_user_id]'] = $current_user['user_id']; $form_data['[edit_role_id]'] = $current_user['role_id']; $form_data['[edit_department_id]'] = $current_user['department_id']; $form_data['[edit_user]'] = $current_user['user_name']; $form_data['[edit_position]'] = $current_user['position_name']; $form_data['[edit_group]'] = $current_user['group_name']; $form_data['[edit_role]'] = $current_user['role_name']; $form_data['[edit_department]'] = $current_user['department_name']; // $form_data['[步骤号]'] = $post['setp_id']; // $form_data['[流程设计步骤号]'] = $gets['step_number']; // $form_data['[公共附件名称]'] = $post['attachment']; // $form_data['[公共附件个数]'] = $post['attachment']; return $form_data; } /** * 测试检查条件 */ public static function testCheckCondition($form_data, $conditions, $gets) { // 存在条件 $wheres = []; foreach ($conditions as $condition) { $f = $condition['f']; $c = $condition['c']; $v = $condition['v']; $t = $condition['t']; if (isset($form_data[$f])) { $condition['f'] = "\$form_data['".$f."']"; } else { // 分割字段名称 list($p, $k) = explode('.', $f); // 多行子表 $lines = $gets['models']; // 子表处理 if(isset($lines[$p])) { $rows = $gets[$p]['rows']; if ($t) { $_test = false; // 总数 if ($t == 'count') { $count = count($rows); if (static::testCondition($count, $v, $c)) { $_test = true; } } // 总和 if ($t == 'sum') { $_sum = 0; foreach ($rows as $row) { $_sum += $row[$k]; } if (static::testCondition($_sum, $v, $c)) { $_test = true; } } $condition['c'] = ''; $condition['v'] = ''; if($_test) { $condition['f'] = 'true'; } else { $condition['f'] = 'false'; } } else { continue; } } else { // 把变量名称作为字符串赋值 $condition['f'] = "\$gets['".$p."']['".$k."']"; } } unset($condition['t']); $wheres[] = join(' ', $condition); } // 检查条件 $where = join(' ', $wheres); $test = eval("return $where;"); return $test; } /** * 检查转入条件 */ public static function runCheckCondition($run_step, $next_steps, $gets) { $form_data = static::formDataCondition($gets); $steps = []; $next_steps_count = count($next_steps); if ($next_steps_count > 0) { // 流程转交条件检查 $conditions = json_decode($run_step['condition'], true); foreach ($next_steps as $step) { $condition = $conditions[$step['step_id']]; if (empty($condition)) { $steps[] = $step; continue; } // 组合条件 $test = static::testCheckCondition($form_data, $condition, $gets); // 条件满足记录步骤数组 if ($test) { $steps[] = $step; } } } return $steps; } /** * */ public static function getFlowStep($steps, $step, $gets, &$ret) { $ids = array_filter(explode(',', $step['join'])); $next_steps = []; foreach($ids as $id) { if (isset($steps[$id])) { $next_steps[] = $steps[$id]; } } $rows = static::runCheckCondition($step, $next_steps, $gets); foreach($rows as $row) { $ret[$row['step_id']] = $row; static::getFlowStep($steps, $row, $gets, $ret); } } /** * 获取流程字段的数据 */ public static function getFlowField($run_id, $row, $flow, $steps, $step, $view, $view_step_id, $action, $permission) { $run_step = $steps[$view_step_id]; if(empty($run_step)) { return; } $write = $permission['flow_step'][$view_step_id]; $remark = $run_step['run_remark']; $by = ''; $line = ' '; if ($run_step['run_updated_id'] > 0) { $updated_by = get_user($run_step['run_updated_id'], 'name', false); $by = $updated_by.' '.format_datetime($run_step['run_updated_at']); } if ($action == 'show' || $action == 'print') { if ($run_step['run_updated_at'] > 0) { if ($remark == '') { $remark = '同意'; } } else { if ($write['w'] == 1) { $remark = ''; } } } if ($action == 'show') { return '