|
@@ -6,6 +6,7 @@ use app\admin\model\Fault;
|
|
use app\common\controller\Backend;
|
|
use app\common\controller\Backend;
|
|
use app\common\model\Config as ConfigModel;
|
|
use app\common\model\Config as ConfigModel;
|
|
use think\Db;
|
|
use think\Db;
|
|
|
|
+use think\Env;
|
|
use think\exception\PDOException;
|
|
use think\exception\PDOException;
|
|
use think\exception\ValidateException;
|
|
use think\exception\ValidateException;
|
|
use app\admin\model\teacher\Exams;
|
|
use app\admin\model\teacher\Exams;
|
|
@@ -22,6 +23,7 @@ class Practice extends Backend
|
|
* @var \app\admin\model\teacher\Collection
|
|
* @var \app\admin\model\teacher\Collection
|
|
*/
|
|
*/
|
|
protected $model = null;
|
|
protected $model = null;
|
|
|
|
+ protected $exam_model = null;
|
|
|
|
|
|
protected $whereExtend = null;
|
|
protected $whereExtend = null;
|
|
|
|
|
|
@@ -29,6 +31,7 @@ class Practice extends Backend
|
|
{
|
|
{
|
|
parent::_initialize();
|
|
parent::_initialize();
|
|
$this->model = new \app\admin\model\teacher\Collection;
|
|
$this->model = new \app\admin\model\teacher\Collection;
|
|
|
|
+ $this->exam_model = new \app\admin\model\teacher\Exams;
|
|
$this->assignConfig('sim_sim_type', ConfigModel::getSimTypeList());
|
|
$this->assignConfig('sim_sim_type', ConfigModel::getSimTypeList());
|
|
$this->assignConfig('sim_question_setting_method', ConfigModel::getSimQuestionList());
|
|
$this->assignConfig('sim_question_setting_method', ConfigModel::getSimQuestionList());
|
|
|
|
|
|
@@ -61,7 +64,7 @@ class Practice extends Backend
|
|
if($params['question_setting_method']==2 && empty($params['question_ids'])){
|
|
if($params['question_setting_method']==2 && empty($params['question_ids'])){
|
|
$this->error('出题方式为考题自选,请选择考题');
|
|
$this->error('出题方式为考题自选,请选择考题');
|
|
}
|
|
}
|
|
- if($params['question_setting_method']==3 && empty($params['question_ids'])){
|
|
|
|
|
|
+ if($params['question_setting_method']==3 && empty($params['task_id'])){
|
|
$this->error('出题方式为任务自选,请选择任务');
|
|
$this->error('出题方式为任务自选,请选择任务');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -75,6 +78,10 @@ class Practice extends Backend
|
|
Db::startTrans();
|
|
Db::startTrans();
|
|
try {
|
|
try {
|
|
$depart_ids = $params['depart_ids'];
|
|
$depart_ids = $params['depart_ids'];
|
|
|
|
+ if($params['question_setting_method']==3 && !empty($params['fault_name'])){
|
|
|
|
+ $params['question_name'] = $params['fault_name'];
|
|
|
|
+ unset($params['fault_name']);
|
|
|
|
+ }
|
|
$result = $this->model->allowField(true)->save($params);
|
|
$result = $this->model->allowField(true)->save($params);
|
|
foreach(explode(',',$depart_ids) as $item){
|
|
foreach(explode(',',$depart_ids) as $item){
|
|
if(!empty($item)){
|
|
if(!empty($item)){
|
|
@@ -99,33 +106,38 @@ class Practice extends Backend
|
|
'user_nickname' => $it['nickname'],
|
|
'user_nickname' => $it['nickname'],
|
|
'user_id' => $it['id'],
|
|
'user_id' => $it['id'],
|
|
'user_depart_id' => $it['depart_id'],
|
|
'user_depart_id' => $it['depart_id'],
|
|
- 'seat_id'=>01,
|
|
|
|
- 'sim_id'=>intval($params['sim_type']),
|
|
|
|
'create_time'=>date('Y-m-d H:i:s'),
|
|
'create_time'=>date('Y-m-d H:i:s'),
|
|
'update_time' => date('Y-m-d H:i:s'),
|
|
'update_time' => date('Y-m-d H:i:s'),
|
|
];
|
|
];
|
|
$examid = Db::name('real_exam')->insertGetId($arr1);
|
|
$examid = Db::name('real_exam')->insertGetId($arr1);
|
|
//匹配的学员自动加入 mx_real_exam_fault 考试故障关联表
|
|
//匹配的学员自动加入 mx_real_exam_fault 考试故障关联表
|
|
|
|
+ $fault_list = Fault::where(['sim_type' => $params['sim_type'], 'fault_state' => 0,'fault_type'=>3])->select();
|
|
if($params['question_setting_method']==1){ //系统随机
|
|
if($params['question_setting_method']==1){ //系统随机
|
|
- $fault_list = Fault::where(['sim_type' => $params['sim_type'], 'fault_state' => 0,'fault_type'=>3])->select();
|
|
|
|
|
|
+ $fault_key = array_rand($fault_list, 3);
|
|
}else if($params['question_setting_method']==2){//教师自选
|
|
}else if($params['question_setting_method']==2){//教师自选
|
|
- $fault_list = Fault::where(['sim_type' => $params['sim_type'],'fault_id'=>['in',$params['question_ids']], 'fault_state' => 0,'fault_type'=>3])->select();
|
|
|
|
|
|
+ $question_ids = $params['question_ids'];
|
|
}else if($params['question_setting_method']==3){ //任务自选
|
|
}else if($params['question_setting_method']==3){ //任务自选
|
|
- $fault_list = Db::name('task_fault')->where(['task_id'=>['in',$params['question_ids']]])->select();
|
|
|
|
|
|
+ $task_ids = Db::name('task_fault')->where(['task_id'=>['in',$params['task_id']]])->column('fault_id');
|
|
}
|
|
}
|
|
- $fault_key = array_rand($fault_list, 3);
|
|
|
|
|
|
+// halt($question_ids);
|
|
foreach ($fault_list as $key=> $item1){
|
|
foreach ($fault_list as $key=> $item1){
|
|
$flag = 0;
|
|
$flag = 0;
|
|
- if(in_array($key,$fault_key)){
|
|
|
|
|
|
+ if(!empty($fault_key) && in_array($key,$fault_key)){
|
|
|
|
+ $flag = 1;
|
|
|
|
+ }
|
|
|
|
+ if(!empty($question_ids) && in_array($item1['fault_id'],explode(',',$question_ids))){
|
|
|
|
+ $flag = 1;
|
|
|
|
+ }
|
|
|
|
+ if(!empty($task_ids) && in_array($item1['fault_id'],$task_ids)){
|
|
$flag = 1;
|
|
$flag = 1;
|
|
}
|
|
}
|
|
$add= [
|
|
$add= [
|
|
'exam_id'=>$examid,
|
|
'exam_id'=>$examid,
|
|
- 'fault_id'=>$item1->fault_id,
|
|
|
|
|
|
+ 'fault_id'=>$item1['fault_id'],
|
|
'ref_type'=>2,
|
|
'ref_type'=>2,
|
|
'flag'=>$flag,
|
|
'flag'=>$flag,
|
|
'ref_state'=>3,
|
|
'ref_state'=>3,
|
|
- 'sim_fault_question_value'=>'0000000'.rand(1,2),
|
|
|
|
|
|
+// 'sim_fault_question_value'=>'0000000'.rand(1,2),
|
|
'createtime'=>time(),
|
|
'createtime'=>time(),
|
|
'updatetime'=>time(),
|
|
'updatetime'=>time(),
|
|
'create_time'=>date('Y-m-d H:i:s'),
|
|
'create_time'=>date('Y-m-d H:i:s'),
|
|
@@ -166,7 +178,7 @@ class Practice extends Backend
|
|
if($params['question_setting_method']==2 && empty($params['question_ids'])){
|
|
if($params['question_setting_method']==2 && empty($params['question_ids'])){
|
|
$this->error('出题方式为考题自选,请选择考题');
|
|
$this->error('出题方式为考题自选,请选择考题');
|
|
}
|
|
}
|
|
- if($params['question_setting_method']==3 && empty($params['question_ids'])){
|
|
|
|
|
|
+ if($params['question_setting_method']==3 && empty($params['task_id'])){
|
|
$this->error('出题方式为任务自选,请选择任务');
|
|
$this->error('出题方式为任务自选,请选择任务');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -175,7 +187,12 @@ class Practice extends Backend
|
|
Db::startTrans();
|
|
Db::startTrans();
|
|
try {
|
|
try {
|
|
$depart_ids = $params['depart_ids'];
|
|
$depart_ids = $params['depart_ids'];
|
|
|
|
+ if($params['question_setting_method']==3 && !empty($params['fault_name'])){
|
|
|
|
+ $params['question_name'] = $params['fault_name'];
|
|
|
|
+ unset($params['fault_name']);
|
|
|
|
+ }
|
|
$result = $row->allowField(true)->save($params);
|
|
$result = $row->allowField(true)->save($params);
|
|
|
|
+
|
|
Db::name('real_exam_collection_dept')->where(['exam_collection_id'=>$row->exam_collection_id])->delete();
|
|
Db::name('real_exam_collection_dept')->where(['exam_collection_id'=>$row->exam_collection_id])->delete();
|
|
foreach(explode(',',$depart_ids) as $item){
|
|
foreach(explode(',',$depart_ids) as $item){
|
|
if(!empty($item)){
|
|
if(!empty($item)){
|
|
@@ -187,57 +204,65 @@ class Practice extends Backend
|
|
Db::name('real_exam_collection_dept')->insert($arr);
|
|
Db::name('real_exam_collection_dept')->insert($arr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- Db::name('real_exam')->where(['exam_collection_id'=>$row->exam_collection_id])->delete();
|
|
|
|
|
|
+
|
|
|
|
+ Db::name('real_exam')->where(['exam_collection_id'=>$row->exam_collection_id,'starttime'=>0])->delete();
|
|
//匹配的学员自动加入 mx_real_exam 考试表 总分
|
|
//匹配的学员自动加入 mx_real_exam 考试表 总分
|
|
$admin_list = Db::name('admin')->where('depart_id','in',$depart_ids)->select();
|
|
$admin_list = Db::name('admin')->where('depart_id','in',$depart_ids)->select();
|
|
foreach ($admin_list as $it){
|
|
foreach ($admin_list as $it){
|
|
- $arr1 = [
|
|
|
|
- 'exam_collection_id' => $row->exam_collection_id,
|
|
|
|
- 'exam_collection_name' => $params['exam_collection_name'],
|
|
|
|
- 'exam_collection_type' => $row['exam_collection_type'],
|
|
|
|
- 'sim_type' => $params['sim_type'],
|
|
|
|
- 'user_username' => $it['username'],
|
|
|
|
- 'user_nickname' => $it['nickname'],
|
|
|
|
- 'user_id' => $it['id'],
|
|
|
|
- 'user_depart_id' => $it['depart_id'],
|
|
|
|
- 'seat_id'=>01,
|
|
|
|
- 'sim_id'=>intval($params['sim_type']),
|
|
|
|
- 'create_time'=>date('Y-m-d H:i:s'),
|
|
|
|
- 'update_time' => date('Y-m-d H:i:s'),
|
|
|
|
- ];
|
|
|
|
- $examid = Db::name('real_exam')->insertGetId($arr1);
|
|
|
|
- //匹配的学员自动加入 mx_real_exam_fault 考试故障关联表
|
|
|
|
- if($params['question_setting_method']==1){ //系统随机
|
|
|
|
- $fault_list = Fault::where(['sim_type' => $params['sim_type'], 'fault_state' => 0,'fault_type'=>3])->select();
|
|
|
|
- }else if($params['question_setting_method']==2){//教师自选
|
|
|
|
- $fault_list = Fault::where(['sim_type' => $params['sim_type'],'fault_id'=>['in',$params['question_ids']], 'fault_state' => 0,'fault_type'=>3])->select();
|
|
|
|
- }else if($params['question_setting_method']==3){ //任务自选
|
|
|
|
- $fault_list = Db::name('task_fault')->where(['task_id'=>['in',$params['question_ids']]])->select();
|
|
|
|
- }
|
|
|
|
- Db::name('real_exam_fault')->where(['exam_id'=>$examid])->delete();
|
|
|
|
- $fault_key = array_rand($fault_list, 3);
|
|
|
|
- foreach ($fault_list as $key=> $item1){
|
|
|
|
- $flag = 0;
|
|
|
|
- if(in_array($key,$fault_key)){
|
|
|
|
- $flag = 1;
|
|
|
|
- }
|
|
|
|
- $add= [
|
|
|
|
- 'exam_id'=>$examid,
|
|
|
|
- 'fault_id'=>$item1['fault_id'],
|
|
|
|
- 'ref_type'=>2,
|
|
|
|
- 'flag'=>$flag,
|
|
|
|
- 'ref_state'=>3,
|
|
|
|
- 'sim_fault_question_value'=>'0000000'.rand(1,2),
|
|
|
|
- 'createtime'=>time(),
|
|
|
|
- 'updatetime'=>time(),
|
|
|
|
|
|
+ $real_exam = Db::name('real_exam')->where(['exam_collection_id'=>$row->exam_collection_id,'user_id'=>$it['id']])->find();
|
|
|
|
+ if(empty($real_exam)){
|
|
|
|
+ $arr1 = [
|
|
|
|
+ 'exam_collection_id' => $row->exam_collection_id,
|
|
|
|
+ 'exam_collection_name' => $params['exam_collection_name'],
|
|
|
|
+ 'exam_collection_type' => $row['exam_collection_type'],
|
|
|
|
+ 'sim_type' => $params['sim_type'],
|
|
|
|
+ 'user_username' => $it['username'],
|
|
|
|
+ 'user_nickname' => $it['nickname'],
|
|
|
|
+ 'user_id' => $it['id'],
|
|
|
|
+ 'user_depart_id' => $it['depart_id'],
|
|
'create_time'=>date('Y-m-d H:i:s'),
|
|
'create_time'=>date('Y-m-d H:i:s'),
|
|
- 'update_time'=>date('Y-m-d H:i:s'),
|
|
|
|
|
|
+ 'update_time' => date('Y-m-d H:i:s'),
|
|
];
|
|
];
|
|
- Db::name('real_exam_fault')->insert($add);
|
|
|
|
|
|
+ $examid = Db::name('real_exam')->insertGetId($arr1);
|
|
|
|
+ //匹配的学员自动加入 mx_real_exam_fault 考试故障关联表
|
|
|
|
+ $fault_list = Fault::where(['sim_type' => $params['sim_type'], 'fault_state' => 0,'fault_type'=>3])->select();
|
|
|
|
+ if($params['question_setting_method']==1){ //系统随机
|
|
|
|
+ $fault_key = array_rand($fault_list, 3);
|
|
|
|
+ }else if($params['question_setting_method']==2){//教师自选
|
|
|
|
+ $question_ids = $params['question_ids'];
|
|
|
|
+ }else if($params['question_setting_method']==3){ //任务自选
|
|
|
|
+ $task_ids = Db::name('task_fault')->where(['task_id'=>['in',$params['task_id']]])->column('fault_id');
|
|
|
|
+ }
|
|
|
|
+ Db::name('real_exam_fault')->where(['exam_id'=>$examid])->delete();
|
|
|
|
+
|
|
|
|
+ foreach ($fault_list as $key=> $item1){
|
|
|
|
+ $flag = 0;
|
|
|
|
+ if(!empty($fault_key) && in_array($key,$fault_key)){
|
|
|
|
+ $flag = 1;
|
|
|
|
+ }
|
|
|
|
+ if(!empty($question_ids) && in_array($item1['fault_id'],explode(',',$question_ids))){
|
|
|
|
+ $flag = 1;
|
|
|
|
+ }
|
|
|
|
+ if(!empty($task_ids) && in_array($item1['fault_id'],$task_ids)){
|
|
|
|
+ $flag = 1;
|
|
|
|
+ }
|
|
|
|
+ $add= [
|
|
|
|
+ 'exam_id'=>$examid,
|
|
|
|
+ 'fault_id'=>$item1['fault_id'],
|
|
|
|
+ 'ref_type'=>2,
|
|
|
|
+ 'flag'=>$flag,
|
|
|
|
+ 'ref_state'=>3,
|
|
|
|
+// 'sim_fault_question_value'=>'0000000'.rand(1,2),
|
|
|
|
+ 'createtime'=>time(),
|
|
|
|
+ 'updatetime'=>time(),
|
|
|
|
+ 'create_time'=>date('Y-m-d H:i:s'),
|
|
|
|
+ 'update_time'=>date('Y-m-d H:i:s'),
|
|
|
|
+ ];
|
|
|
|
+ Db::name('real_exam_fault')->insert($add);
|
|
|
|
+ }
|
|
|
|
+ unset($item1);
|
|
}
|
|
}
|
|
- unset($item1);
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
Db::commit();
|
|
Db::commit();
|
|
} catch (ValidateException|PDOException|Exception $e) {
|
|
} catch (ValidateException|PDOException|Exception $e) {
|
|
Db::rollback();
|
|
Db::rollback();
|
|
@@ -250,6 +275,61 @@ class Practice extends Backend
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ public function del($ids = null)
|
|
|
|
+ {
|
|
|
|
+ if (false === $this->request->isPost()) {
|
|
|
|
+ $this->error(__("Invalid parameters"));
|
|
|
|
+ }
|
|
|
|
+ $ids = $ids ?: $this->request->post("ids");
|
|
|
|
+ if (empty($ids)) {
|
|
|
|
+ $this->error(__('Parameter %s can not be empty', 'ids'));
|
|
|
|
+ }
|
|
|
|
+ $pk = $this->model->getPk();
|
|
|
|
+ $adminIds = $this->getDataLimitAdminIds();
|
|
|
|
+ if (is_array($adminIds)) {
|
|
|
|
+ $this->model->where($this->dataLimitField, 'in', $adminIds);
|
|
|
|
+ }
|
|
|
|
+ $list = $this->model->where($pk, 'in', $ids)->select();
|
|
|
|
+
|
|
|
|
+ $count = 0;
|
|
|
|
+ Db::startTrans();
|
|
|
|
+ try {
|
|
|
|
+ //删除考试集合 mx_real_exam_collection
|
|
|
|
+ foreach ($list as $item) {
|
|
|
|
+ if($item['yikao_count']>0){
|
|
|
|
+ $this->error('已有学生参加考试,无法删除');
|
|
|
|
+ }
|
|
|
|
+ $count += $item->delete();
|
|
|
|
+ }
|
|
|
|
+ //删除学员考试 mx_real_exam
|
|
|
|
+ $exam_list = $this->exam_model->where('exam_collection_id',$ids)->select();
|
|
|
|
+ if(!empty($exam_list)){
|
|
|
|
+ foreach ($exam_list as $k=>$it)
|
|
|
|
+ {
|
|
|
|
+ //删除学员考试故障表 mx_real_exam_fault
|
|
|
|
+ Db::name('real_exam_fault')->where('exam_id',$it['exam_id'])->delete();
|
|
|
|
+ $it->delete();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ //删除考试关联区队表 mx_real_exam_collection_dept
|
|
|
|
+ Db::name('real_exam_collection_dept')->where('exam_collection_id',$ids)->delete();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ Db::commit();
|
|
|
|
+ } catch (PDOException|Exception $e) {
|
|
|
|
+ Db::rollback();
|
|
|
|
+ $this->error($e->getMessage());
|
|
|
|
+ }
|
|
|
|
+ if ($count) {
|
|
|
|
+ $this->success();
|
|
|
|
+ }
|
|
|
|
+ $this->error(__('No rows were deleted'));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
public function multi($ids = null)
|
|
public function multi($ids = null)
|
|
{
|
|
{
|
|
if (false === $this->request->isPost()) {
|
|
if (false === $this->request->isPost()) {
|
|
@@ -273,15 +353,41 @@ class Practice extends Backend
|
|
if (is_array($adminIds)) {
|
|
if (is_array($adminIds)) {
|
|
$this->model->where($this->dataLimitField, 'in', $adminIds);
|
|
$this->model->where($this->dataLimitField, 'in', $adminIds);
|
|
}
|
|
}
|
|
-// if(!empty($values['exam_collection_state'])){
|
|
|
|
-// if($values['exam_collection_state']==2){
|
|
|
|
-// $state_count = $this->model->where(['exam_collection_state'=>$values['exam_collection_state'],'exam_collection_type'=>1])->count();
|
|
|
|
-// if($state_count>0){
|
|
|
|
-// $this->error('已有启用的考试,请先关闭原来的考试');
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
$count = 0;
|
|
$count = 0;
|
|
|
|
+ if(!empty($values['exam_collection_state'])){
|
|
|
|
+ //开始考试集合
|
|
|
|
+ if($values['exam_collection_state']==2){
|
|
|
|
+ //触发Java端后台的接口数据,
|
|
|
|
+ //dev-api/sim/real-exam-collection/teacher/exam/open/{examcollectionId} $ids put
|
|
|
|
+ if(Env::get('app.is_fault')){
|
|
|
|
+ $url = config('site.url_type').'/sim/real-exam-collection/teacher/exam/open/'.$ids;
|
|
|
|
+ $ret = json_decode(send_post($url),true);
|
|
|
|
+ if($ret['code']!=200){
|
|
|
|
+ $this->error($ret['msg']);
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+// $state_count = $this->model->where(['exam_collection_state'=>$values['exam_collection_state'],'exam_collection_type'=>1])->count();
|
|
|
|
+// if($state_count>0){
|
|
|
|
+// $this->error('已有启用的考试,请先关闭原来的考试');
|
|
|
|
+// }
|
|
|
|
+ }
|
|
|
|
+ $count = 1;
|
|
|
|
+ }
|
|
|
|
+ //关闭
|
|
|
|
+ if($values['exam_collection_state']==3){
|
|
|
|
+ //触发Java端后台的接口数据,
|
|
|
|
+ //dev-api/sim/real-exam-collection/teacher/exam/open/{examcollectionId} $ids put
|
|
|
|
+ if(Env::get('app.is_fault')){
|
|
|
|
+ $url = config('site.url_type').'/sim/real-exam-collection/teacher/exam/close/'.$ids;
|
|
|
|
+ $ret = json_decode(send_post($url),true);
|
|
|
|
+ if($ret['code']!=200){
|
|
|
|
+ $this->error($ret['msg']);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ $count = 1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
Db::startTrans();
|
|
Db::startTrans();
|
|
try {
|
|
try {
|
|
$list = $this->model->where($this->model->getPk(), 'in', $ids)->select();
|
|
$list = $this->model->where($this->model->getPk(), 'in', $ids)->select();
|