| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911 | 
							- <?php
 
- namespace app\admin\controller\student;
 
- use app\common\controller\Backend;
 
- use app\common\model\Config as ConfigModel;
 
- use app\admin\model\Report;
 
- use app\admin\model\Fault;
 
- use think\exception\DbException;
 
- use think\exception\PDOException;
 
- use think\exception\ValidateException;
 
- use think\response\Json;
 
- use think\Db;
 
- use think\Env;
 
- /**
 
-  *
 
-  * @icon fa fa-circle-o
 
-  */
 
- class Collection extends Backend
 
- {
 
-     /**
 
-      * Collection模型对象
 
-      * @var \app\admin\model\teacher\Collection
 
-      */
 
-     protected $model = null;
 
-     protected $exam_model = null;
 
-     protected $whereExtend = null;
 
-     protected $noNeedLogin = ['addreport','editreport','delreport','countdown'];
 
-     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->assignConfig('sim_question_setting_method', ConfigModel::getSimQuestionList());
 
-         $this->whereExtend['exam_collection_type'] = 3;
 
-         $this->whereExtend['exam_collection_state'] = 2;
 
-         $this->assignConfig('sim_sim_type', ConfigModel::getSimTypeList());
 
-         $groupIds = $this->auth->getGroupIds();
 
-         //学员查看自己区队的考试集合
 
-         if(in_array(8, $groupIds)){
 
-             $departid = $this->auth->depart_id;
 
-             $this->whereExtend[] = ['exp',Db::raw("FIND_IN_SET($departid,depart_ids)")];
 
-         }
 
-     }
 
-     /**
 
-      * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
 
-      * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
 
-      * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
 
-      */
 
-     /**
 
-      * 查看
 
-      *
 
-      * @return string|Json
 
-      * @throws \think\Exception
 
-      * @throws DbException
 
-      */
 
-     public function index()
 
-     {
 
-         $isset = $this->model->alias('z')
 
-         ->join('real_exam r','z.exam_collection_id=r.exam_collection_id','left')
 
-         ->where('z.exam_collection_type=3 and z.exam_collection_state=2  and r.endtime=0 and r.user_id='.$this->auth->id)->find();
 
-         if(empty($isset)){
 
-             //提示页面,没有开始的考试
 
-             return $this->view->fetch('tishi');
 
-         }else{
 
-             echo "<script>location.href='/admin/student/collection/into/ids/".$isset['exam_collection_id']."'</script>";
 
-         }
 
-         die();
 
-         //设置过滤方法
 
-         $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);
 
-         foreach ($list as $k => $v){
 
-             $exam_isset =  $this->exam_model->where(['user_id'=>$this->auth->id,'exam_collection_id'=>$v['exam_collection_id'],'exam_collection_type'=>3,'endtime'=>['>',0]])->find();
 
-             if(isset($exam_isset)){
 
-                 $v->is_user_examed = 1;
 
-             }else{
 
-                 $v->is_user_examed = 0;
 
-             }
 
-         }
 
-         unset($v);
 
-         $result = ['total' => $list->total(), 'rows' => $list->items()];
 
-         return json($result);
 
-     }
 
-     //进入考试
 
-     public function  into($ids = null)
 
-     {
 
-         $row = $this->model->get($ids);
 
-         if(!$row){
 
-             $this->error('未找到记录');
 
-         }
 
-         $info = $this->exam_model->where(['user_id'=>$this->auth->id,'exam_collection_id'=>$ids,'exam_collection_type'=>3,'endtime'=>0])->find();
 
-         if(!empty($info)){
 
-             if(!empty($this->auth->seat_id) && !empty($info['seat_id']) && $this->auth->seat_id!=$info['seat_id']){
 
-                 $this->error('已在其他座号有开始的考试,不允许换座号');
 
-             }
 
-             $sim = Db::name('seat')->where('seat_num',$this->auth->seat_id)->find();
 
- //            if(empty($sim['current_sim_id']) && Env::get('app.is_fault')){
 
- //                $this->error('未找到模拟器,不可考试');
 
- //            }
 
-             $info['seat_id'] = $this->auth->seat_id;
 
-             $sim_text = '';
 
-             if($info['sim_type']=='0001'){
 
-                 $sim_type_text = 'FZD04B';
 
-             }else if($info['sim_type']=='0002'){
 
-                 $sim_type_text = 'FZB006';
 
-             }else if($info['sim_type']=='0003'){
 
-                 $sim_type_text = '防化兵型';
 
-             }else{
 
-                 $sim_type_text = '';
 
-             }
 
- //            模拟器状态 0:可用初始化 1:在线 2:模拟器离线 3:网关离线 4:硬件故障异常 5:手动禁用
 
-             if(Env::get('app.is_fault')){
 
-                 $url = config('site.url_type').'/sim/real-exam/student/refresh-sim-state?ip='.$this->auth->server_ip;
 
-                 $ret = json_decode(send_get($url),true);
 
-                 if($ret['code']==200){
 
-                     $sim_text = $ret['msg'];
 
-                 }
 
-             }
 
-             $info['sim_text'] = $sim_text;
 
-             $info['sim_type_text'] = $sim_type_text;
 
-         }
 
-         if(!empty($info['starttime']))
 
-         {
 
-             echo "<script>location.href='/admin/student/collection/examing/ids/".$info['exam_id']."'</script>";
 
-             die();
 
-         }
 
-         $this->view->assign('info', $info);
 
-         $this->view->assign('row', $row);
 
-         $this->assignConfig('exam_id', $info['exam_id']);
 
-         $this->assignConfig('url_type', config('site.url_type'));
 
-         $this->assignConfig('server_ip', $this->auth->server_ip);
 
-         $this->assignConfig('is_fault', Env::get('app.is_fault'));
 
-         return $this->view->fetch();
 
-     }
 
