/** * 考场添加学科 * * @param int $exam_id 考试期次ID * @param int $place_id 考场ID * @return void */ public function index($exam_id = 0, $place_id = 0) { if (!$this->check_power('exam_list,exam_manage')) { return; } if (empty($exam_id) || empty($place_id)) { message('参数错误!'); } $query = "select * from {pre}exam_place where place_id={$place_id}"; $place = $this->db->query($query)->row_array(); if (!$place) { message('未查询到考场信息!'); } $query = "select * from {pre}exam where exam_id={$exam_id}"; $exam = $this->db->query($query)->row_array(); if (!$exam) { message('未查询到考场信息!'); } //获取考试期次下的学科 $exams = $this->db->query("select exam_id,subject_id from {pre}exam where rd_exam.exam_pid={$exam_id}")->result_array(); if (empty($exams)) { message('该考试期次不存在学科!'); } //控制考场只能在未开始考试操作 $no_start = ExamPlaceModel::place_is_no_start($place_id); $place['no_start'] = $no_start; $query = array('exam_pid' => $exam_id, 'place_id' => $place_id); $result = ExamPlaceSubjectModel::get_exam_place_subject_list($query); $old_subjects = array(); foreach ($result as $key => $value) { $old_subjects[$value['subject_id']] = $value; } $data = array(); $data['exam'] = $exam; $data['place'] = $place; //$data['allow_subject'] = CpUserModel::get_allowed_subjects(); $data['subjects'] = $exams; $data['subjects_name'] = C('subject'); $data['old_subjects'] = $old_subjects; $data['priv_manage'] = $this->check_power('exam_manage', FALSE); // 模版 $this->load->view('place_subject/index', $data); }
public function batch_delete() { if (!$this->check_power('exam_manage')) { return; } $ids = $this->input->post('ids'); $place_id = (int) $this->input->post('place_id'); if (empty($ids) or !is_array($ids)) { message('请至少选择一项'); return; } $place = ExamPlaceModel::get_place($place_id); if (!count($place)) { message('考场信息不存在'); return; } //控制考场只能在未开始考试操作 $no_start = ExamPlaceModel::place_is_no_start($place_id); if (!$no_start) { message('该考场正在考试或已结束,无法做此操作'); } $back_url = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER']; if (empty($back_url) && $place_id) { $back_url = 'admin/place_invigilator/index/' . $place_id; } $this->db->where_in('id', $ids)->delete('exam_place_invigilator'); message('删除成功', $back_url); }
public function batch_delete() { if (!$this->check_power('exam_manage')) { return; } $ids = $this->input->post('ids'); $place_id = (int) $this->input->post('place_id'); if (empty($ids) or !is_array($ids)) { message('请至少选择一项'); return; } $place = ExamPlaceModel::get_place($place_id); if (!count($place)) { message('考场信息不存在'); return; } // 控制考场只能在未开始考试操作 $no_start = ExamPlaceModel::place_is_no_start($place_id); if (!$no_start) { message('该考场正在考试或已结束,无法做此操作'); } $back_url = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER']; if (empty($back_url) && $place_id) { $back_url = 'admin/place_student/' . $place_id; } // 删除考试已分配的试卷 $ids_array = array_filter(array_values($ids)); $ids_string = implode(',', $ids_array); $sql = "select group_concat(uid) as uids from {pre}exam_place_student where id in({$ids_string})"; $res = $this->db->query($sql)->row_array(); $uids = $res['uids']; // 查询已分配的试卷编号组合 $sql = "select group_concat(etp_id) as etp_ids from {pre}exam_test_paper where uid in({$uids}) and place_id='{$place_id}' "; $res = $this->db->query($sql)->row_array(); $etp_ids = $res['etp_ids']; if ($etp_ids) { // 删除试卷题目 $sql = "delete from {pre}exam_test_paper_question where etp_id in({$etp_ids})"; $this->db->query($sql); // 删除试卷答案 $sql = "delete from {pre}exam_test_result where etp_id in({$etp_ids})"; $this->db->query($sql); } // 删除试卷 $sql = "delete from {pre}exam_test_paper where uid in({$uids}) and place_id={$place_id}"; $this->db->query($sql); // end $this->db->where_in('id', $ids)->delete('exam_place_student'); message('删除成功', $back_url); }
/** * 监考人员 列表 * * @return void */ public function index() { if (!$this->check_power('exam_list,exam_manage')) { return; } // 查询条件 $query = array(); $param = array(); $search = array(); $place_id = $this->input->get_post('place_id'); if ($place_id) { $db_query = $this->db->select('p.place_id,p.place_name,p.address,e.exam_id,e.exam_name,sch.school_id,sch.school_name')->from('exam_place p')->join('exam e', 'p.exam_pid=e.exam_id')->join('school sch', 'p.school_id=sch.school_id')->where('p.place_id', $place_id)->get(); $place = $db_query->row_array(); } if (empty($place)) { message('考场信息不存在'); } //控制考场只能在未开始考试操作 $no_start = ExamPlaceModel::place_is_no_start($place_id); if (!$no_start) { message('该考场正在考试或已结束,无法做此操作'); } $data['place'] = $place; $search['place_id'] = $place_id; $param[] = "place_id={$place_id}"; $page = (int) $this->input->get_post('page'); $page = $page ? $page : 1; $per_page = (int) $this->input->get_post('per_page'); $per_page = $per_page ? $per_page : 10; $order_bys = array('email' => 'invigilator_email', 'name' => 'invigilator_name', 'memo' => 'invigilator_memo', 'time' => 'invigilator_addtime'); $order = $this->input->get_post('order'); !$order && ($order = 'time'); $search['order'] = $order; $param[] = "order={$order}"; $order_type = $this->input->get_post('order_type'); !$order_type && ($order_type = 'desc'); $search['order_type'] = $order_type; $param[] = "order_type={$order_type}"; $order_by = $order_bys[$order] . ' ' . $order_type; $selectWhat = '*'; //拼接查询条件 $query_email = $this->input->get_post('email'); if ($query_email) { $query['invigilator_email'] = trim($query_email); $search['email'] = $query_email; $param[] = "email={$query_email}"; } $query_name = $this->input->get_post('name'); if ($query_name) { $query['invigilator_name'] = trim($query_name); $search['name'] = $query_name; $param[] = "name={$query_name}"; } $query_flag = $this->input->get_post('flag'); if ($query_flag) { $query['invigilator_flag'] = is_string($query_flag) ? (int) $query_flag : $query_flag; $search['flag'] = $query_flag; $param[] = "flag={$query_flag}"; } $query_is_trash = (int) $this->input->get_post('trash'); if ($query_is_trash) { $query['invigilator_flag'] = '-1'; $search['trash'] = $query_is_trash; $param[] = "trash={$query_is_trash}"; } else { $query['invigilator_flag'] = array('0', '1'); } $query_begin_time = $this->input->get_post('begin_time'); if ($query_begin_time) { $query['invigilator_addtime'] = array('>=' => strtotime($query_begin_time)); $search['begin_time'] = $query_begin_time; $param[] = "begin_time={$query_begin_time}"; } $query_end_time = $this->input->get_post('end_time'); if ($query_end_time) { if (!isset($query['invigilator_addtime'])) { $query['invigilator_addtime'] = array(); } $query['invigilator_addtime']['<='] = strtotime($query_end_time); $search['end_time'] = $query_end_time; $param[] = "end_time={$query_end_time}"; } //查看已分配 $has_assigned = intval($this->input->get_post('has_assigned')); if (!$query_is_trash) { if ($has_assigned) { $search['has_assigned'] = $has_assigned; $param[] = "has_assigned={$has_assigned}"; $result = ExamInvigilatorModel::get_invigilator_list($query, $page, $per_page, $order_by, $selectWhat, $place_id); } else { $result = ExamInvigilatorModel::get_invigilator_list($query, $page, $per_page, $order_by, $selectWhat, $place_id, true); } } else { $result = ExamInvigilatorModel::get_invigilator_list($query, $page, $per_page, $order_by, $selectWhat); } $tmp_result = array(); if (count($result)) { foreach ($result as $v) { if ($query_is_trash) { $recycle = RecycleModel::get_recycle_list(array('type' => RECYCLE_EXAM_INVIGILATOR, 'obj_id' => $v['invigilator_id']), null, null, 'ctime asc'); $v['recycle'] = $recycle; } else { $v['recycle'] = array(); } $tmp_result[] = $v; } } // 分页 $purl = site_url('admin/exam_invigilator/index/') . (count($param) ? '?' . implode('&', $param) : ''); if ($has_assigned) { $total = ExamInvigilatorModel::count_invigilator_lists($query, $place_id); } else { $total = ExamInvigilatorModel::count_invigilator_lists($query, $place_id, true); } $data['pagination'] = multipage($total, $per_page, $page, $purl); $data['search'] =& $search; $data['list'] =& $tmp_result; //排序地址 unset($param['order=']); unset($param['order_type=']); $order_url = site_url('admin/exam_invigilator/index/') . (count($param) ? '?' . implode('&', $param) : ''); $data['order_url'] = $order_url; $data['priv_manage'] = $this->check_power('exam_manage', FALSE); // 模版 $this->load->view('exam_invigilator/index', $data); }
/** * 测试报名 * @param int $exam 期次id * @param int $place 场次id, 多个ID用英文逗号分隔开 * @param int $p_id 产品id * @return json 成功/失败 */ public function place_in() { $exam = intval($this->input->post('exam')); $place = $this->input->post('place'); $uid = $this->session->userdata('uid'); $p_id = intval($this->input->post('p_id')); $force = intval($this->input->post('force')); $b_pushcourse = intval($this->input->post('b_pushcourse')); if (!Validate::isJoinedIntStr($place)) { output_json(CODE_ERROR, '报名失败,考场不正确'); } // 检查是否存在该学生 $account = StudentModel::get_student($uid, 'account,account_status'); if (!count($account['account'])) { output_json(CODE_ERROR, '报名失败,不存在该学生.'); } else { if ($account['account_status']) { output_json(CODE_ERROR, '报名失败,学生帐号已被冻结'); } } if (CommonModel::get_product_trans($p_id, $uid, $place, $exam)) { output_json(CODE_ERROR, '报名失败,已报名该产品'); } $res = CommonModel::get_product_list($p_id); if (!$res) { output_json(CODE_ERROR, '报名失败,产品不存在'); } else { $price = $b_pushcourse ? $res['p_price_pushcourse'] : $res['p_price']; $pc_id = $res['pc_id']; } $account = $account['account']; $account1 = $account - $price; if ($account1 < 0) { output_json(CODE_ERROR, '帐号余额不足'); } $inserts = array(); $error = array(); $code = CODE_ERROR; $place_id_arr = array_unique(explode(',', $place)); $place_id_arr2 = array(); foreach ($place_id_arr as $place_id) { if ($place_id) { $query = $this->db->select('p.*,e.exam_name,e.exam_id,e.exam_pid,e.grade_id')->from('exam_place p')->join('exam e', 'p.exam_pid=e.exam_id')->where(array('p.place_id' => $place_id))->get(); $place = $query->row_array(); } else { continue; } if (empty($place)) { $error[] = "考场[{$place_id}]信息不存在"; //output_json(CODE_ERROR, '考场信息不存在'); continue; } $ids = $uid; // 控制考场只能在未开始考试操作 $no_start = ExamPlaceModel::place_is_no_start($place_id); if (!$no_start) { $error[] = "考场[{$place_id}]正确考试或已结束,无法报名"; continue; //output_json(CODE_ERROR, '该考场正在考试或已结束,无法做此操作'); } // $ids = my_intval($ids); // $school_id = (int)$this -> input ->post('school_id'); // 该考场所考到的学科 $subject_ids = array(); $query = $this->db->select('subject_id')->from('exam_place_subject')->where(array('place_id' => $place['place_id']))->get(); $subjects = $query->result_array(); $subject_ids = array(); foreach ($subjects as $subject) { $subject_ids[] = $subject['subject_id']; } $subject_ids = count($subject_ids) ? implode(',', $subject_ids) : '""'; $place['start_time'] = $place['start_time'] + 1; $place['end_time'] = $place['end_time'] - 1; if ($force == 0) { $sql = "SELECT count(u.uid) FROM rd_student u\n WHERE u.grade_id={$place['grade_id']} AND u.is_delete=0 AND u.uid ={$ids}"; $query = Fn::db()->fetchOne($sql); if ($query == 0) { $error[] = "考场[{$place_id}]您的年级不符合要求"; $code = -2; continue; //output_json('-2', '你的年级不符合要求'); } } $not_exists_sql = <<<EOT SELECT uid FROM rd_exam_place_student ps, rd_exam_place p, rd_exam e WHERE e.exam_isfree = 0 AND ps.place_id = p.place_id AND p.place_index = {$place['place_index']} AND ps.uid = u.uid AND p.exam_pid = e.exam_id AND ( ( (p.start_time >= {$place['start_time']} AND p.start_time <= {$place['end_time']} ) OR ( p.end_time >= {$place['start_time']} AND p.end_time <= {$place['end_time']} ) OR ( p.start_time <= {$place['start_time']} AND p.end_time >= {$place['end_time']} ) ) OR p.place_id IN ( SELECT DISTINCT(place_id) FROM rd_exam_place_subject eps WHERE eps.subject_id IN ({$subject_ids}) AND eps.exam_pid = {$place['exam_id']} ) ) EOT; $sql = <<<EOT SELECT u.uid FROM rd_student u WHERE u.is_delete = 0 AND u.uid = {$ids} AND NOT EXISTS({$not_exists_sql}) EOT; $tmp_inserts = array(); $query = $this->db->query($sql); foreach ($query->result_array() as $row) { $vrow = array('place_id' => $place_id, 'uid' => $row['uid']); $tmp_inserts[] = $vrow; $inserts[] = $vrow; } if (empty($tmp_inserts)) { $error[] = "考场[{$place_id}]时间段内您已经参加了相同时间段其它考试"; continue; //output_json(CODE_ERROR, '你已经参加相同时间段其他考试'); } $place_id_arr2[] = $place_id; } if (!empty($error) || empty($inserts)) { output_json($code, "报名失败\n" . implode("\n", $error)); } $vc = C('virtual_currency'); $pt_log = $account . $vc['name'] . '--' . $account1 . $vc['name']; $txt_account = -$price; $db = Fn::db(); $flag = false; if ($db->beginTransaction()) { foreach ($inserts as $val) { $db->replace('rd_exam_place_student', $val); } $param = array('tr_uid' => $uid, 'tr_type' => 3, 'tr_pid' => $p_id, 'tr_flag' => 1, 'tr_money' => $account1, 'tr_trade_amount' => $txt_account, 'tr_comment' => $pt_log); $number = TransactionRecordModel::addTransactionRecord($param); if ($b_pushcourse) { $now = date('Y-m-d H:i:s'); foreach ($place_id_arr2 as $place_id) { $db->insert('t_course_push', array('cp_stuuid' => $uid, 'cp_exampid' => $exam, 'cp_examplaceid' => $place_id, 'cp_addtime' => $now)); } } $sql = <<<EOT UPDATE rd_student SET account = account - {$price} WHERE uid = {$uid} EOT; $db->exec($sql); $flag = $db->commit(); if (!$flag) { $db->rollBack(); $error[] = "考场[{$place_id}]报名失败"; } } if (!$flag) { output_json(CODE_ERROR, "报名失败\n" . implode("\n", $error)); } else { output_json(CODE_SUCCESS, '报名成功.'); } }