public function editCampus($id = 0)
 {
     $model = M('special_lottery');
     if (IS_POST) {
         $_POST['start_time'] = strtotime($_POST['start_time']);
         $_POST['end_time'] = strtotime($_POST['end_time']);
         if ($model->create() && $model->save() !== false) {
             $this->success('编辑成功!', U('index'));
         } else {
             $error = $model->getError();
             $this->error(empty($error) ? '未知错误!' : $error);
         }
     } else {
         $info = $model->find($id) or $this->error('找不到此记录信息!');
         $info['start_time'] = date('Y-m-d H:i', $info['start_time']);
         $info['end_time'] = date('Y-m-d H:i', $info['end_time']);
         $university = get_university() or $this->error('请先添加大学信息!');
         $campus_id = $info['campus_id'];
         $university_id = I('university_id', 0) ? I('university_id', 0) : $info['university_id'];
         $campus = $this->_getCampus($university_id);
         $this->assign('_list_university', $university);
         $this->assign('_list_campus', $campus);
         $this->assign('university_id', $university_id);
         $this->assign('campus_id', $campus_id);
         $this->assign('info', $info);
         $this->meta_title = '编辑校区';
         $this->display('campus_edit');
     }
 }
 public function edit($id = 0)
 {
     $model = M('university_college');
     if (IS_POST) {
         $university = M('university')->find(I('post.university_id')) or $this->error('UNIVERSITY_NOT_FOUND', '找不到此学校信息!');
         $_POST['university_name'] = $university['name'];
         $model->create() or $this->error($model->getError());
         $id = $model->id;
         $name = $model->name;
         $ret = $model->save();
         $ret === false and $this->error($model->getError());
         if ($ret) {
             // 存在更新,则同步更新冗余字段
             M('university_college_major')->where('college_id=' . $id)->setField('college_name', $name);
             M('user_info')->where('college_id=' . $id)->setField('college_name', $name);
         }
         $this->success('编辑成功!', U('index'));
     } else {
         $university = get_university();
         $this->assign('_list_university', $university);
         $info = $model->find($id) or $this->error('找不到此记录信息!');
         $this->assign('info', $info);
         $this->meta_title = '编辑学院';
         $this->display();
     }
 }
 public function edit($id = 0)
 {
     $majorModel = M('university_college_major');
     if (IS_POST) {
         $university = M('university')->find(I('post.university_id')) or $this->error('找不到此学校信息!');
         $_POST['university_name'] = $university['name'];
         // 读取学校名称
         $college = M('university_college')->where('id=' . I('post.college_id'))->find() or ajax_error();
         $_POST['university_name'] = $college['university_name'];
         $_POST['college_name'] = $college['name'];
         $majorModel->create() or $this->error($majorModel->getError());
         $id = $majorModel->id;
         $name = $majorModel->name;
         $ret = $majorModel->save();
         $ret === false and $this->error($majorModel->getError());
         if ($ret) {
             // 存在更新,则同步更新冗余字段
             M('user_info')->where('major_id=' . $id)->setField('major_name', $name);
         }
         $this->success('编辑成功!', U('index'));
     } else {
         $info = $majorModel->find($id) or $this->error('找不到此记录信息!');
         $university = get_university() or $this->error('请先添加大学信息!');
         $college_id = $info['college_id'];
         $university_id = $info['university_id'];
         $sel_university_id = I('university_id', 0);
         if ($sel_university_id && $university_id) {
             // 指定了不同的大学
             $university_id = $sel_university_id;
         }
         $college = $this->_getCollege($university_id);
         $this->assign('_list_university', $university);
         $this->assign('_list_college', $college);
         $this->assign('university_id', $university_id);
         $this->assign('college_id', $college_id);
         $this->assign('info', $info);
         $this->meta_title = '编辑学院';
         $this->display();
     }
 }