-     public function examing($ids = null)
 
-     {
 
-         $row = $this->exam_model->get($ids);
 
-         if(!$row){
 
-             $this->error('未找到记录');
 
-         }
 
-         if ($this->request->isPost()) {
 
-             //先请求接口判断,再进行处理
 
-             if(Env::get('app.is_fault')){
 
-                 $url = config('site.url_type').'/sim/real-exam/student/exam/submit/'.$ids.'?ip='.$this->auth->server_ip;
 
-                 $ret = json_decode(send_get($url),true);
 
-                 if($ret['code']!=200){
 
-                     $this->error($ret['msg']);
 
-                 }
 
-             }
 
-             //计算分数,保存记录
 
-             $params = $this->request->post('row/a');
 
-             $result = false;
 
-             $score = 100;
 
-             $fault_one_score = 25;
 
-             $fault_two_score = 25;
 
-             $fault_three_score = 25;
 
-             //故障现象
 
-             $xianxian_score = 0;
 
-             $xianxian_arr = [];
 
-             $xianxian_content = [];
 
-             //故障部位
 
-             $buwei_score= 0;
 
-             $buwei_arr = [];
 
-             $buwei_content = [];
 
-             //可能原因
 
-             $yuanyin_socre= 0;
 
-             $yuanyin_arr = [];
 
-             $yuanyin_content = [];
 
-             //排除方法
 
-             $fangfa_score= 0;
 
-             $fangfa_arr = [];
 
-             $fangfa_content = [];
 
-             $other_content = [];
 
-             $content = [];
 
-             Db::startTrans();
 
-             try {
 
-                 if(!empty($params['other_report'])){
 
-                     //获取数组
 
-                     $other_report = json_decode($params['other_report'],true);
 
-                     if(count($other_report)==1){
 
-                         $other_report[1] = [
 
-                            'xh_id' => 1,
 
-                            'xx_id' => '',
 
-                            'xx_name' => '',
 
-                            'yy_id' => '',
 
-                            'yy_name' => '',
 
-                            'bw_id' => '',
 
-                            'bw_name' => '',
 
-                            'pc_id' => '',
 
-                            'pc_name' => ''
 
-                         ];
 
-                         $other_report[2] = [
 
-                            'xh_id' => 2,
 
-                            'xx_id' => '',
 
-                            'xx_name' => '',
 
-                            'yy_id' => '',
 
-                            'yy_name' => '',
 
-                            'bw_id' => '',
 
-                            'bw_name' => '',
 
-                            'pc_id' => '',
 
-                            'pc_name' => ''
 
-                         ];
 
-                     }else if(count($other_report)==2){
 
-                         $other_report[2] = [
 
-                            'xh_id' => 2,
 
-                            'xx_id' => '',
 
-                            'xx_name' => '',
 
-                            'yy_id' => '',
 
-                            'yy_name' => '',
 
-                            'bw_id' => '',
 
-                            'bw_name' => '',
 
-                            'pc_id' => '',
 
-                            'pc_name' => ''
 
-                         ];
 
-                     }
 
-                     $params['other_report'] = json_encode($other_report);
 
-                 }
 
-                 //计算用时
 
-                 $endtime = time();
 
-                 $timediff = $endtime-$row->starttime;
 
-                 $remain = $timediff%86400;
 
-                 //计算分钟数
 
-                 $remain = $remain%3600;
 
-                 $mins = intval($remain/60);
 
-                 //计算秒数
 
-                 $secs = $remain%60;
 
-                 //更新考试结束时间
 
-                 $row->end_time = date('Y-m-d H:i:s',$endtime);
 
-                 $row->endtime = $endtime;
 
-                 $row->exam_status = 5;
 
-                 $row->exam_duration = $mins*60+$secs;
 
-                 $row->exam_duration_text = $mins.'分'.$secs.'秒';
 
-                 $row->other_report = $params['other_report'];
 
-                 $result = $row->save();
 
-                 $info = $this->exam_model->where(['exam_id'=>$ids])->find();
 
-                 //特殊判断结果 故障部位
 
-                 // 002型  薄膜开关FPC排线 蜂鸣器出声口 检测剂 干燥管 维护管
 
-                 // 003型  检测剂  干燥管 维护管
 
-                 $question_arr = ['0002GZBW0001','0002GZBW0003','0002GZBW0005','0002GZBW0009','0002GZBW0010','0003GZBW0006','0003GZBW0007','0003GZBW0008'];
 
-                 //更新故障是否正确
 
-                 $fault_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1])->select();
 
-                 if(!empty($fault_list)){
 
-                     foreach ($fault_list as $k =>$t){
 
-                         $answer_right = 2;
 
-                         //真实故障id 故障部位在  特殊故障部位里面
 
-                         if(in_array($t['fault_id'],$question_arr)){
 
-                             if(!empty($t['sim_fault_answer_value']) && substr($t['sim_fault_answer_value'], -1,1)==0){
 
-                                 $answer_right=1;
 
-                             }
 
-                         }else{
 
-                             if(!empty($t['sim_fault_question_value']) && !empty($t['sim_fault_answer_value'])){  
 
-                                 if($t['sim_fault_question_value']!=$t['sim_fault_answer_value'] ){
 
-                                     $answer_right=1;
 
-                                 }
 
-                             }
 
-                         }
 
-                         Db::name('real_exam_fault')->where(['ref_id'=>$t['ref_id']])->update(['answer_right'=>$answer_right]);
 
-                     }
 
-                 }
 
-                 //计算得分,故障是否有扣分  扣分制
 
-                 $fault_right_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1,'answer_right'=>['>',0]])->select();
 
