public function uploadImportStudentAction() { $this->view->disable(); if ($this->request->hasFiles()) { foreach ($this->request->getUploadedFiles() as $file) { if (!in_array($file->getExtension(), Config('CONFIG_UPLOAD_EXT_EXCEL'))) { return $this->displayAjax(false, '格式不正确,目前上传的格式是' . $file->getExtension() . ',请上传 ' . implode(',', Config('CONFIG_UPLOAD_EXT_EXCEL')) . ' 格式的文件'); } if ($file->getSize() <= 0) { return $this->displayAjax(false, '上传的文件为空'); } $grades = st_school_type($this->user->getSchoolId()); $grades_flip = array_flip($grades); $this->db->begin(); //获取所有班级 $classes = self::$service->getClassesForSchool($this->user->getSchoolId()); $excel = st_excel($file->getTempName()); $highestRow = $excel['sheet']->getHighestRow(); // 取得总行数 $highestColumn = $excel['sheet']->getHighestColumn(); // 取得总列数 for ($j = 1; $j <= $highestRow; $j++) { $grade_class = $excel['obj']->getActiveSheet()->getCell("A" . $j)->getValue(); //获取A列的值 $name = $excel['obj']->getActiveSheet()->getCell("B" . $j)->getValue(); //获取B列的值 $std_no = $excel['obj']->getActiveSheet()->getCell("C" . $j)->getValue(); //获取C列的值 $sex = $excel['obj']->getActiveSheet()->getCell("D" . $j)->getValue(); //获取D列的值 //对年级班级进行拆分 $grade_tmp = mb_substr($grade_class, 0, 3, 'utf-8'); if (!isset($grades_flip[$grade_tmp])) { $this->db->rollback(); return $this->displayAjax(false, '年级(' . $grade_tmp . ')不存在,无法添加'); } $class_tmp_key = false; $class_tmp = mb_substr($grade_class, 3, mb_strlen($grade_class) - 3, 'utf-8'); foreach ($classes as $cls) { if ($cls->getName() == $class_tmp and $grades_flip[$grade_tmp] == $cls->getGradeId()) { $class_tmp_key = $cls->getId(); break; } } if ($class_tmp_key === false) { $this->db->rollback(); return $this->displayAjax(false, '班级(' . $class_tmp . ')不存在,请先添加'); } $data = []; $data['classes_id'] = $class_tmp_key; $data['type'] = 1; $data['username'] = $std_no . st_rand(); $data['salt'] = st_rand(); $data['password'] = st_md5('123456', $data['salt']); $data['std_number'] = $std_no; $data['real_name'] = $name; $data['sex'] = $sex == '男' ? 1 : 2; $data['credit'] = $data['mobile'] = $data['email'] = $data['parent_id'] = $data['parent_id'] = 0; $data['school_id'] = $this->user->getSchoolId(); //重名问题 $if = self::$service->getCommon(['classes_id=:classes_id: and school_id=:school_id: and real_name=:real_name:', 'bind' => ['classes_id' => $class_tmp_key, 'school_id' => $this->user->getSchoolId(), 'real_name' => $name]], 'User', true); if ($if) { $this->db->rollback(); return $this->displayAjax(false, '学生(' . $name . ')已经存在,请不要重复导入'); } $res = self::$service->insertCommon($data, 'User'); if ($res !== true) { $this->db->rollback(); return $this->ajax($res); } } $this->db->commit(); break; } $this->displayAjax(true); } else { $this->displayAjax(false, '没有检测到上传的文件'); } }
function st_order_number() { return date('YmdHis') . st_rand(); }
public function editPasswordAction() { $this->thisController->tag->prependTitle('修改密码'); $form = new UserPasswordEditForm(); $this->thisController->assign('form', $form); if (IS_POST) { //验证数据 if (!$form->isValid($this->thisController->request->getPost())) { foreach ($form->getMessages() as $message) { return $this->thisController->flash->error($message); } } //验证原始密码是否正确 $old_password = st_md5($this->thisController->request->getPost('old_password'), $this->thisController->user->getSalt()); if ($old_password != $this->thisController->user->getPassword()) { return $this->thisController->flash->error('原始密码不正确'); } //新密码 $rand = st_rand(); $new_password = st_md5($this->thisController->request->getPost('new_password'), $rand); $data = ['password' => $new_password, 'salt' => $rand]; if (!self::$service->updateCommon($data, $this->thisController->user)) { $this->thisController->flash->error('更新数据失败'); } $this->thisController->redirect('/home/user/editPassword'); } }