ソースを参照

20250104 教师端 调整

贾小兵 3 ヶ月 前
コミット
2e1eb40bcc

+ 6 - 0
application/admin/controller/student/Collection.php

@@ -268,6 +268,12 @@ class Collection extends Backend
             $this->success('交卷成功,待老师确认成绩','/ZQOtIMLKud.php/student/exam/index');
         }
 
+        if(empty($row->starttime)){
+            $row->start_time = date('Y-m-d H:i:s');
+            $row->starttime = time();
+            $row->exam_status = 4;
+            $row->save();
+        }
 
         //还未开始考试
         $row->limit_duration = $this->model->where(['exam_collection_id'=>$row['exam_collection_id']])->value('limit_duration');

+ 125 - 7
application/admin/controller/teacher/Collection.php

@@ -24,12 +24,15 @@ class Collection extends Backend
      * @var \app\admin\model\teacher\Collection
      */
     protected $model = null;
+
+    protected $exam_model = null;
     protected $whereExtend = null;
 
     public function _initialize()
     {
         parent::_initialize();
         $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->assign('sim_sim_type', ConfigModel::getSimTypeList());
         $this->assignConfig('sim_question_setting_method', ConfigModel::getSimQuestionList());
@@ -83,8 +86,54 @@ class Collection extends Backend
             }
 
             //匹配的学员自动加入  mx_real_exam 考试表  总分
+            $admin_list = Db::name('admin')->where('depart_id','in',$depart_ids)->select();
+            foreach ($admin_list as $it){
+                $arr1 = [
+                    'exam_collection_id' => $this->model->exam_collection_id,
+                    'exam_collection_name' => $params['exam_collection_name'],
+                    'exam_collection_type' => $params['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();
+                }
+                $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(),
+                        '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);
 
-            //匹配的学员自动加入  mx_real_exam_fault 考试故障关联表
+            }
 
             Db::commit();
         } catch (ValidateException|PDOException|Exception $e) {
@@ -104,6 +153,10 @@ class Collection extends Backend
             $this->error(__('No Results were found'));
         }
         if (false === $this->request->isPost()) {
+            $examing_count = $this->exam_model->where(['exam_collection_id'=>$ids,'exam_status'=>4])->count();
+            if($examing_count>0){
+                $this->error('有学员考试中,无法修改');
+            }
             $this->view->assign('row', $row);
             $this->assignConfig('row_info', $row);
             return $this->view->fetch();
@@ -124,13 +177,72 @@ class Collection extends Backend
         $result = false;
         Db::startTrans();
         try {
-            //是否采用模型验证
-            if ($this->modelValidate) {
-                $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
-                $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
-                $row->validateFailException()->validate($validate);
-            }
+            $depart_ids = $params['depart_ids'];
             $result = $row->allowField(true)->save($params);
+
+
+            Db::name('real_exam_collection_dept')->where(['exam_collection_id'=>$row->exam_collection_id])->delete();
+            foreach(explode(',',$depart_ids) as $item){
+                if(!empty($item)){
+                    $arr = [
+                        'exam_collection_id' => $row->exam_collection_id,
+                        'dept_id' => $item,
+                        'update_time' => date('Y-m-d H:i:s'),
+                    ];
+                    Db::name('real_exam_collection_dept')->insert($arr);
+                }
+            }
+
+            Db::name('real_exam')->where(['exam_collection_id'=>$row->exam_collection_id])->delete();
+            //匹配的学员自动加入  mx_real_exam 考试表  总分
+            $admin_list = Db::name('admin')->where('depart_id','in',$depart_ids)->select();
+            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(),
+                        '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);
+            }
             Db::commit();
         } catch (ValidateException|PDOException|Exception $e) {
             Db::rollback();
@@ -254,6 +366,12 @@ class Collection extends Backend
     老师开启考试
      */
     public function start($ids = null){
+//        $row = $this->model->get($ids);
+//        if (!$row) {
+//            $this->error(__('No Results were found'));
+//        }
+//        $params['starttime'] = time();
+//        $result = $row->allowField(true)->save($params);
         $this->success('开始成功');
     }
 }

+ 1 - 0
application/admin/controller/teacher/Exams.php

@@ -26,6 +26,7 @@ class Exams extends Backend
         parent::_initialize();
         $this->model = new \app\admin\model\teacher\Exams;
         $this->whereExtend['exam_collection_type'] = 3;
+        $this->whereExtend['starttime'] = ['>',0];
     }
 
 

+ 124 - 12
application/admin/controller/teacher/Practice.php

@@ -2,6 +2,7 @@
 
 namespace app\admin\controller\teacher;
 
+use app\admin\model\Fault;
 use app\common\controller\Backend;
 use app\common\model\Config as ConfigModel;
 use think\Db;