-                 if(!empty($fault_right_list)){
 
-                     if($fault_right_list[0]['answer_right']==1){
 
-                         $fault_one_score = 0;
 
-                     }
 
-                     if($fault_right_list[1]['answer_right']==1){
 
-                         $fault_two_score = 0;
 
-                     }
 
-                     if($fault_right_list[2]['answer_right']==1){
 
-                         $fault_three_score = 0;
 
-                     }
 
-                 }
 
-                 $fault_right_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1])->select();
 
-                 //根据故障部位 数组
 
-                 $fault_arr = [$fault_right_list[0]['fault_id'],$fault_right_list[1]['fault_id'],$fault_right_list[2]['fault_id']];
 
-                 //根据故障部位查找,匹配的排除方法
 
-                 $paichu_arr = Report::where(['bw_id'=>['in',$fault_arr],'sim_type'=>$info['sim_type']])->column('pc_id');
 
-                 //查找故障现象 数组
 
-                 $partent_fault_id = Fault::where(['fault_id'=>['in',$fault_arr],'sim_type'=>$info['sim_type']])->column('parent_fault_id');
 
-                 //根据故障部位查找,匹配可能原因
 
-                 $yy_arr= Fault::where(['parent_fault_id'=>['in',$partent_fault_id],'sim_type'=>$info['sim_type'],'fault_type'=>2])->column('fault_id');
 
-                 
 
