/** * 添加学生第 2 步提交处理. * * @access public * @return void * @author Liuping <*****@*****.**> */ public function addStep2Action() { // 当前操作, 参见第 1 步中说明. $operFlag = intval(I('post.oper', 1)); $post = I('post.'); $otherInfo = []; // 个人其它信息 if (isset($post['otherInfo'])) { $otherInfo = $post['otherInfo']; unset($post['otherInfo']); } $perInfo = $post; // 个人信息 // 字段映射 $this->autoFieldMap($perInfo, $this->perInfoMaps); $this->autoFieldMap($otherInfo, $this->otherInfoMaps); $stuId = intval($perInfo['s_id']); // 学生 id if (empty($stuId)) { $this->error('Invalid parameters'); } // 实例化模型 $model = new MemberStuModel(); // 将 6 项基本信息添加到 $perInfo 中. $stuInfo = $model->fetchStuInfo($stuId); if (empty($stuInfo)) { $this->error('Invalid parameters'); } // 对学生做权限验证 $res = AgentAuth::checkStu($stuId, [AgentAuth::WRITE]); if (9 !== $res['status']) { $this->error('No permission'); } $uid = $stuInfo['uid']; $partid = $stuInfo['partid']; $parentUId = $stuInfo['fuid']; $ano = ''; // 验证成功规则能过, 验证是否有添加学生的权限 // 校验一级中介是否有权限添加学生 if (!AgentAuth::checkTopAgentOfStu($uid)) { $this->error('No permission'); } // 给固定字段设置新值. $perInfo['uid'] = $uid; $perInfo['fuid'] = $parentUId; $perInfo['partid'] = $partid; $perInfo['a_no'] = $ano; $perInfo['family_name'] = $stuInfo['family_name']; $perInfo['given_name'] = $stuInfo['first_name']; $perInfo['gender'] = intval($stuInfo['sex']) === 0 ? 'Male' : 'Female'; $perInfo['date_of_birth'] = intval($stuInfo['birth']); $perInfo['country_of_birth'] = $stuInfo['country']; $perInfo['nationality'] = $stuInfo['nationality']; $otherInfo['uid'] = $uid; $otherInfo['fuid'] = $parentUId; $otherInfo['partid'] = $partid; $otherInfo['s_id'] = $stuId; $otherInfo['a_no'] = $ano; if (empty($perInfo['id'])) { $perInfo['create_time'] = time(); $otherInfo['create_time'] = time(); } // 先验证 per info. $res = $model->validate($model->perInfoRules)->create($perInfo); if (!$res) { $this->error($model->getError()); } $_nationalitys = ['chinese']; // 学生的国藉为 非 Chinese 时必须验证护照 2015-9-19 增加 if (!in_array(strtolower($perInfo['nationality']), $_nationalitys, TRUE)) { $res = $model->validate($model->perInfoRules1)->create($perInfo); if (!$res) { $this->error($model->getError()); } } // other info 验证. // 是否来过英国(ever_to_britain) 为 yes 验证: 签证种类/visa_type, 签证有效期/date_of_expriy, // 第一次入境时间/date_of_first_entry // 支付方式(whoes_payfor) 为 Other 验证: 支付人姓名/whoes_payfor_name, 与支付人关系/payfor_relation // 2015-9-29 增加 是否有困难为 yes 时, 验证困难类型 if (strtolower($otherInfo['ever_to_britain']) === 'yes') { // 是否来过英国 $res = $model->validate($model->otherInfoRules1)->create($otherInfo); if (!$res) { $this->error($model->getError()); } // visa 不为空时, 要验证时间. if (strtolower($otherInfo['visa_type']) != 'no visa required') { $res = $model->validate($model->otherInfoRule4)->create($otherInfo); } } if (strtolower($otherInfo['whoes_payfor']) === 'other') { // 支付方式为 Other $res = $model->validate($model->otherInfoRules2)->create($otherInfo); if (!$res) { $this->error($model->getError()); } } if (strtolower($otherInfo['is_difficulty']) === 'yes') { // 是否有困难为 yes $res = $model->validate($model->otherInfoRules3)->create($otherInfo); if (!$res) { $this->error($model->getError()); } } // 规则验证过了入库操作. $model->startTrans(); // 开启事务. $res = $model->procPerInfo($perInfo, $uid, $stuId, $ano); $res1 = $model->procPerOtherInfo($otherInfo, $uid, $stuId, $ano); if (!$res || !$res1) { $model->rollback(); $this->error('Action failed'); } // 都处理成功, 提交事务. $model->commit(); // 跳转到第三步 $stepUrl = U('addStep3'); $this->myRedirect('addTrans', $stepUrl, $stuId, $uid, $ano, $operFlag); }
/** * 提交申请第 2 步处理. * * @access public * @return void * @author Liuping <*****@*****.**> */ public function appSubmit2Action() { // 校验一级中介是否有权限添加申请 if (!AgentAuth::checkTopAgentOfApply()) { $this->error('No permission'); } // 申请 id $appStatusId = intval(I('post.appStatus', '')); 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'); } // 检查是否已超过允许添加的条数 $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']; // 中介的联系信息 $agentLinkInfo = $modelAppStatus->fetchAgentInfo($uid); // 获取该学生的所有个人信息 // 学生个人详细信息 $perInfo = $modelStu->fetchPerInfo($stuId, $ano); if (empty($perInfo)) { // 新增 $perInfo = $modelStu->fetchPerInfo($stuId, ''); $perInfo['id'] = ''; $perInfo['uid'] = $uid; $perInfo['fuid'] = $fuid; $perInfo['partid'] = $partid; $perInfo['s_id'] = $stuId; $perInfo['a_no'] = $ano; $perInfo['create_time'] = time(); // 将联系电话和邮箱修改成中介的 //$perInfo['contact_number'] = $agentLinkInfo['telephone']; $perInfo['email_address'] = $agentLinkInfo['email']; } // 学生个人其它信息 $perOtherInfo = $modelStu->fetchPerOtherInfo($stuId, $ano); if (empty($perOtherInfo)) { $perOtherInfo = $modelStu->fetchPerOtherInfo($stuId, ''); $perOtherInfo['id'] = ''; $perOtherInfo['uid'] = $uid; $perOtherInfo['fuid'] = $fuid; $perOtherInfo['partid'] = $partid; $perOtherInfo['s_id'] = $stuId; $perOtherInfo['a_no'] = $ano; $perOtherInfo['create_time'] = time(); } // 学生教育背景信息 $eduBackInfo = $modelStu->fetchEduBackInfo($stuId, $ano); if (empty($eduBackInfo)) { $eduBackInfo = $modelStu->fetchEduBackInfo($stuId, ''); foreach ($eduBackInfo as &$row) { $row['id'] = ''; $row['uid'] = $uid; $row['fuid'] = $fuid; $row['partid'] = $partid; $row['s_id'] = $stuId; $row['a_no'] = $ano; $row['create_time'] = time(); } unset($row); } // 语言证书信息 $engCertInfo = $modelStu->fetchEngCertInfo($stuId, $ano); if (empty($engCertInfo)) { $engCertInfo = $modelStu->fetchEngCertInfo($stuId, ''); $engCertInfo['id'] = ''; $engCertInfo['uid'] = $uid; $engCertInfo['fuid'] = $fuid; $engCertInfo['partid'] = $partid; $engCertInfo['s_id'] = $stuId; $engCertInfo['a_no'] = $ano; $engCertInfo['create_time'] = time(); } // 工作经验 $workExpInfo = $modelStu->fetchWorkExpInfo($stuId, $ano); if (empty($workExpInfo)) { $workExpInfo = $modelStu->fetchWorkExpInfo($stuId, ''); if (!empty($workExpInfo)) { foreach ($workExpInfo as &$row) { $row['id'] = ''; $row['uid'] = $uid; $row['fuid'] = $fuid; $row['partid'] = $partid; $row['s_id'] = $stuId; $row['a_no'] = $ano; $row['create_time'] = time(); } unset($row); } } // 推荐人信息 $refereeInfo = $modelStu->fetchRefereesInfo($stuId, $ano); if (empty($refereeInfo)) { $refereeInfo = $modelStu->fetchRefereesInfo($stuId, ''); foreach ($refereeInfo as &$row) { $row['id'] = ''; $row['uid'] = $uid; $row['fuid'] = $fuid; $row['partid'] = $partid; $row['s_id'] = $stuId; $row['a_no'] = $ano; $row['create_time'] = time(); } unset($row); } // 上传信息 $uploadInfo = $modelStu->fetchUploadInfo($stuId, $ano); if (empty($uploadInfo)) { $uploadInfo = $modelStu->fetchUploadInfo($stuId, ''); $uploadInfo['id'] = ''; $uploadInfo['uid'] = $uid; $uploadInfo['fuid'] = $fuid; $uploadInfo['partid'] = $partid; $uploadInfo['s_id'] = $stuId; $uploadInfo['a_no'] = $ano; $uploadInfo['create_time'] = time(); } // 开启事务 $modelStu->startTrans(); $res = $modelStu->procPerInfo($perInfo, $uid, $stuId, $ano); $res1 = $modelStu->procPerOtherInfo($perOtherInfo, $uid, $stuId, $ano); $res2 = $modelStu->procEduBackInfo($eduBackInfo, $uid, $stuId, $ano); $res3 = $modelStu->procEngLangCertInfo($engCertInfo, $uid, $stuId, $ano); $res4 = $modelStu->procWorkExpInfo($workExpInfo, $uid, $stuId, $ano); $res5 = $modelStu->procRefereeInfo($refereeInfo, $uid, $stuId, $ano); $res6 = $modelStu->procUploadInfo($uploadInfo, $uid, $stuId, $ano); if ($res && $res1 && $res2 && $res3 && $res4 && $res5 && $res6) { $modelStu->commit(); } else { $modelStu->rollback(); $this->error('Action failed!'); } $url = 'appSubmit3'; $this->redirect('addTrans', [$this->jumpUrl => $url, $this->jumpInfo => $appStatusId, 'oper' => $operFlag]); }