| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 | <?phpnamespace app\admin\controller\student;use app\admin\model\Fault;use app\admin\model\Report;use app\common\controller\Backend;use app\common\model\Config as ConfigModel;use think\Db;use think\exception\PDOException;/** * sim-自主练习集合管理 * * @icon fa fa-circle-o */class Exercise extends Backend{    /**     * Collection模型对象     * @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->assign('sim_sim_type', ConfigModel::getSimTypeList());    }    /**     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改     */    public function index()    {        //设置过滤方法        $this->request->filter(['strip_tags', 'trim']);        if (false === $this->request->isAjax()) {            return $this->view->fetch();        }        if ($this->request->isPost()) {            $params = $this->request->post('row/a');            $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);                $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' =>1,                    'seat_id' =>12,                    '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);                $count = $examid;                Db::commit();            } catch (PDOException|Exception $e) {                Db::rollback();                $this->error($e->getMessage());            }            if ($count) {                $this->success('开始成功','/ZQOtIMLKud.php/student/exercise/examing/ids/'.$count);            }            $this->error(__('No rows were updated'));        }    }    public  function  examing($ids = null)    {        $row = $this->exam_model->get($ids);        if(!$row){            $this->error('未找到记录');        }        if ($this->request->isPost()) {            $params = $this->request->post('row/a');            $row->end_time = date('Y-m-d H:i:s');            $row->endtime = time();            $row->exam_status = 5;            $row->save();            $this->success('交卷成功','/ZQOtIMLKud.php/student/exercise/analysis/ids/'.$row['exam_id']);        }//        if(empty($row->starttime)){//            $row->start_time = date('Y-m-d H:i:s');//            $row->starttime = time();//            $row->exam_status = 4;//            $row->save();//        }        $isloading =1;        if(empty($row->other_replace)){            $isloading = 0;            $row->other_replace = '[{"fault_id":"","request_status":"0"}]';        }        if(empty($row->other_report)){            $row->other_report = '[{"xx_id":"","yy_id":"","bw_id":"","pc_id":""}]';        }        $row->limit_duration = $this->model->where(['exam_collection_id'=>$row['exam_collection_id']])->value('limit_duration');        if(empty($row->starttime)){            $timer = 60*$row->limit_duration;        }else{            $timer = $row->limit_duration*60 - abs(time() - $row->starttime);        }        $departmentdata = [];        $departmentdata = Fault::where(['replace_part'=>1,'sim_type'=>$row->sim_type])->order('fault_id asc')->select();        $this->view->assign('departmentdata', $departmentdata);        //故障现象        $xianxiang = Fault::where(['fault_type'=>1,'sim_type'=>$row->sim_type])->select();        $this->view->assign('xianxiang', $xianxiang);        $row->replace_list =Db::name('real_exam_comp_request')->where(['exam_id'=>$ids])->select();        $this->assignConfig('ids',$ids);        $this->assignConfig('timer',$timer);        $this->assignConfig('isloading',$isloading);        $this->view->assign('row', $row);        return $this->view->fetch();    }    public function analysis($ids = null)    {        $row = $this->exam_model->get($ids);        if(!$row){            $this->error('未找到记录');        }        if ($this->request->isPost()) {            $params = $this->request->post('row/a');            //计算总分到学员考试表            $this->success('操作成功','/ZQOtIMLKud.php/student/exercise/index');        }        return $this->view->fetch();    }}
 |