Browse Source

20250421 优化调整

贾小兵 1 week ago
parent
commit
5632d71bdb

+ 114 - 1
application/admin/controller/Index.php

@@ -6,6 +6,7 @@ use app\admin\model\AdminLog;
 use app\common\controller\Backend;
 use app\common\controller\Backend;
 use think\Config;
 use think\Config;
 use think\Hook;
 use think\Hook;
+use think\Db;
 use think\Session;
 use think\Session;
 use think\Validate;
 use think\Validate;
 
 
@@ -16,7 +17,7 @@ use think\Validate;
 class Index extends Backend
 class Index extends Backend
 {
 {
 
 
-    protected $noNeedLogin = ['login'];
+    protected $noNeedLogin = ['login','timeout'];
     protected $noNeedRight = ['index', 'logout'];
     protected $noNeedRight = ['index', 'logout'];
     protected $layout = '';
     protected $layout = '';
 
 
@@ -138,4 +139,116 @@ class Index extends Backend
         return $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('完成');
+    }
 }
 }

+ 1 - 1
application/admin/controller/student/Collection.php

@@ -887,7 +887,7 @@ class Collection extends Backend
         $seconds = $diff;
         $seconds = $diff;
         $minutes = floor($seconds / 60);
         $minutes = floor($seconds / 60);
         $seconds = $seconds % 60;
         $seconds = $seconds % 60;
-        if($minutes==0 && $seconds==0){
+        if($minutes<0){
             $a = 0;
             $a = 0;
         }else{
         }else{
             $a = '已经超时,'.$minutes.'分'.$seconds.'秒后系统自动交卷。';
             $a = '已经超时,'.$minutes.'分'.$seconds.'秒后系统自动交卷。';

+ 1 - 1
application/admin/controller/student/Practice.php

@@ -583,7 +583,7 @@ class Practice extends Backend
         }
         }
 
 
         if(empty($row->countdown_time)){
         if(empty($row->countdown_time)){
-            $duration = 10+$row->limit_duration;
+            $duration = bcadd(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)))]);
             $this->exam_model->where('exam_id',$ids)->update(['countdown_time'=>strtotime(date('Y-m-d H:i:s', strtotime('+'.$duration.' minute',$row->starttime)))]);
         }
         }
 
 

+ 14 - 6
application/admin/controller/teacher/Exams.php

@@ -179,10 +179,14 @@ class Exams extends Backend
         try {
         try {
             //是否采用模型验证
             //是否采用模型验证
             $koufen = 0;
             $koufen = 0;
-            foreach ($other_jielun as $key => $value) {
-                if(!empty($value['cx_score'])){
-                    $koufen = $koufen+abs($value['cx_score']);
+            if(!empty($other_jielun)){
+                foreach ($other_jielun as $key => $value) {
+                    if(!empty($value['cx_score'])){
+                        $koufen = $koufen+abs($value['cx_score']);
+                    }
                 }
                 }
+            }else{
+                $koufen = 15; //超时未自动交卷的
             }
             }
             $params['total'] = 100-$params['fault_one_score']-$params['fault_two_score']-$params['fault_three_score']-$params['overtime_score']-$koufen;
             $params['total'] = 100-$params['fault_one_score']-$params['fault_two_score']-$params['fault_three_score']-$params['overtime_score']-$koufen;
             $result = Db::name('real_exam_score')->where('id', $row['id'])->update($params);
             $result = Db::name('real_exam_score')->where('id', $row['id'])->update($params);
@@ -240,10 +244,14 @@ class Exams extends Backend
 
 
 
 
         $koufen = 0;
         $koufen = 0;
-        foreach ($other_jielun as $key => $value) {
-            if(!empty($value['cx_score'])){
-                $koufen = $koufen+abs($value['cx_score']);
+        if(!empty($other_jielun)){
+            foreach ($other_jielun as $key => $value) {
+                if(!empty($value['cx_score'])){
+                    $koufen = $koufen+abs($value['cx_score']);
+                }
             }
             }
+        }else{
+            $koufen = 15;
         }
         }
         $report_score = 15-$koufen;
         $report_score = 15-$koufen;
         $row['report_score'] = $report_score>0?$report_score:0; 
         $row['report_score'] = $report_score>0?$report_score:0; 

+ 1 - 1
application/admin/model/department/Department.php

@@ -43,7 +43,7 @@ class Department extends Model
         self::afterInsert(function ($row) {
         self::afterInsert(function ($row) {
             //创建时自动添加权重值
             //创建时自动添加权重值
             $pk = $row->getPk();
             $pk = $row->getPk();
-            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
+//            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
             self::clearCache();
             self::clearCache();
         });
         });
         self::afterDelete(function ($row) {
         self::afterDelete(function ($row) {

+ 10 - 10
public/assets/js/backend/department/index.js

@@ -40,16 +40,16 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                         {
                         {
                             field: 'weigh',
                             field: 'weigh',
                             title: __('Weigh'),
                             title: __('Weigh'),
-                            formatter: function (value, row, index) {
-                                return '<input type="text" class="form-control text-center text-weigh" data-id="' + row.id + '" value="' + value + '" style="width:50px;margin:0 auto;" />';
-                            },
-                            events: {
-                                "dblclick .text-weigh": function (e) {
-                                    e.preventDefault();
-                                    e.stopPropagation();
-                                    return false;
-                                }
-                            }
+                            // formatter: function (value, row, index) {
+                            //     return '<input type="text" class="form-control text-center text-weigh" data-id="' + row.id + '" value="' + value + '" style="width:50px;margin:0 auto;" />';
+                            // },
+                            // events: {
+                            //     "dblclick .text-weigh": function (e) {
+                            //         e.preventDefault();
+                            //         e.stopPropagation();
+                            //         return false;
+                            //     }
+                            // }
                         },
                         },
                         {
                         {
                             field: 'createtime',
                             field: 'createtime',