贾小兵 3 mesi fa
parent
commit
546fdca50f

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

@@ -114,7 +114,7 @@ class Exams extends Backend
             return $this->selectpage();
         }
         [$where, $sort, $order, $offset, $limit] = $this->buildparams();
-        $list = Db::name('real_exam_comp_request')
+        $list = Db::name('real_exam_comp_request')->where('exam_collection_type',3)
             ->where($where)
             ->order($sort, $order)
             ->paginate($limit);

+ 198 - 2
application/admin/controller/teacher/Practice.php

@@ -4,7 +4,10 @@ namespace app\admin\controller\teacher;
 
 use app\common\controller\Backend;
 use app\common\model\Config as ConfigModel;
-
+use think\Db;
+use think\exception\PDOException;
+use think\exception\ValidateException;
+use app\admin\model\teacher\Exams;
 /**
  * sim-练习集合管理
  *
@@ -41,9 +44,202 @@ class Practice extends Backend
      * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
      * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
      */
+    public function add()
+    {
+        if (false === $this->request->isPost()) {
+            return $this->view->fetch();
+        }
+        $params = $this->request->post('row/a');
+        if (empty($params)) {
+            $this->error(__('Parameter %s can not be empty', ''));
+        }
+        if(empty($params['depart_ids'])){
+            $this->error('请选择区队名称');
+        }
+        if(!empty($params['question_setting_method'])){
+            if($params['question_setting_method']==2 && empty($params['question_ids'])){
+                $this->error('出题方式为考题自选,请选择考题');
+            }
+            if($params['question_setting_method']==3 && empty($params['question_ids'])){
+                $this->error('出题方式为任务自选,请选择任务');
+            }
+        }
+
+        $params = $this->preExcludeFields($params);
+
+        if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
+            $params[$this->dataLimitField] = $this->auth->id;
+        }
+        $result = false;
+        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)){
+                    $arr = [
+                        'exam_collection_id' => $this->model->exam_collection_id,
+                        'dept_id' => $item,
+                        'update_time' => date('Y-m-d H:i:s'),
+                    ];
+                    Db::name('real_exam_collection_dept')->insert($arr);
+                }
+            }
+            Db::commit();
+        } catch (ValidateException|PDOException|Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+        if ($result === false) {
+            $this->error(__('No rows were inserted'));
+        }
+        $this->success();
+    }
+
+    public function edit($ids = null)
+    {
+        $row = $this->model->get($ids);
+        if (!$row) {
+            $this->error(__('No Results were found'));
+        }
+        if (false === $this->request->isPost()) {
+            $this->view->assign('row', $row);
+            $this->assignConfig('row_info', $row);
+            return $this->view->fetch();
+        }
+        $params = $this->request->post('row/a');
+        if (empty($params)) {
+            $this->error(__('Parameter %s can not be empty', ''));
+        }
+        if(!empty($params['question_setting_method'])){
+            if($params['question_setting_method']==2 && empty($params['question_ids'])){
+                $this->error('出题方式为考题自选,请选择考题');
+            }
+            if($params['question_setting_method']==3 && empty($params['question_ids'])){
+                $this->error('出题方式为任务自选,请选择任务');
+            }
+        }
+        $params = $this->preExcludeFields($params);
+        $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);
+            }
+            $result = $row->allowField(true)->save($params);
+            Db::commit();
+        } catch (ValidateException|PDOException|Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+        if (false === $result) {
+            $this->error(__('No rows were updated'));
+        }
+        $this->success();
+    }
 
