/** * 添加学生 第 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); }