Esempio n. 1
0
 /**
  * @description 编辑学生信息保存数据库
  * @author
  * @final
  * @param $act 编辑类型[新增/更新]
  * @param int $uid 学生id
  */
 public function update()
 {
     if (!$this->check_power('student_manage')) {
         return;
     }
     $tab = $this->input->post('tab_name');
     $act = $this->input->post('act') == 'add' ? 'add' : 'edit';
     if ($act == 'add') {
         $student['password'] = trim($this->input->post('password'));
         $student['source_from'] = 1;
         //后台添加
         $tab = '';
     } else {
         $uid = intval($this->input->post('uid'));
         $old_student = StudentModel::get_student($uid);
         $student['uid'] = $uid;
         if (empty($old_student)) {
             message('学生信息不存在!');
             return;
         }
     }
     if ($old_student['email'] != trim($this->input->post('email'))) {
         $student['email_validate'] = 0;
     }
     $student['email'] = trim($this->input->post('email'));
     $student['first_name'] = trim($this->input->post('first_name'));
     $student['last_name'] = trim($this->input->post('last_name'));
     $student['birthday'] = strtotime($this->input->post('birthday'));
     $student['idcard'] = trim($this->input->post('idcard'));
     $student['sex'] = intval($this->input->post('sex')) == 1 ? 1 : 2;
     //$student['province']  = intval($this->input->post('province'));
     //$student['city']      = intval($this->input->post('city'));
     //$student['area']      = intval($this->input->post('area'));
     $student['grade_id'] = intval($this->input->post('grade_id'));
     $student['school_id'] = intval($this->input->post('school_id_0'));
     $student['address'] = trim($this->input->post('address'));
     $student['zipcode'] = trim($this->input->post('zipcode'));
     $student['mobile'] = trim($this->input->post('mobile'));
     $school_id_arr = $this->input->post('school_id');
     $volunteer_arr = $this->input->post('volunteer');
     if (empty($volunteer_arr[a])) {
         $school_id_arr[a] = '';
     }
     if ($tab == 'awards' || $tab == '') {
         if (intval($school_id_arr[a]) == 0 && $student['grade_id'] == 6 && $act == 'edit') {
             $school_id_arr[a] = -1;
             if ($act == 'edit') {
                 message('第一志愿不能为空', 'admin/student/edit/' . $uid);
             } else {
                 message('第一志愿不能为空');
             }
         }
     }
     if (empty($volunteer_arr[b])) {
         $school_id_arr[b] = '';
     }
     if (empty($volunteer_arr[c])) {
         $school_id_arr[c] = '';
     }
     $volunteer = json_encode($school_id_arr);
     //将升学志愿学校id转换为json值
     $extends = array();
     $msg = $this->_check_student($student, $extends, $act, $tab);
     if ($msg) {
         $tmp_msg = array();
         foreach ($msg as $k => $item) {
             $k = $k + 1;
             $tmp_msg[] = "{$k}、{$item}";
         }
         if ($act == 'edit') {
             message(implode("\n", $tmp_msg), 'admin/student/edit/' . $uid);
         } else {
             message(implode("\n", $tmp_msg));
         }
     }
     /*
      * 补充学生的所在区域
      * 根据学生所选的学校更新学生所在地区
      */
     $school = SchoolModel::schoolInfo($student['school_id'], 'province,city,area');
     $student['province'] = isset($school['province']) ? $school['province'] : 0;
     $student['city'] = isset($school['city']) ? $school['city'] : 0;
     $student['area'] = isset($school['area']) ? $school['area'] : 0;
     if ($act == 'add') {
         $result = StudentModel::add($student, $extends);
     } else {
         $result = StudentModel::update($student, $extends, $tab);
     }
     if ($tab == 'awards' || $tab == 'wish' || $tab == '') {
         if ($volunteer) {
             $student_wish = array('uid' => $uid, 'music' => '', 'sport' => '', 'painting' => '', 'other' => '', 'wish' => '', 'upmethod' => '', 'volunteer' => $volunteer);
         }
         if ($act == 'add') {
         } else {
             $db = Fn::db();
             $swv = $db->fetchRow("SELECT volunteer FROM rd_student_wish WHERE uid = {$uid}");
             if ($swv) {
                 $db->update('rd_student_wish', $student_wish, "uid={$uid}");
             } else {
                 $db->insert('rd_student_wish', $student_wish);
             }
         }
     }
     if ($result['success'] == TRUE) {
         if ($act == 'add') {
             $msg = '学生信息添加成功';
             admin_log('add', 'student', $result['uid']);
             $uid = $result['uid'];
         } else {
             $msg = '学生信息修改成功';
             admin_log('edit', 'student', $uid);
             // 如果上传新图片,则删除旧图片文件
             if (!empty($student['picture']) && $old_student['picture'] && is_file(_UPLOAD_ROOT_PATH_ . $old_student['picture'])) {
                 @unlink(_UPLOAD_ROOT_PATH_ . $old_studnet['picture']);
             }
         }
         if ($tab == 'base' || $tab == '') {
             //=========================
             $sbinfo = array();
             $sbinfo['sb_addr_provid'] = intval($this->input->post('sb_addr_provid'));
             $sbinfo['sb_addr_cityid'] = intval($this->input->post('sb_addr_cityid'));
             $sbinfo['sb_addr_areaid'] = intval($this->input->post('sb_addr_areaid'));
             $sbinfo['sb_addr_desc'] = trim($this->input->post('sb_addr_desc'));
             // 培训机构、培训课程、授课教师
             $sbcinfo = array();
             $sbcinfo['no_tiid'] = intval($this->input->post('no_tiid'));
             $sbcinfo['sbc_tiid'] = intval($this->input->post('sbc_tiid'));
             $sbcinfo['ti_name'] = trim($this->input->post('ti_name'));
             $sbcinfo['sbc_corsid'] = intval($this->input->post('sbc_corsid'));
             $sbcinfo['cors_cmid'] = intval($this->input->post('cors_cmid'));
             $sbcinfo['cors_name'] = trim($this->input->post('cors_name'));
             $sbcinfo['sbc_teachers'] = trim($this->input->post('sbc_teachers'));
             $sbs_stunumtype = $this->input->post('sbs_stunumtype');
             if (!is_array($sbs_stunumtype)) {
                 $sbs_stunumtype = array();
             }
             $sbclassid_classid = $this->input->post('sbclassid_classid');
             if (!is_array($sbclassid_classid)) {
                 $sbclassid_classid = array();
             }
             //==========================
             $db = Fn::db();
             $bOk = false;
             try {
                 if ($db->beginTransaction()) {
                     $db->delete('t_student_base', "sb_uid = {$uid}");
                     $sbinfo['sb_uid'] = $uid;
                     $db->insert('t_student_base', $sbinfo);
                     $db->delete('t_student_base_classid', "sbclassid_uid = {$uid}");
                     foreach ($sbclassid_classid as $v) {
                         $db->insert('t_student_base_classid', array('sbclassid_uid' => $uid, 'sbclassid_classid' => $v));
                     }
                     $db->delete('t_student_base_stunumtype', "sbs_uid = {$uid}");
                     foreach ($sbs_stunumtype as $v) {
                         $db->insert('t_student_base_stunumtype', array('sbs_uid' => $uid, 'sbs_stunumtype' => $v));
                     }
                     $db->delete('t_student_base_course', 'sbc_uid = ' . $uid);
                     if (empty($sbcinfo['no_tiid'])) {
                         $now_time = time();
                         $db->insert('t_student_base_course', array('sbc_uid' => $uid, 'sbc_idx' => 0, 'sbc_tiid' => $sbcinfo['sbc_tiid'], 'sbc_corsid' => $sbcinfo['sbc_corsid'], 'sbc_teachers' => $sbcinfo['sbc_teachers']));
                     }
                     $bOk = $db->commit();
                     if (!$bOk) {
                         $err = $db->errorInfo()[2];
                         $db->rollBack();
                         message($msg . '   ' . $err, 'admin/student/edit/' . $uid, 'success');
                     }
                 }
                 if (!$bOk) {
                     message($msg . '   保存学习概况信息事务处理失败', 'admin/student/edit/' . $uid, 'success');
                 } else {
                     message($msg . '   保存学习概况信息成功', 'admin/student/edit/' . $uid, 'success');
                 }
             } catch (Exception $e) {
                 message($msg . '   ' . $e->getMessage(), 'admin/student/edit/' . $uid, 'success');
             }
         }
         message($msg, 'admin/student/edit/' . $uid);
     } else {
         message($result['msg'], 'admin/student/edit/' . $uid);
     }
 }