member_id; $data = $this->request->params([ ["table_type",0] ]); return success((new TeachingResearchService())->list($id,$data['table_type'])); } //教研管理文章详情 public function info($id){ return success((new TeachingResearchService())->info($id)); } //获取能看的教研管理类型 public function lookType(){ $id = $this->member_id; return success((new TeachingResearchService())->lookType($id)); } //获取试卷 public function teachingTestPaper(){ $data = $this->request->params([ ["exam_papers_id",0] ]); $ExamPapers = new ExamPapers(); $ExamQuestions = new ExamQuestions(); $exam_papers_id = $data['exam_papers_id']; $res = $ExamPapers->where('id',$exam_papers_id)->find(); $textArr = $this->safeExplode($res['questions_ids']); $res['count'] = count($textArr); $arrayText = []; foreach ($textArr as $v){ $resText = $ExamQuestions->where('id', $v)->find(); array_push($arrayText,$resText); } $res['resText'] = $arrayText; return success('SUCCESS', $res); } //处理字符串 public function safeExplode($value, $delimiter = ',') { if (is_array($value)) { return $value; } if (is_string($value) && trim($value) !== '') { return explode($delimiter, $value); } return []; } //提交试卷 public function submitTestPaper(){ $data = $this->request->params([ ["optionList",0], ["testPaperId",0], ["id",0], ]); $ExamPapers = new ExamPapers(); $ExamQuestions = new ExamQuestions(); $optionList = $data['optionList']; $testPaperId = $data['testPaperId']; $res = $ExamPapers->where('id',$testPaperId)->find(); $textArr = $this->safeExplode($res['questions_ids']); $optionArr = json_decode($optionList, true); $textArr = array_filter($textArr); $optionArr = array_filter($optionArr); if (count($textArr) !== count($optionArr)) { return fail('请填写全部问题', []); } $result = array_map(function($id, $value) { return ['ids' => (int)$id, 'value' => $value]; }, $textArr, $optionArr); $where = [ 'id'=>$this->member_id, ]; $userRes = (new PersonnelService())->info($where); $LessonCourseTeaching = new LessonCourseTeaching(); $resLessonTeaching = $LessonCourseTeaching->where('id',$data['id'])->find(); if ($resLessonTeaching['answers_num'] >= $res['number_answers']) { return fail('已超过答题次数', []); } else { if (count($userRes['data']['cameus_dept_arr']) > 0) { $campus_id = $userRes['data']['cameus_dept_arr'][0]['campus_id']; } else { $campus_id = 0; } foreach ($result as &$v){ $v['user_id'] = $userRes['data']['id']; $v['question_id'] = $v['ids']; $v['campus_id'] = $campus_id; $v['answer'] = $v['value']; $resEq = $ExamQuestions->where('id',$v['ids'])->find(); if ($resEq['correct_answer'] == $v['value']){ $v['is_correct'] = 1; } else { $v['is_correct'] = 0; } $ExamAnswers = new ExamAnswers(); $ress = $ExamAnswers->create($v); } $LessonCourseTeaching->where('id',$data['id'])->update(['answers_num'=>$resLessonTeaching['answers_num'] + 1]); $correct = array_filter($result, function($item) { return $item['is_correct'] == 1; }); $incorrect = array_filter($result, function($item) { return $item['is_correct'] == 0; }); return success('SUCCESS', ['success'=>count($correct),'error'=>count($incorrect),'num'=>(count($correct) * $res['every_score'])]); } } }