-                 if(!empty($other_report)){
 
-                     foreach ($other_report as $k => $v) {
 
-                         if(!empty($v['xx_id'])){
 
-                             if(in_array($v['xx_id'],$partent_fault_id)){
 
-                                 //故障现象正确
 
-                                 
 
-                                 $kscore = 0;
 
-                                 //故障部位 故障部位错误
 
-                                 $buwei_id= '';
 
-                                 $paichu_id= '';
 
-                                 $yy_id = [];
 
-                                 $xx_id = 0;
 
-                                 foreach($fault_arr as $kk1 =>$va1){
 
-                                     $fault_find = Fault::where(['fault_id'=>$va1])->find();
 
-                                     if($fault_find['parent_fault_id']==$v['xx_id']){
 
-                                         $xx_id = $fault_find['parent_fault_id'];
 
-                                         $buwei_id = $fault_find['fault_id'];
 
-                                         $paichu_id = $fault_find['ref_type4_fault_id'];
 
-                                         $yy_id = Fault::where(['parent_fault_id'=>$fault_find['parent_fault_id'],'sim_type'=>$info['sim_type'],'fault_type'=>2])->column('fault_id');
 
-                                     }
 
-                                 }
 
-                                 if($v['bw_id']!=$buwei_id){
 
-                                     if($v['xx_id']==$xx_id){
 
-                                         $buwei_score = 1+$buwei_score;
 
-                                     }
 
-                                     $kscore = 1+$kscore;
 
-                                     $content[] = [
 
-                                         'gzxz_id'=>$v['xx_id'],
 
-                                         'cx_id'=>$v['bw_id'],
 
-                                         'cx_type'=>'故障部位错写',
 
-                                         'cx_name'=>Fault::where(['fault_id'=>$v['bw_id']])->value('name'),
 
-                                     ];
 
-                                 }
 
-                                 //故障部位少写
 
-                                 //获取当前的故障部位
 
-                                 if($buwei_id!=$v['bw_id']){
 
-                                     if($v['xx_id']==$xx_id){
 
-                                         $buwei_score = 1+$buwei_score;
 
-                                     }
 
-                                     $kscore = 1+$kscore;
 
-                                     $content[] = [
 
-                                         'gzxz_id'=>$v['xx_id'],
 
-                                         'cx_id'=>$buwei_id,
 
-                                         'cx_type'=>'故障部位少写',
 
-                                         'cx_name'=>Fault::where(['fault_id'=>$buwei_id])->value('name'),
 
-                                     ];
 
-                                 }
 
-                             
 
-                                 //排除方法  错写
 
-                                 if($v['pc_id']!=$paichu_id){
 
-                                     $buwei_score = 1+$buwei_score;
 
-                                     $kscore = 1+$kscore;
 
-                                     $content[] = [
 
-                                         'gzxz_id'=>$v['xx_id'],
 
-                                         'cx_id'=>$v['pc_id'],
 
-                                         'cx_type'=>'排除方法错写',
 
-                                         'cx_name'=>Fault::where(['fault_id'=>$v['pc_id']])->value('name'),
 
-                                     ];
 
-                                 }
 
-                                 //排放方法  少写
 
-                                 if($paichu_id!=$v['pc_id']){
 
-                                     if($v['xx_id']==$xx_id){
 
-                                         $buwei_score = 1+$buwei_score;
 
-                                     }
 
-                                     $kscore = 1+$kscore;
 
-                                     $content[] = [
 
-                                         'gzxz_id'=>$v['xx_id'],
 
-                                         'cx_id'=>$v['pc_id'],
 
-                                         'cx_type'=>'排除方法少写',
 
-                                         'cx_name'=>Fault::where(['fault_id'=>$buwei_id])->value('name'),
 
-                                     ];
 
-                                 }
 
-                                 //可能原因 错写
 
-                                 foreach (explode(',',$v['yy_id']) as $key => $value) {
 
-                                     if(!in_array($value,$yy_id)){
 
-                                         $yuanyin_socre = 1+$yuanyin_socre;
 
-                                         $kscore = 1+$kscore;
 
-                                         $content[] = [
 
-                                             'gzxz_id'=>$v['xx_id'],
 
-                                             'cx_id'=>$value,
 
-                                             'cx_type'=>'可能原因错写',
 
-                                             'cx_name'=>Fault::where(['fault_id'=>$value])->value('name'),
 
-                                         ];
 
-                                         // echo $v['xx_id']."@@@".$value."@@@".$kscore."<br/>";
 
-                                     }
 
-                                 }
 
-                                 //可能原因 少写
 
-                                 foreach ($yy_id as $key1 => $value1) {
 
-                                     $yy_id_arr = explode(',',$v['yy_id']);
 
-                                     if(!in_array($value1,$yy_id_arr)){
 
-                                         $yuanyin_socre = 1+$yuanyin_socre;
 
-                                         $kscore = 1+$kscore;
 
-                                         $content[] = [
 
-                                             'gzxz_id'=>$v['xx_id'],
 
-                                             'cx_id'=>$value1,
 
-                                             'cx_type'=>'可能原因少写',
 
-                                             'cx_name'=>Fault::where(['fault_id'=>$value1])->value('name'),
 
-                                         ];
 
-                                     }
 
-                                 }
 
-                                 
 
-                                 if($kscore>5){
 
-                                    $kscore = '-5';
 
-                                 }else if($kscore>0){
 
-                                     $kscore = '-'.$kscore;
 
-                                 }else{
 
-                                    $kscore=0; 
 
-                                 }
 
-                                 $other_content[$k] = [
 
-                                     'gzxz_id'=>$v['xx_id'],
 
-                                     'xh_id' => $k,
 
-                                     'xx_id' => $v['xx_id'],
 
-                                     'xx_name' => $v['xx_name'],
 
-                                     'yy_id' =>$v['yy_id'],
 
-                                     'yy_name' => $v['yy_name'],
 
-                                     'bw_id' => $v['bw_id'],
 
-                                     'bw_name' => $v['bw_name'],
 
-                                     'pc_id' => $v['pc_id'],
 
-                                     'pc_name' => $v['pc_name'],
 
-                                     'cx_type'=>'',
 
-                                     'cx_name'=>$content,
 
-                                     'cx_score'=>$kscore,
 
-                                 ];
 
-                             }else{
 
-                                 $xianxian_score = 5+$xianxian_score;
 
-                                 $other_content[$k] = [
 
-                                     'gzxz_id'=>$v['xx_id'],
 
-                                     'xh_id' => $k,
 
-                                     'xx_id' => $v['xx_id'],
 
-                                     'xx_name' => $v['xx_name'],
 
-                                     'yy_id' =>$v['yy_id'],
 
-                                     'yy_name' => $v['yy_name'],
 
-                                     'bw_id' => $v['bw_id'],
 
-                                     'bw_name' => $v['bw_name'],
 
-                                     'pc_id' => $v['pc_id'],
 
-                                     'pc_name' => $v['pc_name'],
 
-                                     'cx_type'=>'故障现象错写',
 
-                                     'cx_name'=>Fault::where(['fault_id'=>$v['xx_id']])->value('name'),
 
-                                     'cx_score'=>-5,
 
-                                 ];
 
-                             }
 
-                         }else{
 
-                             $xianxian_score = 5+$xianxian_score;
 
-                             $other_content[$k] = [
 
-                                 'gzxz_id'=>'',
 
-                                 'xh_id' => $k,
 
-                                 'xx_id' => '',
 
-                                 'xx_name' => '',
 
-                                 'yy_id' => '',
 
-                                 'yy_name' => '',
 
-                                 'bw_id' => '',
 
-                                 'bw_name' => '',
 
-                                 'pc_id' => '',
 
-                                 'pc_name' => '',
 
-                                 'cx_type'=>'未作答',
 
-                                 'cx_name'=>'',
 
-                                 'cx_score'=>-5,
 
-                             ];
 
-                         }
 
-                     }
 
-                 }else{
 
-                     foreach ($partent_fault_id as $key => $em){
 
-                         $xianxian_score = 5+$xianxian_score;
 
-                         $other_content[] = [
 
-                             'gzxz_id'=>$em,
 
-                             'xh_id' => $key,
 
-                             'xx_id' => '',
 
-                             'xx_name' => '',
 
-                             'yy_id' => '',
 
-                             'yy_name' => '',
 
-                             'bw_id' => '',
 
-                             'bw_name' => '',
 
-                             'pc_id' => '',
 
-                             'pc_name' => '',
 
-                             'cx_type'=>'未作答',
 
-                             'cx_name'=>'',
 
-                             'cx_score'=>-5,
 
-                         ];
 
-                     }
 
-                     unset($em);
 
-                 }
 
