/** * 添加学生 第 3 步提交处理. * * @access public * @return void * @author Liuping <*****@*****.**> */ public function addStep3Action() { // 校验一级中介是否有权限添加学生 if (!AgentAuth::checkTopAgentOfStu()) { $this->error('No permission'); } // 当前操作, 参见第 1 步中说明. $operFlag = intval(I('post.oper', 1)); $studentId = intval(I('post.currStudent', 0)); // 学生 id if (empty($studentId)) { $this->error('Invalid parameters'); } // 实例化 MemberStu 模型 $model = new MemberStuModel(); $stuInfo = $model->fetchStuInfo($studentId); if (empty($stuInfo)) { $this->error('Invalid parameters'); } // 对学生做权限验证 $res = AgentAuth::checkStu($studentId, [AgentAuth::WRITE]); if (9 !== $res['status']) { $this->error('No permission'); } $uid = $stuInfo['uid']; $paretUId = $stuInfo['fuid']; $partid = $stuInfo['partid']; $ano = ''; // 验证成功规则能过, 验证是否有添加学生的权限 // 校验一级中介是否有权限添加学生 if (!AgentAuth::checkTopAgentOfStu($uid)) { $this->error('No permission'); } // 各表单项允许的条数配置. $config = C('ADD_STUDENT_FORM_OPT'); // 获取数据 $eduBackInfo = I('post.eduInfo', []); // 教育背景信息. $certInfo = I('post.engCertInfo', []); // 英语证书信息 $workExpInfo = I('post.workExpInfo', []); // 工作经验信息 $refInfo = I('post.refInfo', []); // 推荐人信息. // 处理数据 $eduBackInfo = $this->processData($eduBackInfo); $workExpInfo = $this->processData($workExpInfo); $refInfo = $this->processData($refInfo); // 按允许的条数截取 $eduBackInfo = array_slice($eduBackInfo, 0, $config['eduBackNum']); $workExpInfo = array_slice($workExpInfo, 0, $config['workExpNum']); $refInfo = array_slice($refInfo, 0, $config['refereesNum']); // 字段映射处理 $eduBackInfo = $this->autoBatchFieldMap($eduBackInfo, $this->eduInfoMaps); $workExpInfo = $this->autoBatchFieldMap($workExpInfo, $this->workExpInfoMaps); $refInfo = $this->autoBatchFieldMap($refInfo, $this->refInfoMaps); $this->autoFieldMap($certInfo, $this->engCertInfoMaps); // 一维数组映射 // 补齐默认数据 // 补齐教育背景信息. foreach ($eduBackInfo as &$row) { $row['uid'] = $uid; $row['fuid'] = $paretUId; $row['partid'] = $partid; $row['s_id'] = $studentId; $row['a_no'] = $ano; if (empty($row['id'])) { $row['create_time'] = time(); } // 目前的规则是, 若教育背景的 国家为 china 就读类型才可以有值 if ('china' === strtolower($row['institution_country'])) { if ('other' !== strtolower($row['attend_type'])) { // 不为 other 指定的就读类型设置为空串 $row['attend_other_type'] = ''; } } else { // 不是中国就读类型都为空 $row['attend_type'] = ''; $row['attend_other_type'] = ''; } } unset($row); // 补齐英语证书信息 $certInfo['uid'] = $uid; $certInfo['fuid'] = $paretUId; $certInfo['partid'] = $partid; $certInfo['s_id'] = $studentId; $certInfo['a_no'] = $ano; //$certInfo['readly_for_test'] = isset($certInfo['readly_for_test']) ? $certInfo['readly_for_test'] : ''; // 2016-1-19 新增 表已加默认值. if (empty($certInfo['id'])) { $certInfo['create_time'] = time(); } // 补齐工作经验 foreach ($workExpInfo as &$row) { $row['uid'] = $uid; $row['fuid'] = $paretUId; $row['partid'] = $partid; $row['s_id'] = $studentId; $row['a_no'] = $ano; if (empty($row['id'])) { $row['create_time'] = time(); } } unset($row); // 补齐推荐人信息 foreach ($refInfo as &$row) { $row['uid'] = $uid; $row['fuid'] = $paretUId; $row['partid'] = $partid; $row['s_id'] = $studentId; $row['a_no'] = $ano; if (empty($row['id'])) { $row['create_time'] = time(); } } unset($row); // 验证规则 部分 // 验证教育背景 qualification 为 other 时, qualificationOther 必填 // institution_country 为 china 时, attend_type 必填 // attend_type 为 other 时, attend_other_type 必填 foreach ($eduBackInfo as &$row) { // 处理 qualification, 若为 Other 时, 拼接成 qualification-qualificationOther if ('other' === strtolower($row['qualification'])) { if (empty($row['qualificationOther'])) { $this->error('Title of qualification cannot be empty'); } elseif (!$model->validateEnChar($row['qualificationOther'])) { $this->error('Please enter a valid qualification'); } // 检测通过用 - 连接. $row['qualification'] = $row['qualification'] . '-' . $row['qualificationOther']; } unset($row['qualificationOther']); // 验证其它规则项 $res = $model->validate($model->eduInfoRules)->create($row); if (!$res) { $this->error($model->getError()); } // institution_country 为中国时 if ('china' === strtolower($row['institution_country'])) { $res1 = $model->validate($model->eduInfoRules1)->create($row); if (!$res1) { $this->error($model->getError()); } // 若 attend_type 为 other 时验证 attend_other_type if ('other' === strtolower($row['attend_type'])) { $res2 = $model->validate($model->eduInfoRules2)->create($row); if (!$res2) { $this->error($model->getError()); } } } } unset($row); // 验证工作经验 foreach ($workExpInfo as $row) { $res = $model->validate($model->workExpInfoRules)->create($row); if (!$res) { $this->error($model->getError()); } } unset($row); // 验证语言证书 // have_en_test 即 是否在近两年内有过英语测试 为 yes 时 // 证书名称 总成绩 考试日期 城市(拼音) 国家(拼音) 证书号码(证书的右下角)为必填项 // en_is_first 为 no 时, 其它规则还保留原有的验证规则. $res = $model->validate($model->certInfoRules2)->create($certInfo); if (!$res) { $this->error($model->getError()); } $en_is_first = strtolower($certInfo['en_is_first']); if ('yes' === $en_is_first) { // en_is_first 为 yes 不验证其它规则, 置空 $certInfo['certification_name'] = ''; $certInfo['totle_score'] = 0; $certInfo['test_date'] = ''; $certInfo['country'] = ''; $certInfo['city'] = ''; $certInfo['certification_number'] = ''; } else { // en_is_first 为 no 时执行原有的验证规则. $res = $model->validate($model->certInfoRules)->create($certInfo); if (!$res) { $this->error($model->getError()); } if ('yes' === strtolower($certInfo['have_en_test'])) { $res1 = $model->validate($model->certInfoRules1)->create($certInfo); if (!$res1) { $this->error($model->getError()); } } else { // 等于 no 置空 $certInfo['certification_name'] = ''; $certInfo['totle_score'] = 0; $certInfo['test_date'] = ''; $certInfo['country'] = ''; $certInfo['city'] = ''; $certInfo['certification_number'] = ''; } } // 验证推荐人 foreach ($refInfo as $row) { $res = $model->validate($model->refInfoRules)->create($row); if (!$res) { $this->error($model->getError()); } } unset($row); // 开启事务 $model->startTrans(); // 全部通过写入数据库. $res = $model->procEduBackInfo($eduBackInfo, $uid, $studentId, $ano); $res1 = $model->procEngLangCertInfo($certInfo, $uid, $studentId, $ano); $res2 = $model->procWorkExpInfo($workExpInfo, $uid, $studentId, $ano); $res3 = $model->procRefereeInfo($refInfo, $uid, $studentId, $ano); if (!($res && $res1 && $res2 && $res3)) { $model->rollback(); $this->error('Action failed'); } // 都处理成功, 提交事务. $model->commit(); // 跳转到第三步 $stepUrl = U('addStep4'); $this->myRedirect('addTrans', $stepUrl, $studentId, $uid, $ano, $operFlag); }
/** * 提交申请第 3 步处理. * * @access public * @return void * @author Liuping <*****@*****.**> */ public function appSubmit3Action() { // 校验一级中介是否有权限添加申请 if (!AgentAuth::checkTopAgentOfApply()) { $this->error('No permission'); } // 申请 id $appStatusId = intval(I('post.appStatus', '')); // 陈述内容 $stateContent = I('post.stateText', ''); if (empty($appStatusId)) { $this->error('Parameters error', U('Student/noApplyStudentList')); } $modelAppStatus = new ApplyStatusModel(); $appStatusInfo = $modelAppStatus->find($appStatusId); if (NULL === $appStatusInfo || FALSE === $appStatusInfo) { $appStatusInfo = []; } if (empty($appStatusInfo)) { $this->error('Parameters error', U('Student/noApplyStudentList')); } // 操作类型 1 : 添加, 2 : 编辑 $operFlag = intval(I('post.oper', 1)); // 根据操作类型, 设置不同的权限 $authRule = []; if (1 === $operFlag) { $authRule[] = AgentAuth::ADD; } else { $authRule[] = AgentAuth::WRITE; } $modelStu = new MemberStuModel(); // 验证权限 $res = AgentAuth::checkStu($appStatusInfo['s_no'], $authRule); if ($res['status'] !== 9) { $this->error('No permission'); } // 申请状态 $applyStatus = intval($appStatusInfo['a_status']); // 若申请状态为材料出错(a_status : 2), 就不验证是否超过允许添加的条数和不更新申请数量 $res = FALSE; // 默认为未超过申请条数 if (2 !== $applyStatus) { // 检查是否已超过允许添加的条数 $res = $modelAppStatus->checkApplyNum($appStatusInfo['year'], $appStatusInfo['s_no']); } if ($res) { // 超过申请次数跳转到中介未申请学生列表 $msg = 'The application amount of ' . $appStatusInfo['year'] . 'entry for this student has run out.'; $this->error($msg, U('Student/noApplyStudentList')); } // 开始组装新添加的数据 $uid = $appStatusInfo['uid']; $fuid = $appStatusInfo['fuid']; $partid = $appStatusInfo['partid']; $stuId = $appStatusInfo['s_no']; $ano = $appStatusInfo['a_no']; // 个人陈述 $perStateInfo = $modelStu->fetchPerStateInfo($stuId, $ano); if (empty($perStateInfo)) { // 新增 $perStateInfo = $modelStu->fetchPerStateInfo($stuId, ''); $perStateInfo['id'] = ''; $perStateInfo['uid'] = $uid; $perStateInfo['fuid'] = $fuid; $perStateInfo['partid'] = $partid; $perStateInfo['s_id'] = $stuId; $perStateInfo['a_no'] = $ano; $perStateInfo['create_time'] = time(); } // 陈述内容 $perStateInfo['content'] = $stateContent; // 执行验证规则 $res = $modelStu->validate($modelStu->perStateRules)->create($perStateInfo); if (!$res) { $this->error($modelStu->getError()); } $modelStu->startTrans(); // 开启事务 $res = $modelStu->procPerStateInfo($perStateInfo, $uid, $stuId, $ano); $res1 = $modelAppStatus->switchCompleteStatus($appStatusId, 1, time()); $stuFullName = $appStatusInfo['first_name'] . ' ' . $appStatusInfo['family_name']; // 若申请状态为材料出错(a_status : 2), 就不验证是否超过允许添加的条数和不更新申请数量 $res2 = TRUE; // 默认为更新数量成功 if (2 !== $applyStatus) { $res2 = $modelAppStatus->updateApplyNum($appStatusInfo['year'], $stuId, $stuFullName); } $aoInfo = $modelStu->fetchAoInfo($stuId); $res3 = $modelAppStatus->switchApplyStatus($appStatusId, 1); // 更新状态为 审核中. $res4 = TRUE; $res5 = TRUE; $res6 = TRUE; $_cont = '用户重新提交了申请'; $_cont1 = 'Application has been resubmitted, application status changes to"Verifying by ApplicationUK"'; if (!empty($aoInfo) && 2 === $applyStatus) { // 有跟进AO且状态是材料出错, 就记录日志 $res4 = $modelStu->writeLog($aoInfo['ao_uid'], $uid, $ano, 1, date('Y-m-d H:i:s') . ', ' . $_cont); $res5 = $modelStu->writeApplyLog($aoInfo['ao_uid'], $uid, $ano, 1, $_cont1); } // 新申请记录新申请日志. if (0 === $applyStatus) { $_cont1 = 'Your application has been submitted and now under verification, application status changes to "Verifing by ApplicationUK"'; $res6 = $modelStu->writeApplyLog(empty($aoInfo) ? 0 : $aoInfo['ao_uid'], $uid, $ano, 1, $_cont1); } if ($res && $res1 && $res2 && $res3 && $res4 && $res5 && $res6) { $modelStu->commit(); if (!empty($aoInfo) && 2 === $applyStatus) { // 材料出错重新提交, 给 AO 发邮件 $resubmitTime = date('Y-m-d H:i:s', time()); $emailTitle = $stuFullName . ' ' . $_cont; $emailContent = <<<MAIL 学生姓名: {$stuFullName}. 提交时间: {$resubmitTime}. 描述: {$_cont}. MAIL; // 发送邮件 MemberStuModel::sendEmail($aoInfo['ao_user_email'], $emailTitle, $emailContent); } elseif (!empty($aoInfo)) { // 新添加/修改申请时要发邮件 $_cont = '提交了新的申请'; $resubmitTime = date('Y-m-d H:i:s', time()); $emailTitle = $stuFullName . ' ' . $_cont; $emailContent = <<<MAIL 学生姓名: {$stuFullName}. 提交时间: {$resubmitTime}. 描述: {$_cont}. MAIL; // 发送邮件 MemberStuModel::sendEmail($aoInfo['ao_user_email'], $emailTitle, $emailContent); } // 写入系统日志 $_mark = session('username') . '在' . date('Y-m-d H:i:s') . ', 添加了一个申请资料, 申请编号 : ' . $ano . ', 学生姓名 : ' . $appStatusInfo['first_name'] . $appStatusInfo['family_name']; if (1 === $operFlag) { // 写入新增日志 system_log($_mark, $modelAppStatus->getTableName(), $ano, 'a', $appStatusInfo, NULL, 1); } // 成功跳转到已申请列表. //$this->success('Successful!', U('Student/studentList')); $this->success('Successful!', U('Student/studentDetail', ['id' => $stuId])); } else { $modelStu->rollback(); $this->error('Action failed'); } }