@@ -74,12 +75,6 @@ class Practice extends Backend
         Db::startTrans();
         try {
             $depart_ids = $params['depart_ids'];
-            //是否采用模型验证
-            if ($this->modelValidate) {
-                $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
-                $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
-                $this->model->validateFailException()->validate($validate);
-            }
             $result = $this->model->allowField(true)->save($params);
             foreach(explode(',',$depart_ids) as $item){
                 if(!empty($item)){
@@ -91,6 +86,56 @@ class Practice extends Backend
                     Db::name('real_exam_collection_dept')->insert($arr);
                 }
             }
+
+            //匹配的学员自动加入  mx_real_exam 考试表  总分
+            $admin_list = Db::name('admin')->where('depart_id','in',$depart_ids)->select();
+            foreach ($admin_list as $it){
+                $arr1 = [
+                    'exam_collection_id' => $this->model->exam_collection_id,
+                    'exam_collection_name' => $params['exam_collection_name'],
+                    'exam_collection_type' => $params['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();
+                }
+                $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(),
+                        '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);
+
+            }
             Db::commit();
         } catch (ValidateException|PDOException|Exception $e) {
             Db::rollback();
@@ -129,13 +174,70 @@ class Practice extends Backend
         $result = false;
         Db::startTrans();
         try {
-            //是否采用模型验证
-            if ($this->modelValidate) {
-                $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
-                $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
-                $row->validateFailException()->validate($validate);
-            }
+            $depart_ids = $params['depart_ids'];
             $result = $row->allowField(true)->save($params);
+            Db::name('real_exam_collection_dept')->where(['exam_collection_id'=>$row->exam_collection_id])->delete();
+            foreach(explode(',',$depart_ids) as $item){
+                if(!empty($item)){
+                    $arr = [
+                        'exam_collection_id' => $row->exam_collection_id,
+                        'dept_id' => $item,
+                        'update_time' => date('Y-m-d H:i:s'),
+                    ];
+                    Db::name('real_exam_collection_dept')->insert($arr);
+                }
+            }
+            Db::name('real_exam')->where(['exam_collection_id'=>$row->exam_collection_id])->delete();
+            //匹配的学员自动加入  mx_real_exam 考试表  总分
+            $admin_list = Db::name('admin')->where('depart_id','in',$depart_ids)->select();
+            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(),
+                        '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);
+            }
+
             Db::commit();
         } catch (ValidateException|PDOException|Exception $e) {
             Db::rollback();
@@ -242,4 +344,14 @@ class Practice extends Backend
         $result = ['total' => $list->total(), 'rows' => $list->items()];
         return json($result);
     }
+
+    public function start($ids = null){
+//        $row = $this->model->get($ids);
+//        if (!$row) {
+//            $this->error(__('No Results were found'));
+//        }
+//        $params['starttime'] = time();
+//        $result = $row->allowField(true)->save($params);
+        $this->success('开始成功');
+    }
 }

+ 1 - 1
application/admin/controller/teacher/Task.php

@@ -103,7 +103,7 @@ class Task extends Backend
         ];
         $selectData = Fault::where($where)->select();
         foreach ($selectData as $key => $value){
-            $children = Fault::where(['parent_fault_id'=>$value['fault_id'],'fault_state'=>0])->select();
+            $children = Fault::where(['parent_fault_id'=>$value['fault_id'],'fault_type' => 3,'fault_state'=>0])->select();
             $selectData[$key]['children'] = $children;
         }
         unset($value);

+ 1 - 1
application/admin/lang/zh-cn/teacher/practice.php

@@ -8,7 +8,7 @@ return [
     'Exam_collection_state'   => '状态',//:[0]-初始化,[2]-打开,[3]-关闭
     'Exam_collection_name'    => '练习名称',
     'Task_id'                 => '任务ID',
-    'Limit_duration'          => '练习时长(分钟)',
+    'Limit_duration'          => '练习时长',
     'Start_time'              => '练习开始时间',
     'End_time'                => '练习结束时间',
     'Create_user_id'          => '创建教师ID/用户ID',

+ 6 - 5
application/admin/view/teacher/practice/index.html

@@ -8,13 +8,14 @@
                     <div id="toolbar" class="toolbar">
                         <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
                         <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('teacher/collection/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
-                        <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('teacher/collection/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
-                        <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('teacher/collection/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
-                        
+                        <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('teacher/practice/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
+<!--                        <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('teacher/practice/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>-->
+
+
+                        <a href="javascript:;" class="btn btn-warning btn-start btn-disabled disabled {:$auth->check('teacher/practice/start')?'':'hide'}" title="{:__('开始练习')}" ><i class="fa fa-play-circle"></i> {:__('开始练习')}</a>
+
 
-                        
 
-                        
                     </div>
                     <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
                            data-operate-edit="{:$auth->check('teacher/collection/edit')}"

+ 25 - 0
public/assets/js/backend/teacher/practice.js

@@ -70,6 +70,20 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                     extend: 'data-area=\'["85%","85%"]\'',
                                     url: 'teacher/practice/edit',
                                 },
+                                {
+                                    name: 'dispatch',
+                                    text: '',
+                                    icon: 'fa fa-hand-pointer-o',
+                                    title: '进入考试',
+                                    visible: function (rr) {
+                                        if(rr.exam_collection_state == 2){
+                                            return true;
+                                        }
+                                        return false;
+                                    },
+                                    classname: 'btn btn-info btn-xs btn-magic btn-addtabs',
+                                    url: 'tteacher/practice/persent',
+                                },
                                 // {
                                 //     name: 'dispatch',
                                 //     text: '',
@@ -94,6 +108,17 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
 
             // 为表格绑定事件
             Table.api.bindevent(table);
+
+            $(document).on('click', '.btn-start', function () {
+                var ids = Table.api.selectedids(table);
+                Fast.api.ajax({
+                    url: "teacher/practice/start/ids/"+ids,
+                    type: "post",
+                }, function () {
+                    table.bootstrapTable('refresh');
+                    Layer.close(index);
+                });
+            });
         },
         persent: function () {
             Table.api.init({