Esempio n. 1
0
 /**
  * 添加学生 第 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);
 }
Esempio n. 2
0
 /**
  * 提交申请第 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]);
 }