Browse Source

接口

master
李双庆 10 months ago
parent
commit
abe3eb091b
  1. 90
      niucloud/app/api/controller/apiController/TeachingResearch.php
  2. 4
      niucloud/app/api/route/route.php

90
niucloud/app/api/controller/apiController/TeachingResearch.php

@ -12,6 +12,10 @@
namespace app\api\controller\apiController;
use app\dict\member\MemberLoginTypeDict;
use app\model\exam_papers\ExamPapers;
use app\model\exam_questions\ExamQuestions;
use app\model\lesson_course_teaching\LessonCourseTeaching;
use app\model\exam_answers\ExamAnswers;
use app\Request;
use app\service\api\apiService\PersonnelService;
use app\service\api\apiService\TeachingResearchService;
@ -49,4 +53,90 @@ class TeachingResearch extends BaseApiService
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 {
foreach ($result as &$v){
$v['user_id'] = $userRes['data']['id'];
$v['question_id'] = $v['ids'];
$v['campus_id'] = 0;
$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'])]);
}
}
}

4
niucloud/app/api/route/route.php

@ -271,6 +271,10 @@ Route::group(function () {
Route::get('teachingResearch/info/:id', 'apiController.teachingResearch/info');
//获取能看的教研管理类型
Route::get('teachingResearch/lookType', 'apiController.teachingResearch/lookType');
//获取试卷
Route::get('teachingResearch/teachingTestPaper', 'apiController.teachingResearch/teachingTestPaper');
//提交试卷
Route::get('teachingResearch/submitTestPaper', 'apiController.teachingResearch/submitTestPaper');
})->middleware(ApiChannel::class)
->middleware(ApiPersonnelCheckToken::class, true)
->middleware(ApiLog::class);

Loading…
Cancel
Save