post('id',0); $duration = $request->post('duration',0); $leval_time = $request->post('leval_time',0); $score = $request->post('score',0); $scoreTotal = $request->post('scoreTotal',0); $list = $request->post('list',[]); if(!$id) { return sparkSuccess(dataReturn(-1,'提交失败,请联系工作人员')); } $user_exam_time = $duration*60 - $leval_time; $code = exam_code(); # 提交编号 $examModel = new Exam(); # 试卷 $examData['user_id'] = $userId; # 答题用户id $examData['score'] = $score; # 试卷分数 $examData['total_score'] = $scoreTotal; # 用户得分 $examData['exam_time'] = $duration*60; # 试卷考试时长 $examData['user_exam_time'] = $user_exam_time; # 用户答卷时长 $examData['exam_code'] = $code; # 试卷编码 $examData['add_time'] = date('Y-m-d H:i:s'); # 试卷编码 $res = $examModel->insert($examData); $questionlogModel = new QuestionLog();# 试卷试题 if ($res) { foreach ($list as $k=>$v) { $inserData = [ 'exam_code' => $code, 'question_id' => $v['id'], 'question_name' => $v['question_name'], 'question_type' => $v['question_type'], 'user_answer' => $v['user_answer'], 'answer' => $v['answer'], 'score' => $v['score'], 'user_score' => $v['user_score'], 'q_options' => empty($v['q_options']) ? '' :json_encode($v['q_options']) ]; $questionlogModel->insert($inserData); } } return sparkSuccess(dataReturn(0,'提交成功')); } public function getQuestion(Request $request) { $id = $request->get('id',0); if(!$id) { return sparkSuccess(dataReturn(-1,'获取测评信息失败')); } $managent = new Managent(); $managent_info = $managent->find($id); if(!$managent_info) { return sparkSuccess(dataReturn(-1,'获取测评信息失败')); } //自动选题 if($managent_info['question_type'] == 1) { $question_info = $this->setQuestion(); $managent_info['question_num'] = $question_info['question_num']; $managent_info['score'] = $question_info['score']; $managent_info['list'] = $question_info['list']; $managent_info['duration'] = $question_info['exam_time']; }else{ $question_option = json_decode($managent_info['question'],true); $score=0; foreach($question_option as $v) { $score += $v['score']; } $managent_info['score'] = $score; $managent_info['question_num'] = count($question_option); $managent_info['list'] = $question_option; } return sparkSuccess(dataReturn(0,'获取成功',$managent_info)); } public function setQuestion() { $examModel = new Con(); $examConfig = $examModel->first()->toArray(); $questionList=[]; $question = new Question(); $proportion = \json_decode($examConfig['proportion'],true); $score=0; foreach($proportion as $val) { $where=[]; $where[]=['question_type','=',$val['question_type']]; $where[]=['status','=',1]; $where[]=['difficulty','=',$examConfig['difficulty']]; $question_list = $question->getAllList($where,['id','question_name','question_type','difficulty','answer','q_options']); shuffle($question_list); $question_list = array_slice($question_list,0,$val['question_num']); foreach($question_list as &$item) { $item['q_options'] = json_decode($item['q_options'],true); $item['score'] = $val['score']; $score += $val['score']; } $questionList = array_merge($questionList,$question_list); } $res['exam_time'] = $examConfig['exam_time']; # 考试时长 $res['question_num'] = count($questionList); # 总题数 $res['score'] = $score; # 总分数 $res['list'] = $questionList; # 总分数 return $res; } }