-                 // echo "故障现象得分:".$xianxian_score."<br/>";
 
-                 // echo "故障部位得分:".$buwei_score."<br/>";
 
-                 // echo "排除方法得分:".$fangfa_score."<br/>";
 
-                 // echo "可能原因得分:".$yuanyin_socre."<br/>";
 
-                 // echo "<pre>";
 
-                 // print_r($xianxian_content);
 
-                 // echo "<pre>";
 
-                 // print_r($other_content);
 
-                 // die();
 
-                 $weixiu_score = $xianxian_score+$yuanyin_socre+$buwei_score+$fangfa_score;
 
-                 if($weixiu_score>15){
 
-                     $weixiu_score = 15;
 
-                 }
 
-                 //是否超时
 
-                 //$info['countdown_time'] 开始时间+考试时长+10分倒计时
 
-                 $countdown_time= strtotime(date('Y-m-d H:i:s', strtotime('-10 minute',$info['countdown_time'])));
 
-                 $overtime_fen = ceil((time()-$countdown_time) / 60);
 
-                 if($overtime_fen>=10){
 
-                     $overtime_score = 10;
 
-                 }else if($overtime_fen>0 && $overtime_fen<10){
 
-                     $overtime_score = $overtime_fen ;
 
-                 }else{
 
-                     $overtime_score =0;
 
-                 }
 
-                 $fault_score = $score-$fault_one_score-$fault_two_score-$fault_three_score-$weixiu_score-$overtime_score;
 
-                 //更新考试结果表
 
-                 $params['exam_id'] = $ids;
 
-                 $params['total'] = $fault_score;//得分;
 
-                 $params['fault_one_score'] = $fault_one_score;//得分;
 
-                 $params['fault_two_score'] = $fault_two_score;//得分;
 
-                 $params['fault_three_score'] = $fault_three_score;//得分;
 
-                 $params['xianxian_score'] = $xianxian_score;//得分;
 
-                 $params['xianxian_content'] = json_encode($xianxian_content);//错题;
 
-                 $params['yuanyin_socre'] = $yuanyin_socre;//得分;
 
-                 $params['yuanyin_content'] = json_encode($yuanyin_content);//错题;
 
-                 $params['buwei_score'] = $buwei_score;//得分;
 
-                 $params['buwei_content'] = json_encode($buwei_content);//错题;
 
-                 $params['fangfa_score'] = $fangfa_score;//得分;
 
-                 $params['fangfa_content'] = json_encode($fangfa_content);//错题;
 
-                 $params['other_jielun'] = json_encode($other_content);//每个答题的得分
 
-                 $params['overtime_score'] = $overtime_score;//得分;
 
-                 Db::name('real_exam_score')->insert($params);
 
