/** * 添加学生 第 1 步提交处理. * * @access public * @return void * @author Liuping <*****@*****.**> */ public function addStep1Action() { // 当前操作, 参见第 1 步中说明. $operFlag = intval(I('post.oper', 1)); $data = I('post.'); $this->autoFieldMap($data, $this->baseInfoMaps); // 转换字段名 $lastStuId = $data['id']; if (empty($lastStuId)) { $data['create_time'] = time(); } // 上级中介 uid $data['fuid'] = $this->getParentAgentUId(); $partid = $data['partid']; // 部门id, 没有选择部门时计算 if (empty($partid)) { $partid = $this->getDeptId(); } else { $partid = intval($partid); } $data['partid'] = $partid; // 先验证规则. $model = new MemberStuModel(); // 2015-9-1 liuping 增加, 处理表中增加 is_mod 字段作为该学生6项基本信息是否可以修改判断 $res = TRUE; // 验证状态, 默认验证通过 if (!empty($lastStuId)) { $stuInfo = $model->fetchStuInfo($lastStuId); if (empty($stuInfo)) { $this->error('Parameters error'); } $res = AgentAuth::checkStu(intval($lastStuId), [AgentAuth::WRITE]); if (9 !== $res['status']) { $this->error('No permission'); } // 是否可以修改, 可以修改就要执行验证规则 $is_mod = isset($stuInfo['is_mod']) ? intval($stuInfo['is_mod']) : 0; if (0 === $is_mod) { // 可以修改, 执行验证 $res = $model->validate($model->baseInfoRules)->create($data); } else { $res = TRUE; } } else { // 新增时执行的验证 $res = $model->validate($model->baseInfoRules)->create($data); } if (!$res) { // 验证失败 $this->error($model->getError()); } // 验证成功规则能过, 验证是否有添加学生的权限 // 校验一级中介是否有权限添加学生 if (!AgentAuth::checkTopAgentOfStu($data['uid'])) { $this->error('No permission'); } // 验证是否有该学生资料. $res1 = $this->checkBaseInfo($data); if ($res1) { $this->error('This student has been added previously!'); } // 字段规则验证成功且不重名. if ($res && !$res1) { $data['birth'] = dateToTimestamp($data['birth']); $res = $model->procBaseInfo($data); if (!$res) { // 添加或修改失败 $this->error('Action failed'); } // 新增时, 获取到最近一次 id if (empty($lastStuId)) { $lastStuId = $model->getLastInsID(); } // 写入系统日志 $_mark = session('username') . '在' . date('Y-m-d H:i:s') . ', 编辑了一个学生, 学生姓名: ' . $stuInfo['first_name'] . $stuInfo['family_name']; if (2 === $operFlag) { // 写入编辑日志 system_log($_mark, $model->getTableName(), $lastStuId, 'e', $data, $stuInfo, 1); } } $stepUrl = U('addStep2'); $stuId = $lastStuId; $uid = $data['uid']; $this->myRedirect('addTrans', $stepUrl, $stuId, $uid, '', $operFlag); }