+
+    public function multi($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'));
+        }
+
+        if (false === $this->request->has('params')) {
+            $this->error(__('No rows were updated'));
+        }
+        parse_str($this->request->post('params'), $values);
+        $values = true ? $values : array_intersect_key($values, array_flip(is_array($this->multiFields) ? $this->multiFields : explode(',', $this->multiFields)));
+//        $values = $this->auth->isSuperAdmin() ? $values : array_intersect_key($values, array_flip(is_array($this->multiFields) ? $this->multiFields : explode(',', $this->multiFields)));
+        if (empty($values)) {
+            $this->error(__('You have no permission'));
+        }
+        $adminIds = $this->getDataLimitAdminIds();
+        if (is_array($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;
+        Db::startTrans();
+        try {
+            $list = $this->model->where($this->model->getPk(), 'in', $ids)->select();
+            foreach ($list as $item) {
+                $count += $item->allowField(true)->isUpdate(true)->save($values);
+            }
+            Db::commit();
+        } catch (PDOException|Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+        if ($count) {
+            $this->success();
+        }
+        $this->error(__('No rows were updated'));
+    }
     public function persent()
     {
-        return $this->view->fetch();
+        //设置过滤方法
+        $this->request->filter(['strip_tags', 'trim']);
+        if (false === $this->request->isAjax()) {
+
+            $examlist = Exams::select();
+            foreach ($examlist as $k => $v){
+                $examlist[$k]['score'] = Db::name('real_exam_score')->where('exam_id',$v['exam_id'])->find();
+            }
+            $this->view->assign('examlist', $examlist);
+            return $this->view->fetch();
+        }
+        //如果发送的来源是 Selectpage,则转发到 Selectpage
+        if ($this->request->request('keyField')) {
+            return $this->selectpage();
+        }
+        [$where, $sort, $order, $offset, $limit] = $this->buildparams();
+        $list = Db::name('real_exam_comp_request')
+            ->where($where)->where('exam_collection_type',1)
+            ->order($sort, $order)
+            ->paginate($limit);
+        unset($v);
+        $result = ['total' => $list->total(), 'rows' => $list->items()];
+        return json($result);
+    }
+
+    public function examing()
+    {
+        //设置过滤方法
+        $this->request->filter(['strip_tags', 'trim']);
+        if (false === $this->request->isAjax()) {
+            return $this->view->fetch();
+        }
+        //如果发送的来源是 Selectpage,则转发到 Selectpage
+        if ($this->request->request('keyField')) {
+            return $this->selectpage();
+        }
+        [$where, $sort, $order, $offset, $limit] = $this->buildparams();
+        $list = $this->model
+            ->where($where)->where($this->whereExtend)
+            ->order($sort, $order)
+            ->paginate($limit);
+        $result = ['total' => $list->total(), 'rows' => $list->items()];
+        return json($result);
     }
 }

+ 3 - 0
application/admin/view/teacher/collection/add.html

@@ -6,6 +6,9 @@
         <input class="form-control" name="row[create_by]" type="hidden" value="{$auth->nickname}">
         <input class="form-control depart_ids" name="row[depart_ids]" type="hidden" value="">
         <input class="form-control question_ids" name="row[question_ids]" type="hidden" value="0">
+
+        <input class="form-control depart_ids" name="row[depart_ids]" type="text" value="0">
+
         <div class="form-group col-sm-6">
             <label class="control-label col-xs-12 col-sm-3 addRedStar">{:__('Exam_collection_name')}:</label>
             <div class="col-xs-12 col-sm-7">

+ 4 - 2
application/admin/view/teacher/practice/add.html

@@ -1,10 +1,11 @@
 <form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
     <div class="row">
         <input class="form-control" name="row[exam_collection_state]" type="hidden" value="3">
-        <input class="form-control" name="row[exam_collection_type]" type="hidden" value="3">
+        <input class="form-control" name="row[exam_collection_type]" type="hidden" value="1">
         <input class="form-control" name="row[create_user_id]" type="hidden" value="{$auth->id}">
         <input class="form-control" name="row[create_by]" type="hidden" value="{$auth->nickname}">
-        <input class="form-control depart_ids" name="row[depart_ids]" type="text" value="0">
+        <input class="form-control depart_ids" name="row[depart_ids]" type="text" value="">
+        <input class="form-control question_ids" name="row[question_ids]" type="text" value="0">
         <div class="form-group col-sm-6">
             <label class="control-label col-xs-12 col-sm-3 addRedStar">{:__('Exam_collection_name')}:</label>
             <div class="col-xs-12 col-sm-7">
@@ -56,6 +57,7 @@
                 </select>
             </div>
             <button class="btn btn-info btn-sm" style="display: none">自选考题编辑</button>
+            <button class="btn btn-info btn-task" style="display: none">自选任务编辑</button>
         </div>
     </div>
     <div class="panel panel-default panel-intro">

+ 4 - 1
application/admin/view/teacher/practice/edit.html

@@ -1,5 +1,7 @@
 <form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
     <div class="row">
+        <input class="form-control question_ids" name="row[question_ids]" type="text" value="{$row.question_ids|htmlentities}">
+        <input class="form-control depart_ids" name="row[depart_ids]" type="text" value="{$row.depart_ids|htmlentities}">
         <div class="form-group col-sm-6">
             <label class="control-label col-xs-12 col-sm-3 addRedStar">{:__('Exam_collection_name')}:</label>
             <div class="col-xs-12 col-sm-7">
@@ -50,7 +52,8 @@
                     {/foreach}
                 </select>
             </div>
-            <button class="btn btn-info btn-sm" style="display: none">自选考题编辑</button>
+            <div class="btn btn-info btn-sm" {if $row.question_setting_method neq 2}style="display: none"{/if}>自选考题编辑</div>
+        <div class="btn btn-info btn-task" {if $row.question_setting_method neq 3}style="display: none"{/if}>自选任务编辑</div>
         </div>
     </div>
     <div class="panel panel-default panel-intro">

+ 0 - 3
public/assets/js/backend/teacher/collection.js

@@ -95,9 +95,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
             // 为表格绑定事件
             Table.api.bindevent(table);
         },
