/** * 提交申请第 1 步处理. * * @access public * @return void * @author Liuping <*****@*****.**> */ public function appSubmit1Action() { // 校验一级中介是否有权限添加申请 if (!AgentAuth::checkTopAgentOfApply()) { $this->error('No permission'); } $post = I('post.'); $studentId = intval(I('post.studentId', '')); $data = []; // 待写入的数据 // 操作类型 1 : 添加, 2 : 编辑 $operFlag = intval(I('post.oper', 1)); // 根据操作类型, 设置不同的权限 $authRule = []; if (1 === $operFlag) { $authRule[] = AgentAuth::ADD; } else { $authRule[] = AgentAuth::WRITE; } if (empty($studentId)) { $this->error('Parameters error'); } // 实例化学生模型 $modelStu = new MemberStuModel(); $stuInfo = $modelStu->fetchStuInfo($studentId); if (empty($stuInfo)) { $this->error('Parameters error'); } // 0 表示个人信息不完整, 不能申请 if ($stuInfo['is_complete'] < 1) { $this->error('Please completed application materials before apply!'); } // 权限验证 $res = AgentAuth::checkStu($studentId, $authRule); if ($res['status'] !== 9) { $this->error('No permission'); } // ApplyStatus 模型 $modelApplyStatus = new ApplyStatusModel(); $appId = intval(I('post.appId', '')); $uid = session('uid'); // 当前登录用户, 也就是添加申请的中介 UID $parentAgentUId = session('agentPid'); // 上级中介 id $partid = session('agentPartId'); // 当前用户所属部门 id // 赋值 $data['id'] = $appId; $data['type'] = I('post.selectType', ''); $data['family_name'] = $stuInfo['family_name']; $data['first_name'] = $stuInfo['first_name']; $data['sex'] = $stuInfo['sex']; $data['birth'] = $stuInfo['birth']; $data['country'] = $stuInfo['country']; $data['nationality'] = $stuInfo['nationality']; $data['year'] = I('post.selectYear', ''); $data['us_id'] = I('post.selectSchool', ''); $data['main_sub_id'] = I('post.selectMainSub', ''); $data['child_sub_id'] = I('post.selectChildSub', ''); $data['mj_id'] = I('post.selectCourse', ''); $data['month'] = I('post.selectMonth', ''); if (empty($appId)) { // 新增时 $data['uid'] = $uid; $data['fuid'] = $parentAgentUId; $data['partid'] = $partid; $data['s_no'] = $stuInfo['id']; $data['a_no'] = getApplyNo(); $data['c_time'] = time(); } else { $data['s_no'] = $stuInfo['id']; $data['e_time'] = time(); } // 执行验证规则 $res = $modelApplyStatus->validate($modelApplyStatus->appStatusInfoRules)->create($data); if (!$res) { $this->error($modelApplyStatus->getError()); } // 检查是否已超过允许添加的条数 $res = $modelApplyStatus->checkApplyNum($data['year'], $data['s_no']); if ($res) { // 超过申请次数跳转到中介未申请学生列表 $msg = 'The application amount of ' . $data['year'] . ' entry for this student has run out.'; $this->error($msg, U('Student/noApplyStudentList')); } // 检查同一学生是否已申请过同一专业 $res = $modelApplyStatus->checkExistsApply($data['id'], $data['year'], $studentId, $data['us_id'], $data['mj_id']); if ($res) { $msg = 'This student has applied for this course for ' . $data['year'] . ' entry, cannot re-apply'; $this->error($msg); } // 新增或修改 $res = $modelApplyStatus->procAppStatusInfo($data, $uid, $stuInfo['id']); if (!$res) { $this->error('Action failed!'); } // 如果新添加, 获取最近一次 id if (empty($appId)) { $appId = $modelApplyStatus->getLastInsID(); } // 写入系统日志 $_appOldInfo = $modelApplyStatus->find($appId); if (!empty($_appOldInfo)) { $_mark = session('username') . '在' . date('Y-m-d H:i:s') . ', 编辑了一个申请资料, 申请编号: ' . $data['a_no'] . ', 学生姓名: ' . $_appOldInfo['first_name'] . $_appOldInfo['family_name']; system_log($_mark, $modelApplyStatus->getTableName(), $_appOldInfo['a_no'], 'e', $data, $_appOldInfo, 1); } $url = 'appSubmit2'; $this->redirect('addTrans', [$this->jumpUrl => $url, $this->jumpInfo => $appId, 'oper' => $operFlag]); }