作者 何书鹏
1 个管道 的构建 通过 耗费 1 秒

合并分支 'heshupeng' 到 'master'

模拟试题优化



查看合并请求 !304
... ... @@ -85,7 +85,7 @@ class Simulation extends Api
empty($simulation_id) && $this->error('缺少必要参数');
$info = $this->model->get($simulation_id);
empty($info) && $this->error('试卷信息不存在');
$info['full_score'] = Question::where('target_id',$simulation_id)->sum('score');
$info['full_score'] = $info['question_num'] * $info['question_score'];
$info = $info->visible(['id','title','year','time','pass_score','satisfaction','description','do_num'])->append(['full_score']);
$this->success('成功',$info);
}
... ... @@ -163,7 +163,7 @@ class Simulation extends Api
->where('user_id',$user_id)
->delete();
// 把题目ID存到缓存
cache('simulation_'.$user_id, array_column($list, 'id'));
cache('simulation_'.$user_id.'_'.$simulation_id, array_column($list, 'id'));
$this->success('成功',compact('time','total','list'));
}
... ... @@ -202,7 +202,7 @@ class Simulation extends Api
$where = [
'q.target_id' => $simulation_id,
'q.target_type' => '2',
'q.id' => cache('simulation_'.$user_id) ? ['in',cache('simulation_'.$user_id)] : 0
'q.id' => cache('simulation_'.$user_id.'_'.$simulation_id) ? ['in',cache('simulation_'.$user_id.'_'.$simulation_id)] : 0
];
$list = Question::alias('q')
->join('mobile_question_answer qa','q.id = qa.question_id and user_id='.$user_id,'left')
... ... @@ -247,10 +247,14 @@ class Simulation extends Api
empty($simulation_id) && $this->error('缺少必要参数');
$info = $this->model->get($simulation_id);
empty($info) && $this->error('试卷信息不存在');
$where = [
'q.target_id' => $simulation_id,
'q.target_type' => '2',
'q.id' => cache('simulation_'.$user_id.'_'.$simulation_id) ? ['in',cache('simulation_'.$user_id.'_'.$simulation_id)] : 0
];
$list = Question::alias('q')
->join('mobile_question_answer qa','q.id = qa.question_id and user_id='.$user_id,'left')
->where('q.target_id',$simulation_id)
->where('q.target_type','2')
->where($where)
->field('q.id,q.title,q.option,q.type,q.answer,q.score,qa.get_score,qa.is_wrong')
->select();
// 考试得分
... ... @@ -258,8 +262,7 @@ class Simulation extends Api
// 正确率
$right_count = Question::alias('q')
->join('mobile_question_answer qa','q.id = qa.question_id and user_id='.$user_id,'left')
->where('q.target_id',$simulation_id)
->where('q.target_type','2')
->where($where)
->where('qa.is_wrong','0')
->count('q.id');
$right_rate = !empty($right_count) ? bcdiv($right_count,count($list),4) * 100 : 0;
... ... @@ -267,7 +270,7 @@ class Simulation extends Api
$result = SimulationResult::create([
'user_id' => $user_id,
'simulation_id' => $simulation_id,
'full_score' => array_sum(array_column($list, 'score')),
'full_score' => $info['question_num'] * $info['question_score'],
'get_score' => $myscore,
'right_rate' => $right_rate
]);
... ... @@ -338,10 +341,14 @@ class Simulation extends Api
empty($simulation_result_id) && $this->error('缺少必要参数');
$info = SimulationResult::get($simulation_result_id);
empty($info) && $this->error('考试结果信息不存在');
$where = [
'q.target_id' => $info['simulation_id'],
'q.target_type' => '2',
'q.id' => cache('simulation_'.$user_id.'_'.$info['simulation_id']) ? ['in',cache('simulation_'.$user_id.'_'.$info['simulation_id'])] : 0
];
$list = Question::alias('q')
->join('mobile_question_answer qa','q.id = qa.question_id and user_id='.$user_id,'left')
->where('q.target_id',$info['simulation_id'])
->where('q.target_type','2')
->where($where)
->field('
q.id,
q.title,
... ... @@ -400,14 +407,19 @@ class Simulation extends Api
*/
public function analysisList()
{
$user_id = $this->auth->id;
$simulation_id = $this->request->param('simulation_id');
empty($simulation_id) && $this->error('缺少必要参数');
$where = [
'q.target_id' => $simulation_id,
'q.target_type' => '2',
'q.id' => cache('simulation_'.$user_id.'_'.$simulation_id) ? ['in',cache('simulation_'.$user_id.'_'.$simulation_id)] : 0
];
$list = Question::alias('q')
->join('mobile_question_note qn','q.id = qn.question_id and qn.user_id='.$this->auth->id,'left')
->join('mobile_question_collect qc','q.id = qc.question_id and qc.user_id='.$this->auth->id,'left')
->join('mobile_question_answer qa','q.id = qa.question_id and qa.user_id='.$this->auth->id,'left')
->where('q.target_type',2)
->where('q.target_id',$simulation_id)
->where($where)
->field('
q.id,
q.title,
... ...