| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 | 
							- <?php
 
- namespace app\admin\controller;
 
- use app\admin\model\AdminLog;
 
- use app\common\controller\Backend;
 
- use think\Config;
 
- use think\Hook;
 
- use think\Db;
 
- use think\Session;
 
- use think\Validate;
 
- /**
 
-  * 后台首页
 
-  * @internal
 
-  */
 
- class Index extends Backend
 
- {
 
-     protected $noNeedLogin = ['login','timeout'];
 
-     protected $noNeedRight = ['index', 'logout'];
 
-     protected $layout = '';
 
-     public function _initialize()
 
-     {
 
-         parent::_initialize();
 
-         //移除HTML标签
 
-         $this->request->filter('trim,strip_tags,htmlspecialchars');
 
-     }
 
-     /**
 
-      * 后台首页
 
-      */
 
-     public function index()
 
-     {
 
-         $cookieArr = ['adminskin' => "/^skin\-([a-z\-]+)\$/i", 'multiplenav' => "/^(0|1)\$/", 'multipletab' => "/^(0|1)\$/", 'show_submenu' => "/^(0|1)\$/"];
 
-         foreach ($cookieArr as $key => $regex) {
 
-             $cookieValue = $this->request->cookie($key);
 
-             if (!is_null($cookieValue) && preg_match($regex, $cookieValue)) {
 
-                 config('fastadmin.' . $key, $cookieValue);
 
-             }
 
-         }
 
-         //左侧菜单
 
-         list($menulist, $navlist, $fixedmenu, $referermenu) = $this->auth->getSidebar([
 
-             'dashboard' => 'hot',
 
-             'addon'     => ['new', 'red', 'badge'],
 
-             'auth/rule' => __('Menu'),
 
-         ], $this->view->site['fixedpage']);
 
-         $action = $this->request->request('action');
 
-         if ($this->request->isPost()) {
 
-             if ($action == 'refreshmenu') {
 
-                 $this->success('', null, ['menulist' => $menulist, 'navlist' => $navlist]);
 
-             }
 
-         }
 
-         $this->assignconfig('cookie', ['prefix' => config('cookie.prefix')]);
 
-         $this->view->assign('menulist', $menulist);
 
-         $this->view->assign('navlist', $navlist);
 
-         $this->view->assign('fixedmenu', $fixedmenu);
 
-         $this->view->assign('referermenu', $referermenu);
 
-         $this->view->assign('title', __('Home'));
 
-         return $this->view->fetch();
 
-     }
 
-     /**
 
-      * 管理员登录
 
-      */
 
-     public function login()
 
-     {
 
-         $url = $this->request->get('url', '', 'url_clean');
 
-         $url = $url ?: 'index/index';
 
-         if ($this->auth->isLogin()) {
 
-             $this->success(__("You've logged in, do not login again"), $url);
 
-         }
 
-         //保持会话有效时长,单位:小时
 
-         $keeyloginhours = 24;
 
-         if ($this->request->isPost()) {
 
-             $username = $this->request->post('username');
 
-             $password = $this->request->post('password', '', null);
 
-             $keeplogin = $this->request->post('keeplogin');
 
-             $token = $this->request->post('__token__');
 
-             $rule = [
 
-                 'username'  => 'require|length:3,30',
 
-                 'password'  => 'require|length:3,30',
 
-                 '__token__' => 'require|token',
 
-             ];
 
-             $data = [
 
-                 'username'  => $username,
 
-                 'password'  => $password,
 
-                 '__token__' => $token,
 
-             ];
 
-             if (Config::get('fastadmin.login_captcha')) {
 
-                 $rule['captcha'] = 'require|captcha';
 
-                 $data['captcha'] = $this->request->post('captcha');
 
-             }
 
-             $validate = new Validate($rule, [], ['username' => __('Username'), 'password' => __('Password'), 'captcha' => __('Captcha')]);
 
-             $result = $validate->check($data);
 
-             if (!$result) {
 
-                 $this->error($validate->getError(), $url, ['token' => $this->request->token()]);
 
-             }
 
-             AdminLog::setTitle(__('Login'));
 
-             $result = $this->auth->login($username, $password, $keeplogin ? $keeyloginhours * 3600 : 0);
 
-             if ($result === true) {
 
-                 Hook::listen("admin_login_after", $this->request);
 
-                 $this->success(__('Login successful'), $url, ['url' => $url, 'id' => $this->auth->id, 'username' => $username, 'avatar' => $this->auth->avatar]);
 
-             } else {
 
-                 $msg = $this->auth->getError();
 
-                 $msg = $msg ? $msg : __('Username or password is incorrect');
 
-                 $this->error($msg, $url, ['token' => $this->request->token()]);
 
-             }
 
-         }
 
-         // 根据客户端的cookie,判断是否可以自动登录
 
-         if ($this->auth->autologin()) {
 
-             Session::delete("referer");
 
-             $this->redirect($url);
 
-         }
 
-         $background = Config::get('fastadmin.login_background');
 
-         $background = $background ? (stripos($background, 'http') === 0 ? $background : config('site.cdnurl') . $background) : '';
 
-         $this->view->assign('keeyloginhours', $keeyloginhours);
 
-         $this->view->assign('background', $background);
 
-         $this->view->assign('title', __('Login'));
 
-         Hook::listen("admin_login_init", $this->request);
 
-         return $this->view->fetch();
 
-     }
 
-     /**
 
-      * 退出登录
 
-      */
 
-     public function logout()
 
-     {
 
-         if ($this->request->isPost()) {
 
-             $this->auth->logout();
 
-             Hook::listen("admin_logout_after", $this->request);
 
-             $this->success(__('Logout successful'), 'index/login');
 
-         }
 
-         $html = "<form id='logout_submit' name='logout_submit' action='' method='post'>" . token() . "<input type='submit' value='ok' style='display:none;'></form>";
 
-         $html .= "<script>document.forms['logout_submit'].submit();</script>";
 
-         return $html;
 
-     }
 
-     /**
 
-      * 超时异常数据处理
 
-      * 已开始考试,且 未主动交卷。。。。  关闭浏览器,断电时间超过考试时间。
 
-      * @return void
 
-      */
 
-     public function timeout()
 
-     {
 
-         $where = ['exam_status'=>4,'countdown_time'=>['<',time()],'exam_collection_type'=>3,'endtime'=>0];
 
-         $list = Db::name('real_exam')->where($where)->select();
 
-         foreach ($list as $k => $v) {
 
-             $score = 100;
 
-             $fault_one_score = 25;
 
-             $fault_two_score = 25;
 
-             $fault_three_score = 25;
 
-             $overtime_score = 10;//超时
 
-             //故障现象
 
-             $xianxian_score = 15;
 
-             $other_jielun = [];
 
-             $other_replace = '[{"fault_id":"","request_status":"0"}]';
 
-             //故障表查找得分
 
-             //特殊判断结果 故障部位
 
-             // 002型  薄膜开关FPC排线 蜂鸣器出声口 检测剂 干燥管 维护管
 
-             // 003型  检测剂  干燥管 维护管
 
-             $question_arr = ['0002GZBW0001','0002GZBW0003','0002GZBW0005','0002GZBW0009','0002GZBW0010','0003GZBW0006','0003GZBW0007','0003GZBW0008'];
 
-             //更新故障是否正确
 
-             $fault_list = Db::name('real_exam_fault')->where(['exam_id'=>$v['exam_id'],'flag'=>1])->select();
 
-             if(!empty($fault_list)){
 
-                 foreach ($fault_list as $k1 =>$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'=>$v['exam_id'],'flag'=>1,'answer_right'=>['>',0]])->select();
 
-             if(!empty($fault_right_list)){
 
-                 if($fault_right_list[0]['answer_right']==1){
 
-                     $fault_one_score = 0;
 
-                 }
 
-                 if(!empty($fault_right_list[1]['answer_right']) && $fault_right_list[1]['answer_right']==1){
 
-                     $fault_two_score = 0;
 
-                 }
 
-                 if(!empty($fault_right_list[2]['answer_right']) &&  $fault_right_list[2]['answer_right']==1){
 
-                     $fault_three_score = 0;
 
-                 }
 
-             }
 
-             $total = $score-$fault_one_score-$fault_two_score-$fault_three_score-$xianxian_score-$overtime_score;
 
-             //追加考试记录数据
 
-             $add = [
 
-                 'exam_id' => $v['exam_id'],
 
-                 'total' => $total,
 
-                 'fault_one_score' => $fault_one_score,
 
-                 'fault_two_score' => $fault_two_score,
 
-                 'fault_three_score' => $fault_three_score,
 
-                 'xianxian_score' => $xianxian_score,
 
-                 'other_replace' => $other_replace,
 
-                 'other_jielun' => $other_jielun,
 
-                 'overtime_score' => $overtime_score,
 
-             ];
 
-             Db::name('real_exam_score')->insert($add);
 
-             //计算用时
 
-             $endtime = time();
 
-             $timediff = $endtime-$v['starttime'];
 
-             $remain = $timediff%86400;
 
-             //计算分钟数
 
-             $remain = $remain%3600;
 
-             $mins = intval($remain/60);
 
-             //计算秒数
 
-             $secs = $remain%60;
 
-             $diffInSeconds = $endtime-$v['starttime']; // 两个时间戳之间的差异(秒)
 
-             $minutes = floor($diffInSeconds / 60); // 计算分钟数
 
-             $seconds = $diffInSeconds % 60; // 计算剩余的秒数
 
-             $exam_duration = $mins*60+$secs;
 
-             $exam_duration_text = $minutes.'分'.$seconds.'秒';
 
-             $endtime = $endtime;
 
-             $end_time = date('Y-m-d H:i:s',$endtime);
 
-             $update = [
 
-                 'total_score'=>$total,
 
-                 'exam_duration'=>$exam_duration,
 
-                 'exam_duration_text'=>$exam_duration_text,
 
-                 'exam_status'=>5,
 
-                 'endtime'=>$endtime,
 
-                 'end_time'=>$end_time,
 
-             ];
 
-             //同步更新成绩
 
-             Db::name('real_exam')->where(['exam_id'=>$v['exam_id']])->update($update);
 
-         }
 
-         unset($v);
 
-         die('完成');
 
-     }
 
- }
 
 
  |