-                 $this->exam_model->where(['exam_id'=>$ids])->update(['total_score'=>$fault_score]);
 
-                 Db::commit();
 
-             } catch (ValidateException|PDOException|Exception $e) {
 
-                 Db::rollback();
 
-                 $this->error($e->getMessage());
 
-             }
 
-             if ($result === false) {
 
-                 $this->error(__('No rows were inserted'));
 
-             }
 
-             $this->success('交卷成功,待老师确认成绩','/admin/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();
 
-         }
 
-         $isloading =1;
 
-         if(empty($row->other_replace)){
 
-             $isloading = 0;
 
-             $row->other_replace = '[{"fault_id":"","request_status":"0"}]';
 
-         }
 
-         $row->other_report_text = !empty($row->other_report) ? json_decode($row->other_report,true) : [];
 
-         $other_report_count = !empty($row->other_report) ? count(json_decode($row->other_report,true)) :0;
 
-         //还未开始考试
 
-         $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);
 
-         }
 
-         if(empty($row->countdown_time)){
 
-             $duration = 10+$row->limit_duration;
 
-             $this->exam_model->where('exam_id',$ids)->update(['countdown_time'=>strtotime(date('Y-m-d H:i:s', strtotime('+'.$duration.' minute',$row->starttime)))]);
 
-         }
 
-         $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->assignConfig('other_report_count',$other_report_count);
 
-         $this->view->assign('row', $row);
 
-         $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);
 
-         //可能原因
 
-         $yuanyin = Fault::where(['fault_type'=>2,'sim_type'=>$row->sim_type])->select();
 
-         $this->view->assign('yuanyin', $yuanyin);
 
-         //故障部位
 
-         $buwei = Fault::where(['fault_type'=>3,'sim_type'=>$row->sim_type])->select();
 
-         $this->view->assign('buwei', $buwei);
 
-         //排除方法
 
-         $paichu = Fault::where(['fault_type'=>4,'sim_type'=>$row->sim_type])->select();
 
-         $this->view->assign('paichu', $paichu);
 
-         return $this->view->fetch();
 
-     }
 
-     public function replace($ids = null)
 
-     {
 
-         if ($this->request->isPost()) {
 
-             $params = $this->request->post('other_replace','');
 
-             $other_report = $this->request->post('other_report','');
 
-             $param = json_decode($params,true);
 
-             $faultid_arr = [];
 
-             foreach ($param as $it) {
 
-                 if(!empty($it['fault_id'])){
 
-                     $faultid_arr[] = $it['fault_id'];
 
-                 }
 
-             }
 
-             $row = $this->exam_model->get($ids);
 
-             $rowinfo = $this->model->get($row->exam_collection_id);
 
-             $uniqueArray = array_unique($faultid_arr);
 
-             //考试 判断
 
-             if (count($faultid_arr) != count($uniqueArray) && $rowinfo['exam_collection_type']==3) {
 
-                 $this->error('存在相同可更换件,不允许重复申请。');
 
-             }
 
-             //考试 判断
 
-             if (count($faultid_arr) != count($uniqueArray) && $rowinfo['exam_collection_type']==2) {
 
-                 $this->error('存在相同可更换件,不允许重复申请。');
 
-             }
 
-             if(!empty($param)){
 
-                 $faultid_arr = [];
 
-                 foreach ($param as $key=>$item){
 
-                     if(!empty($item['fault_id'])){
 
-                         $isreplace = Db::name('real_exam_comp_request')->where(['exam_id'=>$ids,'fault_id'=>$item['fault_id'],'sim_type'=>$row->sim_type])->find();
 
-                         if(empty($isreplace)){
 
-                             $add = [
 
-                                 'exam_id'=>$ids,
 
-                                 'sim_type'=>$this->exam_model->where('exam_id',$ids)->value('sim_type'),
 
-                                 'fault_id'=>$item['fault_id'],
 
-                                 'request_status'=>1,
 
-                                 'fault_name'=>Db::name('fault')->where('fault_id',$item['fault_id'])->value('replace_name'),
 
-                                 'create_by_user_id'=>$this->auth->id,
 
-                                 'create_by'=>$this->auth->nickname,
 
-                                 '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_comp_request')->insert($add);
 
-                             $status = 1;
 
-                         }else{
 
-                             $status = $isreplace['request_status'];
 
-                         }
 
-                         $faultid_arr[] = [
 
-                             'fault_id'=>$item['fault_id'],
 
-                             'request_status'=>$status,
 
-                         ];
 
-                     }
 
-                 }
 
-                 unset($item);
 
-                 $row = $this->exam_model->get($ids);
 
-                 $row-> other_replace = $faultid_arr ? json_encode($faultid_arr):'';
 
-                 $row-> other_report = $other_report;
 
-                 $result = $row->save();
 
-             }
 
-             $this->success('申请成功,待老师审批');
 
-         }
 
-     }
 
