智慧教务系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

147 lines
5.4 KiB

<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
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;
use app\service\api\captcha\CaptchaService;
use app\service\api\login\ConfigService;
use app\service\api\login\LoginService;
use core\base\BaseApiService;
use Exception;
use think\Response;
/**
* 公共控制器相关接口
* Class Personnel
* @package app\api\controller\apiController
*/
class TeachingResearch extends BaseApiService
{
//教研管理列表
public function list(){
$id = $this->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'])]);
}
}
}