/** * 试题广场 */ public function getIndex() { //只显示职业方向和公司分类 $cate_info = Category::where('pid', '0')->select(['_id', 'cate_name'])->get(); foreach ($cate_info as $k => &$val) { if ($val->cate_name == '知识点') { $tmp_cate = Category::where('pid', (string) $val->_id)->where('level', '2')->select(['_id', 'cate_name'])->get(); $val['two_cate'] = $tmp_cate; foreach ($tmp_cate as $kk => &$vv) { $tmp_zhishi = Category::where('pid', (string) $vv->_id)->select(['_id', 'cate_name'])->get(); $vv['zhishi'] = $tmp_zhishi; } } else { $tmp_cate = Category::where('pid', (string) $val->_id)->select(['_id', 'cate_name'])->get(); $val['two_cate'] = $tmp_cate; } } //print_R($cate_info);die; $url = array(); //默认显示最新 if (!empty($_GET['is_hot'])) { $id = $_GET['is_hot']; $where['is_hot'] = '1'; $url['is_hot'] = '1'; } else { $id = ''; $where['is_news'] = '1'; } //搜索 $choose_cate = array(); $par = array(); $par_arr = array(); $q_type = array(); if (!empty($_GET['par'])) { $par = explode('_', $_GET['par']); $par_arr = $par; $url['par'] = $_GET['par']; $choose_cate = Category::whereIn('_id', $par)->orwhereIn('cate_name', $par)->select(['_id', 'cate_name'])->get(); foreach ($par as $k => $v) { $reg = "/^[\\x{4e00}-\\x{9fa5}]+\$/u"; $res = preg_match($reg, $v); if ($res) { $q_type[] = $par[$k]; unset($par[$k]); } } if ($par) { $exam_info = Exam::whereIn('job', $par)->orwhereIn('company_id', $par)->orwhereIn('zhishi', $par)->where($where)->get(); } else { $exam_info = Exam::where($where)->get(); } } else { $exam_info = Exam::where($where)->get(); } $id_arr = array(); foreach ($exam_info as $k => $val) { $id_arr[] = $val->_id; } if (!$q_type) { $question_info = Question::whereIn('e_id', $id_arr)->select(['q_title'])->paginate(10); } else { $question_info = Question::whereIn('e_id', $id_arr)->whereIn('q_type', $q_type)->select(['q_title'])->paginate(10); } //print_R($question_info); $question_info->setPath('index'); return view('square.square', ['cate_info' => $cate_info, 'question_info' => $question_info, 'id' => $id, 'choose_cate' => $choose_cate, 'par_arr' => $par_arr, 'url' => $url]); }