-     /**
 
-      * @Notes:添加维修报告
 
-      * @Author: jxb
 
-      * @Date: 2025/1/21
 
-      * @Time: 10:29
 
-      */
 
-     public function addreport($ids = null){
 
-         $row = $this->exam_model->get($ids);
 
-         if(!$row){
 
-             $this->error('未找到记录');
 
-         }
 
-         if ($this->request->isPost()) {
 
-             $unwin = $this->request->post('unwin/a');
 
-             $arr = [];
 
-             if(!empty($unwin)){
 
-                 if(empty($unwin['xx_id'])){
 
-                     $this->error('故障现象选项有空白项');
 
-                 }
 
-                 if(empty($unwin['yy_id'][0])){
 
-                     $this->error('可能原因选项有空白项');
 
-                 }
 
-                 if(empty($unwin['bw_id'])){
 
-                     $this->error('故障部位选项有空白项');
 
-                 }
 
-                 if(empty($unwin['pc_id'])){
 
-                     $this->error('排除方法选项有空白项');
 
-                 }
 
-                 $xx_name = Fault::where('fault_id',$unwin['xx_id'])->value('name');
 
-                 $yy_name = Fault::where('fault_id','in',$unwin['yy_id'])->column('name');
 
-                 $bw_name = Fault::where('fault_id',$unwin['bw_id'])->value('name');
 
-                 $pc_name = Fault::where('fault_id',$unwin['pc_id'])->value('name');
 
-                 $arr = [
 
-                     'xh_id' => $unwin['xh_id'],
 
-                     'xx_id' => $unwin['xx_id'],
 
-                     'xx_name'=>$xx_name,
 
-                     'yy_id' => implode(',',$unwin['yy_id']),
 
-                     'yy_name' =>  implode(',',$yy_name),
 
-                     'bw_id' => $unwin['bw_id'],
 
-                     'bw_name' => $bw_name,
 
-                     'pc_id' => $unwin['pc_id'],
 
-                     'pc_name' => $pc_name,
 
-                 ];
 
-             }
 
-             $other_report = !empty($row->other_report) ? json_decode($row->other_report,true) : [];
 
-             array_push($other_report,$arr);
 
-             $row->other_report = json_encode($other_report);
 
-             $row->save();
 
-             $this->success();
 
-         }
 
-         //故障现象
 
-         $xianxiang = Fault::where(['fault_type'=>1,'sim_type'=>$row->sim_type])->order('order_num asc')->select();
 
-         $this->view->assign('xianxiang', $xianxiang);
 
-         //可能原因
 
-         $yuanyin = Fault::where(['fault_type'=>2,'sim_type'=>$row->sim_type])->order('order_num asc')->column('fault_id,name');
 
-         $this->view->assign('yuanyin', $yuanyin);
 
-         //故障部位
 
-         $buwei = Fault::where(['fault_type'=>3,'sim_type'=>$row->sim_type])->order('order_num asc')->column('fault_id,name');
 
-         $this->view->assign('buwei', $buwei);
 
-         //排除方法
 
-         $paichu = Fault::where(['fault_type'=>4,'sim_type'=>$row->sim_type])->order('order_num asc')->column('fault_id,name');
 
-         $this->view->assign('paichu', $paichu);
 
-         $row->other_report_count = 0;
 
-         $xxid = [];
 
-         if(!empty($row->other_report)){
 
-             $row->other_report_count = count(json_decode($row->other_report,true));
 
-             $otherreport = json_decode($row->other_report,true);
 
-             foreach ($otherreport as $k  =>$item){
 
-                 array_push($xxid,$item['xx_id']);
 
-             }
 
-         }
 
-         $row->xxid = $xxid;
 
-         $this->view->assign('row', $row);
 
-         return $this->view->fetch();
 
-     }
 
-     /**
 
-      * @Notes:编辑报告
 
-      * @Author: jxb
 
-      * @Date: 2025/1/21
 
-      * @Time: 15:04
 
-      */
 
