Browse Source

20250209 优化调整

贾小兵 2 months ago
parent
commit
39d900322c

+ 5 - 3
application/admin/controller/student/Collection.php

@@ -117,10 +117,12 @@ class Collection extends Backend
             if(!empty($this->auth->seat_id) && !empty($info['seat_id']) && $this->auth->seat_id!=$info['seat_id']){
                 $this->error('已在其他座号有开始的考试,不允许换座号');
             }
-            $this->exam_model->where('exam_id',$info['exam_id'])->update(['seat_id'=>$this->auth->seat_id,'sim_id'=>$this->auth->sim_id]);
+            $sim = Db::name('sim')->where('sim_type',$info['sim_type'])->where('seat_id',$this->auth->seat_id)->find();
+            if(empty($sim)){
+                $this->error('未找到模拟器,不可考试');
+            }
+            $this->exam_model->where('exam_id',$info['exam_id'])->update(['seat_id'=>$this->auth->seat_id,'sim_id'=>$sim['sim_id']]);
             $info['seat_id'] = $this->auth->seat_id;
-//            $sim = Db::name('sim')->where('seat_id',$this->auth->seat_id)->find();
-            $sim = Db::name('sim')->where('sim_type',$info['sim_type'])->find();
             $sim_text = '';
             if(!empty($sim)){
                 if($sim['sim_state']==1){

+ 7 - 2
application/admin/controller/student/Exercise.php

@@ -65,6 +65,11 @@ class Exercise extends Backend
                 $params['end_time'] = date('Y-m-d');
                 $exam_id = $this->model->insertGetId($params);
 
+                $sim = Db::name('sim')->where('sim_type',$params['sim_type'])->where('seat_id',$this->auth->seat_id)->find();
+                if(empty($sim)){
+                    $this->error('未找到模拟器,不可练习');
+                }
+
                 $data = [
                     'exam_collection_id' => $exam_id,
                     'user_id' => $this->auth->id,
@@ -74,8 +79,8 @@ class Exercise extends Backend
                     '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,
+                    'seat_id' =>$this->auth->seat_id,
+                    'sim_id' =>$sim['sim_id'],
                     'exam_status'=>4,
                     'start_time'=>date('Y-m-d H:i:s'),
                     'starttime'=>time(),

+ 41 - 14
application/admin/controller/student/Practice.php

@@ -97,20 +97,47 @@ class Practice extends Backend
             $this->error('未找到记录');
         }
         $info = $this->exam_model->where(['user_id'=>$this->auth->id,'exam_collection_id'=>$ids])->find();
-        if(empty($info)){
-            $arr = [
-                'exam_collection_id' => $ids,
-                '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' => $row->exam_collection_name,
-                'exam_collection_type' =>1,
-                'sim_type' => $row->sim_type,
-                'seat_id' => 1,
-                'sim_id' => 12,
-            ];
-            $this->exam_model->save($arr);
+        // if(empty($info)){
+        //     $arr = [
+        //         'exam_collection_id' => $ids,
+        //         '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' => $row->exam_collection_name,
+        //         'exam_collection_type' =>1,
+        //         'sim_type' => $row->sim_type,
+        //         'seat_id' => 1,
+        //         'sim_id' => 12,
+        //     ];
+        //     $this->exam_model->save($arr);
+        // }
+        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('sim')->where('sim_type',$info['sim_type'])->where('seat_id',$this->auth->seat_id)->find();
+            if(empty($sim)){
+                $this->error('未找到模拟器,不可练习');
+            }
+            $this->exam_model->where('exam_id',$info['exam_id'])->update(['seat_id'=>$this->auth->seat_id,'sim_id'=>$sim['sim_id']]);
+            $info['seat_id'] = $this->auth->seat_id;
+            $sim_text = '';
+            if(!empty($sim)){
+                if($sim['sim_state']==1){
+                    $sim_text = '在线';
+                }else if($sim['sim_state']==2){
+                    $sim_text = '模拟器离线';
+                }else if($sim['sim_state']==3){
+                    $sim_text = '网关离线';
+                }else if($sim['sim_state']==4){
+                    $sim_text = '硬件故障异常';
+                }else if($sim['sim_state']==5){
+                    $sim_text = '手动禁用';
+                }
+            }
+//            模拟器状态 0:可用初始化 1:在线 2:模拟器离线 3:网关离线 4:硬件故障异常 5:手动禁用
+            $info['sim_text'] = $sim_text;
         }
         if(!empty($info['starttime']))
         {

+ 0 - 2
application/admin/controller/teacher/Collection.php

@@ -101,7 +101,6 @@ class Collection extends Backend
                     'user_username' => $it['username'],
                     'user_nickname' => $it['nickname'],
                     'user_id' => $it['id'],
-                    'sim_id' => Db::name('sim')->where('sim_type',$params['sim_type'])->value('sim_id'),
                     'user_depart_id' => $it['depart_id'],
                     'create_time'=>date('Y-m-d H:i:s'),
                     'update_time' => date('Y-m-d H:i:s'),
@@ -223,7 +222,6 @@ class Collection extends Backend
                         'user_username' => $it['username'],
                         'user_nickname' => $it['nickname'],
                         'user_id' => $it['id'],
-                        'sim_id' => Db::name('sim')->where('sim_type',$params['sim_type'])->value('sim_id'),
                         'user_depart_id' => $it['depart_id'],
                         'create_time'=>date('Y-m-d H:i:s'),
                         'update_time' => date('Y-m-d H:i:s'),

+ 0 - 1
application/admin/controller/teacher/Practice.php

@@ -105,7 +105,6 @@ class Practice extends Backend
                     'user_username' => $it['username'],
                     'user_nickname' => $it['nickname'],
                     'user_id' => $it['id'],
-                    'sim_id' => Db::name('sim')->where('sim_type',$params['sim_type'])->value('sim_id'),
                     'user_depart_id' => $it['depart_id'],
                     'create_time'=>date('Y-m-d H:i:s'),
                     'update_time' => date('Y-m-d H:i:s'),

+ 5 - 4
application/admin/library/Auth.php

@@ -66,16 +66,17 @@ class Auth extends \fast\Auth
         //学员,追加 对应的IP和 座号
         if(!empty($admin->depart_id)){
             // 获取服务器自己的IP地址
-            $server_ip = gethostbyname('localhost');
+            // $server_ip = gethostbyname('localhost');
+            $server_ip = $_SERVER['REMOTE_ADDR'];//gethostbyname('localhost');
             $admin->server_ip = $server_ip;
             $seat_id = Db::name('seat')->where('seat_bind_ip',$server_ip)->value('seat_id');
             if(!empty($seat_id)){
                 $admin->seat_id = $seat_id;
-                $sim_id = Db::name('sim')->where('seat_id',$seat_id)->value('sim_id');
-                $admin->sim_id = $sim_id??0;
+                //$sim_id = Db::name('sim')->where('seat_id',$seat_id)->value('sim_id');
+                //$admin->sim_id = $sim_id??0;
             }else{
                 $admin->seat_id = 1;
-                $admin->sim_id = 11;
+                //$admin->sim_id = 11;
             }
         }
         Session::set("admin", $admin->toArray());