|
@@ -61,58 +61,74 @@ class Exercise extends Backend
|
|
|
$count = 0;
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
- $params['exam_collection_type'] = 2;
|
|
|
- $params['exam_collection_state'] = 2;
|
|
|
- $params['question_setting_method'] = 1;
|
|
|
- $params['exam_collection_name'] = $this->auth->nickname.'练习';
|
|
|
- $params['limit_duration'] = 30;
|
|
|
- $params['start_time'] = date('Y-m-d');
|
|
|
- $params['end_time'] = date('Y-m-d');
|
|
|
-
|
|
|
- $exam_id = $this->model->insertGetId($params);
|
|
|
-
|
|
|
-// $sim = Db::name('sim')->where('sim_type',$params['sim_type'])->where('seat_id',$this->auth->seat_id)->find();
|
|
|
-// if(empty($sim)){
|
|
|
-// $this->error('未找到模拟器,不可练习');
|
|
|
-// }
|
|
|
-
|
|
|
- $data = [
|
|
|
- 'exam_collection_id' => $exam_id,
|
|
|
- 'user_id' => $this->auth->id,
|
|
|
- 'user_username' => $this->auth->username,
|
|
|
- 'user_nickname' => $this->auth->nickname,
|
|
|
- 'user_depart_id' => $this->auth->depart_id,
|
|
|
- 'exam_collection_name' => $params['exam_collection_name'],
|
|
|
- 'exam_collection_type' =>$params['exam_collection_type'],
|
|
|
- 'sim_type' => $params['sim_type'],
|
|
|
- 'seat_id' =>0,
|
|
|
- 'sim_id' =>0,
|
|
|
- 'exam_status'=>4,
|
|
|
- 'start_time'=>date('Y-m-d H:i:s'),
|
|
|
- 'starttime'=>time(),
|
|
|
- 'create_time'=>date('Y-m-d H:i:s'),
|
|
|
- 'createtime'=>time(),
|
|
|
- 'update_time'=>date('Y-m-d H:i:s'),
|
|
|
- 'updatetime'=>time(),
|
|
|
- ];
|
|
|
- $examid = $this->exam_model->insertGetId($data);
|
|
|
+ $exam_info = $this->exam_model->where(['user_id'=>$this->auth->id,'exam_status'=>1])->find();
|
|
|
+ //考试集合id $exam_id
|
|
|
+ //学员考试id $examid
|
|
|
+ if(!empty($exam_info)){
|
|
|
+ $exam_id = $exam_info['exam_collection_id'];
|
|
|
+ $examid = $exam_info['exam_id'];
|
|
|
+ }else{
|
|
|
+ $params['exam_collection_type'] = 2;
|
|
|
+ $params['exam_collection_state'] = 2;
|
|
|
+ $params['question_setting_method'] = 1;
|
|
|
+ $params['exam_collection_name'] = $this->auth->nickname.'练习';
|
|
|
+ $params['limit_duration'] = 30;
|
|
|
+ $params['start_time'] = date('Y-m-d');
|
|
|
+ $params['end_time'] = date('Y-m-d');
|
|
|
+ $exam_id = $this->model->insertGetId($params);
|
|
|
+
|
|
|
+ $data = [
|
|
|
+ 'exam_collection_id' => $exam_id,
|
|
|
+ 'user_id' => $this->auth->id,
|
|
|
+ 'user_username' => $this->auth->username,
|
|
|
+ 'user_nickname' => $this->auth->nickname,
|
|
|
+ 'user_depart_id' => $this->auth->depart_id,
|
|
|
+ 'exam_collection_name' => $params['exam_collection_name'],
|
|
|
+ 'exam_collection_type' =>$params['exam_collection_type'],
|
|
|
+ 'sim_type' => $params['sim_type'],
|
|
|
+ 'seat_id' =>0,
|
|
|
+ 'sim_id' =>0,
|
|
|
+ 'exam_status'=>1,
|
|
|
+// 'start_time'=>date('Y-m-d H:i:s'),
|
|
|
+// 'starttime'=>time(),
|
|
|
+ 'create_time'=>date('Y-m-d H:i:s'),
|
|
|
+ 'createtime'=>time(),
|
|
|
+ 'update_time'=>date('Y-m-d H:i:s'),
|
|
|
+ 'updatetime'=>time(),
|
|
|
+ ];
|
|
|
+ $examid = $this->exam_model->insertGetId($data);
|
|
|
+ }
|
|
|
|
|
|
+ //先删除故障信息表中的数据
|
|
|
+ Db::name('real_exam_fault')->where('exam_id',$examid)->delete();
|
|
|
|
|
|
//匹配的学员自动加入 mx_real_exam_fault 考试故障关联表
|
|
|
+ //获取随机题目
|
|
|
+ if($params['sim_type']=='0001'){
|
|
|
+ $fault_key1 = rand(0,1);
|
|
|
+ $fault_key2 = rand(2,3);
|
|
|
+ $fault_key3 = rand(4,5);
|
|
|
+ $fault_key4 = rand(6,7);
|
|
|
+ $fault_key5 = rand(8,9);
|
|
|
+ }else if($params['sim_type']=='0002'){
|
|
|
+ $fault_key1 = 1;
|
|
|
+ $fault_key2 = 3;
|
|
|
+ $fault_key3 = 5;
|
|
|
+ $fault_key4 = rand(6,7);
|
|
|
+ $fault_key5 = rand(9,10);
|
|
|
+ }else if($params['sim_type']=='0003'){
|
|
|
+ $fault_key1 = rand(0,1);
|
|
|
+ $fault_key2 = rand(2,3);
|
|
|
+ $fault_key3 = rand(8,10);
|
|
|
+ $fault_key4 = rand(11,12);
|
|
|
+ $fault_key5 = rand(13,14);
|
|
|
+ }
|
|
|
+ $fault_key_arr = [$fault_key1,$fault_key2,$fault_key3,$fault_key4,$fault_key5];
|
|
|
+ $keys = array_rand($fault_key_arr, 3); // 随机取出3个元素
|
|
|
+ $fault_key = array_intersect_key($fault_key_arr, array_flip($keys));
|
|
|
+
|
|
|
$fault_list = Fault::where(['sim_type' => $params['sim_type'], 'fault_state' => 0,'fault_type'=>3])->select();
|
|
|
foreach ($fault_list as $key=> $item1){
|
|
|
- $fault_key = [1,5,10];
|
|
|
- if($params['sim_type']=='0002'){
|
|
|
- $fault_key1 = 1;
|
|
|
- $fault_key2 = 5;
|
|
|
- $fault_key3 = rand(10,11);
|
|
|
- }else{
|
|
|
- $fault_key1 = rand(0, 1);
|
|
|
- $fault_key2 = rand(2, 3);
|
|
|
- $fault_key3 = 9;
|
|
|
- }
|
|
|
- $fault_key = [$fault_key1,$fault_key2,$fault_key3];
|
|
|
-
|
|
|
$flag = 0;
|
|
|
if(!empty($fault_key) && in_array($key,$fault_key)){
|
|
|
$flag = 1;
|
|
@@ -130,10 +146,8 @@ class Exercise extends Backend
|
|
|
];
|
|
|
Db::name('real_exam_fault')->insert($add);
|
|
|
}
|
|
|
-
|
|
|
$count = $examid;
|
|
|
|
|
|
-
|
|
|
Db::commit();
|
|
|
} catch (PDOException|Exception $e) {
|
|
|
Db::rollback();
|
|
@@ -147,6 +161,22 @@ class Exercise extends Backend
|
|
|
if($ret['code']!=200){
|
|
|
$this->error($ret['msg']);
|
|
|
}
|
|
|
+ //接口返回正常,更新当前字段为开始考试
|
|
|
+ if($ret['code']==200){
|
|
|
+ $update = [
|
|
|
+ 'exam_status'=>4,
|
|
|
+ 'start_time'=>date('Y-m-d H:i:s'),
|
|
|
+ 'starttime'=>time(),
|
|
|
+ ];
|
|
|
+ $this->exam_model->where(['exam_id'=>$examid])->update($update);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $update = [
|
|
|
+ 'exam_status'=>4,
|
|
|
+ 'start_time'=>date('Y-m-d H:i:s'),
|
|
|
+ 'starttime'=>time(),
|
|
|
+ ];
|
|
|
+ $this->exam_model->where(['exam_id'=>$examid])->update($update);
|
|
|
}
|
|
|
$this->success('开始成功','/admin/student/exercise/examing/ids/'.$count);
|
|
|
}
|