-     public function editreport($ids = null,$xh_id = null){
 
-         $row = $this->exam_model->get($ids);
 
-         if(!$row){
 
-             $this->error('未找到记录');
 
-         }
 
-         if ($this->request->isPost()) {
 
-             $unwin = $this->request->post('unwin/a');
 
-             if(!empty($unwin)){
 
-                 if(empty($unwin['xx_id'])){
 
-                     $this->error('故障现象选项有空白项');
 
-                 }
 
-                 if(empty($unwin['yy_id'][0])){
 
-                     $this->error('可能原因选项有空白项');
 
-                 }
 
-                 if(empty($unwin['bw_id'])){
 
-                     $this->error('故障部位选项有空白项');
 
-                 }
 
-                 if(empty($unwin['pc_id'])){
 
-                     $this->error('排除方法选项有空白项');
 
-                 }
 
-                 $xx_name = Fault::where('fault_id',$unwin['xx_id'])->value('name');
 
-                 $yy_name = Fault::where('fault_id','in',$unwin['yy_id'])->column('name');
 
-                 $bw_name = Fault::where('fault_id',$unwin['bw_id'])->value('name');
 
-                 $pc_name = Fault::where('fault_id',$unwin['pc_id'])->value('name');
 
-                 $other_report = !empty($row->other_report) ? json_decode($row->other_report,true) : [];
 
-                 foreach ($other_report as $k  =>$item){
 
-                     if($k==$xh_id){
 
-                         $other_report[$k]['xx_id'] =$unwin['xx_id'];
 
-                         $other_report[$k]['xx_name'] =$xx_name;
 
-                         $other_report[$k]['yy_id'] = implode(',',$unwin['yy_id']);
 
-                         $other_report[$k]['yy_name'] =implode(',',$yy_name);
 
-                         $other_report[$k]['bw_id'] = $unwin['bw_id'];
 
-                         $other_report[$k]['bw_name'] =$bw_name;
 
-                         $other_report[$k]['pc_id'] =$unwin['pc_id'];
 
-                         $other_report[$k]['pc_name'] =$pc_name;
 
-                     }
 
-                 }
 
-                 $row->other_report = json_encode($other_report);
 
-                 $row->save();
 
-             }
 
-             $this->success();
 
-         }
 
-         //故障现象
 
-         $xianxiang = Fault::where(['fault_type'=>1,'sim_type'=>$row->sim_type])->order('order_num asc')->select();
 
-         $this->view->assign('xianxiang', $xianxiang);
 
-         //可能原因
 
-         $yuanyin = Fault::where(['fault_type'=>2,'sim_type'=>$row->sim_type])->order('order_num asc')->column('fault_id,name');
 
-         $this->view->assign('yuanyin', $yuanyin);
 
-         //故障部位
 
-         $buwei = Fault::where(['fault_type'=>3,'sim_type'=>$row->sim_type])->order('order_num asc')->column('fault_id,name');
 
-         $this->view->assign('buwei', $buwei);
 
-         //排除方法
 
-         $paichu = Fault::where(['fault_type'=>4,'sim_type'=>$row->sim_type])->order('order_num asc')->column('fault_id,name');
 
-         $this->view->assign('paichu', $paichu);
 
-         $row->other_report_text = [];
 
-         $xxid = [];
 
-         if(!empty($row->other_report)){
 
-             $other_report = json_decode($row->other_report,true);
 
-             foreach ($other_report as $k  =>$item){
 
-                 if($k==$xh_id){
 
-                     $row->other_report_text = [
 
-                         'xx_id'=>$item['xx_id'],
 
-                         'yy_id'=>explode(',',$item['yy_id']),
 
-                         'bw_id'=>$item['bw_id'],
 
-                         'pc_id'=>$item['pc_id'],
 
-                         'xh_id'=>$item['xh_id']
 
-                     ];
 
-                 }else{
 
-                     array_push($xxid,$item['xx_id']);
 
-                 }
 
-             }
 
-         }
 
-         $row->xxid = $xxid;
 
-         $this->view->assign('row', $row);
 
-         return $this->view->fetch();
 
-     }
 
-     /**
 
-      * @Notes:移除 维修报告
 
-      * @Author: jxb
 
-      * @Date: 2025/1/21
 
-      * @Time: 14:45
 
-      */
 
-     public function delreport($ids = null){
 
-         $row = $this->exam_model->get($ids);
 
-         if(!$row){
 
-             $this->error('未找到记录');
 
-         }
 
-         if ($this->request->isPost()) {
 
-             $xh_id = $this->request->post('xh_id');
 
-             if(!empty($row->other_report)){
 
-                 $other_report = json_decode($row->other_report,true);
 
-                 unset($other_report[$xh_id]);
 
-                 $row->other_report = json_encode($other_report);
 
-                 $row->save();
 
-             }
 
-             $this->success();
 
-         }
 
-     }  
 
-     public function countdown($ids = null){
 
-         $row = $this->exam_model->get($ids);
 
-         if(!$row){
 
-             $this->error('未找到记录');
 
-         }
 
-         // 计算差值
 
-         // $time = strtotime(date('Y-m-d H:i:s', strtotime('+10 minute',$row->countdown_time)));
 
-         $diff = $row->countdown_time-time();
 
-         // 将差值转换为秒
 
-         $seconds = $diff;
 
-         $minutes = floor($seconds / 60);
 
-         $seconds = $seconds % 60;
 
-         if($minutes<0){
 
-             $a = 0;
 
-         }else{
 
-             $a = '已经超时,'.$minutes.'分'.$seconds.'秒后系统自动交卷。';
 
-         }
 
-         $this->success($a);
 
-     }
 
-     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('操作成功','/admin/student/collection/index');
 
-         }
 
-         return $this->view->fetch();
 
-     }
 
- }
 
 
  |