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

合并分支 'heshupeng' 到 'master'

模拟试题优化



查看合并请求 !304
@@ -85,7 +85,7 @@ class Simulation extends Api @@ -85,7 +85,7 @@ class Simulation extends Api
85 empty($simulation_id) && $this->error('缺少必要参数'); 85 empty($simulation_id) && $this->error('缺少必要参数');
86 $info = $this->model->get($simulation_id); 86 $info = $this->model->get($simulation_id);
87 empty($info) && $this->error('试卷信息不存在'); 87 empty($info) && $this->error('试卷信息不存在');
88 - $info['full_score'] = Question::where('target_id',$simulation_id)->sum('score'); 88 + $info['full_score'] = $info['question_num'] * $info['question_score'];
89 $info = $info->visible(['id','title','year','time','pass_score','satisfaction','description','do_num'])->append(['full_score']); 89 $info = $info->visible(['id','title','year','time','pass_score','satisfaction','description','do_num'])->append(['full_score']);
90 $this->success('成功',$info); 90 $this->success('成功',$info);
91 } 91 }
@@ -163,7 +163,7 @@ class Simulation extends Api @@ -163,7 +163,7 @@ class Simulation extends Api
163 ->where('user_id',$user_id) 163 ->where('user_id',$user_id)
164 ->delete(); 164 ->delete();
165 // 把题目ID存到缓存 165 // 把题目ID存到缓存
166 - cache('simulation_'.$user_id, array_column($list, 'id')); 166 + cache('simulation_'.$user_id.'_'.$simulation_id, array_column($list, 'id'));
167 $this->success('成功',compact('time','total','list')); 167 $this->success('成功',compact('time','total','list'));
168 } 168 }
169 169
@@ -202,7 +202,7 @@ class Simulation extends Api @@ -202,7 +202,7 @@ class Simulation extends Api
202 $where = [ 202 $where = [
203 'q.target_id' => $simulation_id, 203 'q.target_id' => $simulation_id,
204 'q.target_type' => '2', 204 'q.target_type' => '2',
205 - 'q.id' => cache('simulation_'.$user_id) ? ['in',cache('simulation_'.$user_id)] : 0 205 + 'q.id' => cache('simulation_'.$user_id.'_'.$simulation_id) ? ['in',cache('simulation_'.$user_id.'_'.$simulation_id)] : 0
206 ]; 206 ];
207 $list = Question::alias('q') 207 $list = Question::alias('q')
208 ->join('mobile_question_answer qa','q.id = qa.question_id and user_id='.$user_id,'left') 208 ->join('mobile_question_answer qa','q.id = qa.question_id and user_id='.$user_id,'left')
@@ -247,10 +247,14 @@ class Simulation extends Api @@ -247,10 +247,14 @@ class Simulation extends Api
247 empty($simulation_id) && $this->error('缺少必要参数'); 247 empty($simulation_id) && $this->error('缺少必要参数');
248 $info = $this->model->get($simulation_id); 248 $info = $this->model->get($simulation_id);
249 empty($info) && $this->error('试卷信息不存在'); 249 empty($info) && $this->error('试卷信息不存在');
  250 + $where = [
  251 + 'q.target_id' => $simulation_id,
  252 + 'q.target_type' => '2',
  253 + 'q.id' => cache('simulation_'.$user_id.'_'.$simulation_id) ? ['in',cache('simulation_'.$user_id.'_'.$simulation_id)] : 0
  254 + ];