-
-
-
         task: function () {
             // 初始化表格参数配置
             Table.api.init({

+ 170 - 63
public/assets/js/backend/teacher/practice.js

@@ -32,6 +32,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                     [
                         {checkbox: true},
                         {field: 'exam_collection_id', title: __('编号')},
+                        {field: 'exam_collection_name', title: __('Exam_collection_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                         {field: 'sim_type', title: __('Sim_type'),searchList:{"0001":"FZD04B型侦毒器","0002":"FZB006型毒剂报警器","0003":"防化兵用毒剂报警器"},formatter: Table.api.formatter.simtype},
                         {field: 'question_setting_method', title: __('Question_setting_method'),searchList:{"1":"系统随机","2":"教师自选","3":"任务自选"},formatter: Table.api.formatter.simmethod},
                         {field: 'exam_collection_type', title: __('Exam_collection_type'),operate: false,formatter: function (value, row, index) {
@@ -45,7 +46,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                             table: table,
                             formatter: Table.api.formatter.collectonstate
                         },
-                        {field: 'exam_collection_name', title: __('Exam_collection_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
+
                         // {field: 'task_id', title: __('Task_id')},
                         {field: 'limit_duration', title: __('Limit_duration')},
                         {field: 'start_time', title: __('Start_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
@@ -68,22 +69,23 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                     classname: 'btn btn-success btn-xs btn-magic btn-dialog',
                                     extend: 'data-area=\'["85%","85%"]\'',
                                     url: 'teacher/practice/edit',
-                                },{
-                                    name: 'dispatch',
-                                    text: '',
-                                    icon: 'fa fa-trash',
-                                    title: '删除',
-                                    classname: 'btn btn-danger btn-xs btn-magic btn-ajax',
-                                    url: 'teacher/practice/del',
-                                    confirm: '确定要删除吗?',
-                                    success: function (data, ret) {
-                                        $(".btn-refresh").trigger("click");
-                                    },
-                                    error: function (data, ret) {
-                                        Layer.alert(ret.msg);
-                                        return false;
-                                    }
-                                }
+                                },
+                                // {
+                                //     name: 'dispatch',
+                                //     text: '',
+                                //     icon: 'fa fa-trash',
+                                //     title: '删除',
+                                //     classname: 'btn btn-danger btn-xs btn-magic btn-ajax',
+                                //     url: 'teacher/practice/del',
+                                //     confirm: '确定要删除吗?',
+                                //     success: function (data, ret) {
+                                //         $(".btn-refresh").trigger("click");
+                                //     },
+                                //     error: function (data, ret) {
+                                //         Layer.alert(ret.msg);
+                                //         return false;
+                                //     }
+                                // }
                             ],
                         }
                     ]
@@ -97,7 +99,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
             Table.api.init({
                 extend: {
                     index_url: 'teacher/practice/persent' + location.search,
-                    indexed_url: 'teacher/practice/index' + location.search,
+                    indexed_url: 'teacher/practice/examing' + location.search,
                     table: 'teacher_exams',
                 }
             });
@@ -112,27 +114,63 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                 fixedColumns: true,
                 fixedRightNumber: 1,
                 searchFormVisible:false,
+                showExport:false,
+                search:false,
                 columns: [
                     [
                         // {checkbox: true},
-                        {field: '', title: __('更换件')},
-                        {field: '', title: __('学员姓名')},
-                        {field: '', title: __('状态')},
-                        {field: 'endtime', title: __('申请时间'), formatter: Table.api.formatter.datetime, operate: false, addclass: 'datetimerange', sortable: true},
+                        {field: 'fault_name', title: __('更换件')},
+                        {field: 'create_by', title: __('学员姓名')},
+                        {field: 'request_status', title: __('状态'),
+                            formatter: function(value, row,index) {
+                                if(value==1){
+                                    return '<span class="text-warning">待处理</span>';
+                                }else if(value==2){
+                                    return '<span class="text-success">已送</span>';
+                                }else if(value==3){
+                                    return '<span class="text-danger">已驳回</span>';
+                                }
+                            }
+                        },
+                        {field: 'createtime', title: __('申请时间'), formatter: Table.api.formatter.datetime, operate: false, addclass: 'datetimerange', sortable: true},
                         {field: 'operate', title: __('Operate'), table: table,
                             events: Table.api.events.operate,
                             // formatter: Table.api.formatter.operate
                             formatter: Table.api.formatter.buttons,
                             buttons: [
-                                // {
-                                //     name: 'dispatch',
-                                //     text: '',
-                                //     icon: 'fa fa-pencil',
-                                //     title: '编辑',
-                                //     classname: 'btn btn-success btn-xs btn-magic btn-dialog',
-                                //     extend: 'data-area=\'["55%","95%"]\'',
-                                //     url: 'teacher/exams/edit',
-                                // }
+                                {
+                                    name: 'dispatch',
+                                    text: '',
+                                    icon: 'fa fa-check',
+                                    title: '已送',
+                                    classname: 'btn btn-success btn-xs btn-magic btn-ajax',
+                                    url: 'teacher/exams/handle/type/1',
+                                    visible: function (rr) {
+                                        if(rr.request_status == 1 || rr.request_status == 0){
+                                            return true;
+                                        }
+                                        return  false;
+                                    },
+                                    success: function (data, ret) {
+                                        table.bootstrapTable("refresh");
+                                    },
+                                },{
+                                    name: 'dispatch',
+                                    text: '',
+                                    icon: 'fa fa-reply-all',
+                                    title: '驳回',
+                                    classname: 'btn btn-danger btn-xs btn-magic btn-ajax',
+                                    url: 'teacher/exams/handle/type/2',
+                                    visible: function (rr) {
+                                        if(rr.request_status == 1 || rr.request_status == 0){
+                                            return true;
+                                        }
+                                        return  false;
+                                    },
+                                    success: function (data, ret) {
+                                        table.bootstrapTable("refresh");
+                                    },
+                                }
                             ],
                         }
                     ]
@@ -157,31 +195,20 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                 columns: [
                     [
                         // {checkbox: true},
-                        {field: '', title: __('座号')},
-                        {field: '', title: __('模拟器状态')},
-                        {field: '', title: __('学员学号')},
-                        {field: '', title: __('学员姓名')},
-                        {field: '', title: __('考试状态')},
-                        {field: '', title: __('考试成绩')},
-                        {field: '', title: __('故障现象')},
-                        {field: '', title: __('故障部位')},
-                        {field: '', title: __('排除方法')},
-                        {field: 'operate', title: __('Operate'), table: table1,
-                            events: Table.api.events.operate,
-                            // formatter: Table.api.formatter.operate
-                            formatter: Table.api.formatter.buttons,
-                            buttons: [
-                                // {
-                                //     name: 'dispatch',
-                                //     text: '',
-                                //     icon: 'fa fa-pencil',
-                                //     title: '编辑',
-                                //     classname: 'btn btn-success btn-xs btn-magic btn-dialog',
-                                //     extend: 'data-area=\'["55%","95%"]\'',
-                                //     url: 'teacher/exams/edit',
-                                // }
-                            ],
-                        }
+                        {field: 'seat_id', title: __('座号')},
+                        {field: '', title: __('模拟器状态'),
+                            formatter: function(value, row,index) {
+                                return '<span class="text-success">就绪</span>';
+                            }
+                        },
+                        {field: 'user_username', title: __('学员学号')},
+                        {field: 'user_nickname', title: __('学员姓名')},
+                        {field: '', title: __('状态'),
+                            formatter: function(value, row,index) {
+                                return '<span class="text-success">已交卷</span>';
+                            }
+                        },
+                        {field: 'total_score', title: __('模拟成绩')},
                     ]
                 ]
             });
@@ -197,7 +224,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
         },
         api: {
             bindevent: function () {
-
+                var rel_Ids = [];
                 Table.api.init({
                     extend: {
                         index_url: 'department/admin/departadmintotal' + location.search,
@@ -215,7 +242,16 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                     Search:false,
                     columns: [
                         [
-                            {checkbox: true},
+                            {checkbox: true,
+                                formatter: function(value,row,index){
+                                    // console.log(row.id+'####'+Config.row_info.depart_ids)
+                                    if(Config.row_info != undefined && Config.row_info.depart_ids.indexOf(row.id)>-1){
+                                        rel_Ids.push(row.id);
+                                        return true;
+                                    }
+                                    return false;
+                                }
+                            },
                             {field: 'department_name', title: __('区队名称'), operate: false,width: '400px', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                             {field: 'department_admin_count', title: __('全部人员数量'),operate: false},
                         ]
@@ -225,14 +261,85 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                 // 为表格绑定事件
                 Table.api.bindevent(table);
 
-
-                $("input[name='btSelectAll']").click(function () {
-                    var ids = Table.api.selectedids(table);
-                    console.log(ids);
-                    $(".depart_ids").val(ids);
+                table.on('click-row.bs.table', function (e, row, element) {
+                    console.log(rel_Ids)
+                    // console.log('row')
+                    if(!$.inArray(row.id,rel_Ids)){
+                        arr = $.grep(rel_Ids, function(value) {
+                            return value != row["id"];
+                        });
+                        rel_Ids = arr;
+                    }else if(rel_Ids.indexOf(row.id)>-1){
+                        var index = rel_Ids.indexOf(row.id);
+                        if (index > -1) {
+                            rel_Ids.splice(index, 1);
+                        }
+                    }else{
+                        rel_Ids.push(row.id);
+                    }
+                    $(".depart_ids").val(rel_Ids.join());
                 });
 
+                $(document).on('change', '#c-question_setting_method', function () {
+                    if($(this).val()==1){
+                        $(".btn-sm,.btn-task").css('display','none');
+                    }else if($(this).val()==2){
+                        $(".btn-sm").css('display','block');
+                        $(".btn-task").css('display','none');
+                    }else if($(this).val()==3){
+                        $(".btn-sm").css('display','none');
+                        $(".btn-task").css('display','block');
+                    }
+                    $(".question_ids").val(0);
+                });
+                //考题
+                $(document).on('click', '.btn-sm', function () {
+                    var simtype = $("#c-sim_type").val();
+                    if(!simtype){
+                        Layer.alert('请选择模拟器类型');
+                        return false
+                    }
+                    var title = '选择考题';
+                    Fast.api.open(Fast.api.fixurl("teacher/collection/faults/type/"+simtype), title, {
+                        area: ["85%", "85%"],
+                        maxmin: true,
+                        moveOut: false,
+                        offset: ['40px'],
+                        callback: function(value) {
+                            console.log(value)
+                            if (value.task_id) {
+                                $(".question_ids").val(value.task_id);
+                            }
+                        }
+                    });
+                });
+                //任务
+                $(document).on('click', '.btn-task', function () {
+                    var simtype = $("#c-sim_type").val();
+                    if(!simtype){
+                        Layer.alert('请选择模拟器类型');
+                        return false;
+                    }
+                    var title = '选择任务';
+                    parent.Fast.api.open(Fast.api.fixurl("teacher/collection/task/type/"+simtype), title, {
+                        area: ["85%", "85%"],
+                        maxmin: true,
+                        moveOut: false,
+                        offset: ['40px'],
+                        callback: function(value) {
+                            if (value.task_id) {
+                                $(".question_ids").val(value.task_id);
+                            }
+                        }
+                    });
+                });
 
+                // $("input[name='btSelectAll']").click(function () {
+                //     var ids = Table.api.selectedids(table);
+                //     console.log(ids);
+                //     $(".depart_ids").val(ids);
+                // });
+                $("input[name='btSelectAll']").css('display','none');
                 Form.api.bindevent($("form[role=form]"));
             }
         }