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 = "
" . token() . "
"; $html .= ""; return $html; } /** * 超时异常数据处理 * 已开始考试,且 未主动交卷。。。。 关闭浏览器,断电时间超过考试时间。 * @return void */ public function timeout() { $where = ['exam_status'=>4,'countdown_time'=>['>',0],'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('完成'); } }