250 $list = Question::alias('q') 255 $list = Question::alias('q')
251 ->join('mobile_question_answer qa','q.id = qa.question_id and user_id='.$user_id,'left') 256 ->join('mobile_question_answer qa','q.id = qa.question_id and user_id='.$user_id,'left')
252 - ->where('q.target_id',$simulation_id)  
253 - ->where('q.target_type','2') 257 + ->where($where)
254 ->field('q.id,q.title,q.option,q.type,q.answer,q.score,qa.get_score,qa.is_wrong') 258 ->field('q.id,q.title,q.option,q.type,q.answer,q.score,qa.get_score,qa.is_wrong')
255 ->select(); 259 ->select();
256 // 考试得分 260 // 考试得分
@@ -258,8 +262,7 @@ class Simulation extends Api @@ -258,8 +262,7 @@ class Simulation extends Api
258 // 正确率 262 // 正确率
259 $right_count = Question::alias('q') 263 $right_count = Question::alias('q')
260 ->join('mobile_question_answer qa','q.id = qa.question_id and user_id='.$user_id,'left') 264 ->join('mobile_question_answer qa','q.id = qa.question_id and user_id='.$user_id,'left')
261 - ->where('q.target_id',$simulation_id)  
262 - ->where('q.target_type','2') 265 + ->where($where)
263 ->where('qa.is_wrong','0') 266 ->where('qa.is_wrong','0')
264 ->count('q.id'); 267 ->count('q.id');
265 $right_rate = !empty($right_count) ? bcdiv($right_count,count($list),4) * 100 : 0; 268 $right_rate = !empty($right_count) ? bcdiv($right_count,count($list),4) * 100 : 0;
@@ -267,7 +270,7 @@ class Simulation extends Api @@ -267,7 +270,7 @@ class Simulation extends Api
267 $result = SimulationResult::create([ 270 $result = SimulationResult::create([
268 'user_id' => $user_id, 271 'user_id' => $user_id,
269 'simulation_id' => $simulation_id, 272 'simulation_id' => $simulation_id,
270 - 'full_score' => array_sum(array_column($list, 'score')), 273 + 'full_score' => $info['question_num'] * $info['question_score'],
271 'get_score' => $myscore, 274 'get_score' => $myscore,
272 'right_rate' => $right_rate 275 'right_rate' => $right_rate
273 ]); 276 ]);
@@ -338,10 +341,14 @@ class Simulation extends Api @@ -338,10 +341,14 @@ class Simulation extends Api
338 empty($simulation_result_id) && $this->error('缺少必要参数'); 341 empty($simulation_result_id) && $this->error('缺少必要参数');
339 $info = SimulationResult::get($simulation_result_id); 342 $info = SimulationResult::get($simulation_result_id);
340 empty($info) && $this->error('考试结果信息不存在'); 343 empty($info) && $this->error('考试结果信息不存在');
  344 + $where = [
  345 + 'q.target_id' => $info['simulation_id'],
  346 + 'q.target_type' => '2',
  347 + 'q.id' => cache('simulation_'.$user_id.'_'.$info['simulation_id']) ? ['in',cache('simulation_'.$user_id.'_'.$info['simulation_id'])] : 0
  348 + ];
341 $list = Question::alias('q') 349 $list = Question::alias('q')
342 ->join('mobile_question_answer qa','q.id = qa.question_id and user_id='.$user_id,'left') 350 ->join('mobile_question_answer qa','q.id = qa.question_id and user_id='.$user_id,'left')
343 - ->where('q.target_id',$info['simulation_id'])  
344 - ->where('q.target_type','2') 351 + ->where($where)
345 ->field(' 352 ->field('
346 q.id, 353 q.id,
347 q.title, 354 q.title,
@@ -400,14 +407,19 @@ class Simulation extends Api @@ -400,14 +407,19 @@ class Simulation extends Api
400 */ 407 */
401 public function analysisList() 408 public function analysisList()
402 { 409 {
  410 + $user_id = $this->auth->id;
403 $simulation_id = $this->request->param('simulation_id'); 411 $simulation_id = $this->request->param('simulation_id');
404 empty($simulation_id) && $this->error('缺少必要参数'); 412 empty($simulation_id) && $this->error('缺少必要参数');
  413 + $where = [
  414 + 'q.target_id' => $simulation_id,
  415 + 'q.target_type' => '2',
  416 + 'q.id' => cache('simulation_'.$user_id.'_'.$simulation_id) ? ['in',cache('simulation_'.$user_id.'_'.$simulation_id)] : 0
  417 + ];
405 $list = Question::alias('q') 418 $list = Question::alias('q')
406 ->join('mobile_question_note qn','q.id = qn.question_id and qn.user_id='.$this->auth->id,'left') 419 ->join('mobile_question_note qn','q.id = qn.question_id and qn.user_id='.$this->auth->id,'left')
407 ->join('mobile_question_collect qc','q.id = qc.question_id and qc.user_id='.$this->auth->id,'left') 420 ->join('mobile_question_collect qc','q.id = qc.question_id and qc.user_id='.$this->auth->id,'left')
408 ->join('mobile_question_answer qa','q.id = qa.question_id and qa.user_id='.$this->auth->id,'left') 421 ->join('mobile_question_answer qa','q.id = qa.question_id and qa.user_id='.$this->auth->id,'left')
409 - ->where('q.target_type',2)  
410 - ->where('q.target_id',$simulation_id) 422 + ->where($where)
411 ->field(' 423 ->field('
412 q.id, 424 q.id,
413 q.title, 425 q.title,