Collection.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. <?php
  2. namespace app\admin\controller\student;
  3. use app\common\controller\Backend;
  4. use app\common\model\Config as ConfigModel;
  5. use app\admin\model\Report;
  6. use app\admin\model\Fault;
  7. use think\exception\DbException;
  8. use think\exception\PDOException;
  9. use think\exception\ValidateException;
  10. use think\response\Json;
  11. use think\Db;
  12. /**
  13. * sim-考试集合管理
  14. *
  15. * @icon fa fa-circle-o
  16. */
  17. class Collection extends Backend
  18. {
  19. /**
  20. * Collection模型对象
  21. * @var \app\admin\model\teacher\Collection
  22. */
  23. protected $model = null;
  24. protected $exam_model = null;
  25. protected $whereExtend = null;
  26. public function _initialize()
  27. {
  28. parent::_initialize();
  29. $this->model = new \app\admin\model\teacher\Collection;
  30. $this->exam_model = new \app\admin\model\teacher\Exams;
  31. $this->assignConfig('sim_sim_type', ConfigModel::getSimTypeList());
  32. $this->assignConfig('sim_question_setting_method', ConfigModel::getSimQuestionList());
  33. $this->whereExtend['exam_collection_type'] = 3;
  34. $this->whereExtend['exam_collection_state'] = 2;
  35. $this->assignConfig('sim_sim_type', ConfigModel::getSimTypeList());
  36. $groupIds = $this->auth->getGroupIds();
  37. //学员查看自己区队的考试集合
  38. if(in_array(8, $groupIds)){
  39. $departid = $this->auth->depart_id;
  40. $this->whereExtend[] = ['exp',Db::raw("FIND_IN_SET($departid,depart_ids)")];
  41. }
  42. }
  43. /**
  44. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  45. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  46. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  47. */
  48. /**
  49. * 查看
  50. *
  51. * @return string|Json
  52. * @throws \think\Exception
  53. * @throws DbException
  54. */
  55. public function index()
  56. {
  57. $isset = $this->model->alias('z')
  58. ->join('real_exam r','z.exam_collection_id=r.exam_collection_id','left')
  59. ->where('z.exam_collection_type=3 and z.exam_collection_state=2 and r.endtime=0 and r.user_id='.$this->auth->id)->find();
  60. if(empty($isset)){
  61. //提示页面,没有开始的考试
  62. return $this->view->fetch('tishi');
  63. }else{
  64. //// $this->redirect('/ZQOtIMLKud.php/student/collection/examing/ids/'.$isset['exam_id'].'?ref=addtabs');
  65. // echo "<script>location.href='/ZQOtIMLKud.php/student/collection/examing/ids/".$isset['exam_id']."';</script>";
  66. // //$this->redirect('/hotelmanage/room/displayindex/ids/1');
  67. // exit();
  68. echo "<script>location.href='/ZQOtIMLKud.php/student/collection/into/ids/".$isset['exam_collection_id']."'</script>";
  69. }
  70. die();
  71. //设置过滤方法
  72. $this->request->filter(['strip_tags', 'trim']);
  73. if (false === $this->request->isAjax()) {
  74. return $this->view->fetch();
  75. }
  76. //如果发送的来源是 Selectpage,则转发到 Selectpage
  77. if ($this->request->request('keyField')) {
  78. return $this->selectpage();
  79. }
  80. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  81. $list = $this->model
  82. ->where($where)->where($this->whereExtend)
  83. ->order($sort, $order)
  84. ->paginate($limit);
  85. foreach ($list as $k => $v){
  86. $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();
  87. if(isset($exam_isset)){
  88. $v->is_user_examed = 1;
  89. }else{
  90. $v->is_user_examed = 0;
  91. }
  92. }
  93. unset($v);
  94. $result = ['total' => $list->total(), 'rows' => $list->items()];
  95. return json($result);
  96. }
  97. //进入考试
  98. public function into($ids = null)
  99. {
  100. $row = $this->model->get($ids);
  101. if(!$row){
  102. $this->error('未找到记录');
  103. }
  104. //如果考试时间结束,也不可进入考试,超时未进入考试的学员
  105. // $duration = 10+$row->limit_duration;
  106. // $futureTimestamp = strtotime("+$duration minutes", $row->starttime);
  107. // if(time()>$futureTimestamp){
  108. // return $this->view->fetch('tishi');
  109. // }
  110. $info = $this->exam_model->where(['user_id'=>$this->auth->id,'exam_collection_id'=>$ids,'exam_collection_type'=>3,'endtime'=>0])->find();
  111. if(!empty($info)){
  112. $this->exam_model->where('exam_id',$info['exam_id'])->update(['seat_id'=>$this->auth->seat_id,'sim_id'=>$this->auth->sim_id]);
  113. $info['seat_id'] = $this->auth->seat_id;
  114. $sim = Db::name('sim')->where('seat_id',$this->auth->seat_id)->find();
  115. $sim_text = '';
  116. if(!empty($sim)){
  117. if($sim['sim_state']==1){
  118. $sim_text = '在线';
  119. }else if($sim['sim_state']==2){
  120. $sim_text = '模拟器离线';
  121. }else if($sim['sim_state']==3){
  122. $sim_text = '网关离线';
  123. }else if($sim['sim_state']==4){
  124. $sim_text = '硬件故障异常';
  125. }else if($sim['sim_state']==5){
  126. $sim_text = '手动禁用';
  127. }
  128. }
  129. // 模拟器状态 0:可用初始化 1:在线 2:模拟器离线 3:网关离线 4:硬件故障异常 5:手动禁用
  130. $info['sim_text'] = $sim_text;
  131. }
  132. if(!empty($info['starttime']))
  133. {
  134. echo "<script>location.href='/ZQOtIMLKud.php/student/collection/examing/ids/".$info['exam_id']."'</script>";
  135. die();
  136. }
  137. if ($this->request->isPost()) {
  138. // $exam_collection_id = $this->request->post('exam_collection_id');
  139. // if(empty($info->starttime)){
  140. // $info->start_time = date('Y-m-d H:i:s');
  141. // $info->starttime = time();
  142. // }
  143. // $info->exam_status = 4;
  144. // $info->save();
  145. // $this->success('开始成功','/ZQOtIMLKud.php/student/collection/examing/ids/'.$info['exam_id']);
  146. }
  147. $this->view->assign('info', $info);
  148. $this->view->assign('row', $row);
  149. $this->assignConfig('exam_id', $info['exam_id']);
  150. $this->assignConfig('url_type', config('site.url_type'));
  151. return $this->view->fetch();
  152. }
  153. public function examing($ids = null)
  154. {
  155. $row = $this->exam_model->get($ids);
  156. if(!$row){
  157. $this->error('未找到记录');
  158. }
  159. if ($this->request->isPost()) {
  160. //先请求接口判断,再进行处理
  161. $url = config('site.url_type').'/sim/real-exam-collection/teacher/exam/open/'.$ids;
  162. $ret = json_decode(send_get($url),true);
  163. if($ret['code']!=200){
  164. $this->error($ret['msg']);
  165. }
  166. //计算分数,保存记录
  167. $params = $this->request->post('row/a');
  168. $result = false;
  169. $score = 100;
  170. $fault_one_score = 25;
  171. $fault_two_score = 25;
  172. $fault_three_score = 25;
  173. $xianxian_score = 0;
  174. $yuanyin_socre= 0;
  175. $buwei_score= 0;
  176. $fangfa_score= 0;
  177. $xianxian_arr = [];
  178. $yuanyin_arr = [];
  179. $buwei_arr = [];
  180. $fangfa_arr = [];
  181. $jielun_score = 0;
  182. Db::startTrans();
  183. try {
  184. //更新考试结束时间
  185. $row->end_time = date('Y-m-d H:i:s');
  186. $row->endtime = time();
  187. $row->exam_status = 5;
  188. $row->other_report = $params['other_report'];
  189. $result = $row->save();
  190. $info = $this->exam_model->where(['exam_id'=>$ids])->find();
  191. //更新故障是否正确
  192. $fault_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1])->select();
  193. if(!empty($fault_list)){
  194. foreach ($fault_list as $k =>$t){
  195. $answer_right = 0;
  196. if(!empty($t['sim_fault_question_value']) && !empty($t['sim_fault_answer_value'])){
  197. if($t['sim_fault_question_value']==$t['sim_fault_answer_value']){
  198. $answer_right=1;
  199. }else{
  200. $answer_right=2;
  201. }
  202. }
  203. Db::name('real_exam_fault')->where(['ref_id'=>$t['ref_id']])->update(['answer_right'=>$answer_right]);
  204. }
  205. }
  206. //计算得分,故障是否有扣分 扣分制
  207. $fault_right_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1,'answer_right'=>['>',0]])->select();
  208. if(!empty($fault_right_list)){
  209. if($fault_right_list[0]['answer_right']==1){
  210. $fault_one_score = 0;
  211. }
  212. if($fault_right_list[1]['answer_right']==1){
  213. $fault_two_score = 0;
  214. }
  215. if($fault_right_list[2]['answer_right']==1){
  216. $fault_three_score = 0;
  217. }
  218. //根据故障部位,查找故障现象
  219. $fault_arr = [$fault_right_list[0]['fault_id'],$fault_right_list[1]['fault_id'],$fault_right_list[2]['fault_id']];
  220. $partent_fault_id = Fault::where(['fault_id'=>['in',$fault_arr]])->column('parent_fault_id');
  221. //故障保存的是部位,需要查找故障现象
  222. $other_report = json_decode($params['other_report'],true);
  223. if(count($other_report)<3){
  224. $xianxian_score = 5;
  225. }else{
  226. foreach ($other_report as $key => $em){
  227. //故障现象
  228. if(!in_array($em['xx_id'],$partent_fault_id)){
  229. $xianxian_score = 5+$xianxian_score;
  230. $xianxian_arr[] = $em['xx_id'];
  231. }
  232. // echo $em['yy_id']."<br>";
  233. //故障部位
  234. if(!empty($em['bw_id'])){
  235. $report_xx_id = Report::where(['bw_id'=>['in',$em['bw_id']]])->column('xx_id');
  236. if(!in_array($em['xx_id'],$report_xx_id)){ //现象不对,直接扣分
  237. $buwei_score = 1+$buwei_score;
  238. $buwei_arr[] = $em['bw_id'];
  239. echo "这里是假1的部位扣了+1分<br/>";
  240. }else{
  241. //现象正确,判断是不是正确的选项
  242. foreach (explode(',',$em['bw_id']) as $s => $bs){
  243. if(!in_array($bs,$fault_arr)){
  244. $buwei_score = 1+$buwei_score;
  245. $buwei_arr[] = $bs;
  246. echo "这里是假2的部位扣了+1分<br/>";
  247. }
  248. }
  249. }
  250. // $report = Report::where('bw_id',$em['bw_id'])->find();
  251. // if(empty($report) || $report['bw_type']==30){
  252. // $buwei_score = 1+$buwei_score;
  253. //// array_push($buwei_arr,$em['bw_id']);
  254. // $buwei_arr[] = $em['bw_id'];
  255. //// echo "这里是假的部位扣了+1分<br/>";
  256. // }
  257. // if(!empty($em['yy_id']) && !empty($report)){
  258. // if($report['bw_type']!=3 || $report['yy_id']!=$em['yy_id'] ){
  259. // $buwei_score = 1+$buwei_score;
  260. // echo "这里错误扣了+1分<br/>";
  261. // }
  262. // }
  263. }else{
  264. //部位为空 +1
  265. $buwei_score = 1+ $buwei_score;
  266. // $buwei_arr[] = '';
  267. // echo "这里为空扣了+1分<br/>";
  268. }
  269. //可能原因
  270. if(!empty($em['yy_id'])){
  271. $report_bw_id = Report::where(['yy_id'=>['in',$em['yy_id']]])->column('bw_id');
  272. if(!in_array($em['bw_id'],$report_bw_id)){ //现象不对,直接扣分
  273. $yuanyin_socre = 1+$yuanyin_socre;
  274. $yuanyin_arr[] = $em['yy_id'];
  275. }else{
  276. }
  277. // $report = Report::where('yy_id',$em['yy_id'])->find();
  278. // if(empty($report) || $report['bw_type']==30){
  279. // $yuanyin_socre = 1+ $yuanyin_socre;
  280. //// echo "这里是假的部位扣了+1分<br/>";
  281. //// array_push($yuanyin_arr,$em['yy_id']);
  282. // $yuanyin_arr[] = $em['yy_id'];
  283. // }
  284. // if(!empty($em['yy_id']) && !empty($report)){
  285. // if($report['bw_id']!=$em['bw_id'] ){
  286. // $yuanyin_socre = 1+$yuanyin_socre;
  287. //// echo "这里错误扣了+1分<br/>";
  288. //// array_push($yuanyin_arr,$em['yy_id']);
  289. // $yuanyin_arr[] = $em['yy_id'];
  290. // }
  291. // }
  292. }else{
  293. //部位为空 +1
  294. $yuanyin_socre = 1+$yuanyin_socre;
  295. // array_push($yuanyin_arr,'');
  296. // echo "这里为空扣了+1分<br/>";
  297. // $yuanyin_arr[] = '';
  298. }
  299. //排除方法
  300. if(!empty($em['pc_id'])){
  301. $report_pc_id = Report::where(['pc_id'=>['in',$em['pc_id']]])->column('bw_id');
  302. if(!in_array($em['bw_id'],$report_pc_id)){ //现象不对,直接扣分
  303. $fangfa_score = 1+$fangfa_score;
  304. $fangfa_arr[] = $em['pc_id'];
  305. }else{
  306. }
  307. // $report = Report::where('pc_id',$em['pc_id'])->find();
  308. // if(empty($report) || $report['bw_type']==30){
  309. // $fangfa_score = 1+ $fangfa_score;
  310. //
  311. // $fangfa_arr[] = $em['pc_id'];
  312. //// array_push($fangfa_arr,$em['pc_id']);
  313. //// echo "这里是假的方法扣了+1分<br/>";
  314. // }
  315. // if(!empty($em['pc_id']) && !empty($report)){
  316. // if($report['bw_id']!=$em['bw_id'] ){
  317. // $fangfa_score = 1+$fangfa_score;
  318. // $fangfa_arr[] = $em['pc_id'];
  319. //// array_push($fangfa_arr,$em['pc_id']);
  320. //// echo "这里错误扣了+1分<br/>";
  321. // }
  322. // }
  323. }else{
  324. $fangfa_score = 1+$fangfa_score;
  325. // array_push($yuanyin_arr,'');
  326. // $fangfa_arr[] = '';
  327. // echo "这里为空扣了+1分<br/>";
  328. }
  329. }
  330. // echo '部位:'.$buwei_score.'<br/>';
  331. // echo '原因:'.$yuanyin_socre.'<br/>';
  332. // echo '方法:'.$fangfa_score.'<br/>';
  333. }
  334. }
  335. // echo "<pre>";
  336. // print_r($buwei_arr);
  337. // echo '原因:'.$yuanyin_socre.'<br/>';
  338. // echo '部位:'.$buwei_score.'<br/>';
  339. // echo '现象:'.$xianxian_score;
  340. // die();
  341. $weixiu_score = $xianxian_score+$yuanyin_socre+$buwei_score+$fangfa_score;
  342. if($weixiu_score>15){
  343. $weixiu_score = 15;
  344. }
  345. // $xianxian_score = rand(1,3);
  346. // $yuanyin_socre= rand(1,3);
  347. // $buwei_score= rand(1,3);
  348. // $fangfa_score= rand(1,3);
  349. // if(empty($params['other_jielun'])){
  350. // $jielun_score = rand(1,3);
  351. // }
  352. //是否超时
  353. $overtime_fen = intval((time()-$info['endtime']) / 60);
  354. if($overtime_fen>=10){
  355. $overtime_score = 10;
  356. }else if($overtime_fen>0 && $overtime_fen<10){
  357. $overtime_score = $overtime_fen ;
  358. }else{
  359. $overtime_score =0;
  360. }
  361. $fault_score = $score-$fault_one_score-$fault_two_score-$fault_three_score-$weixiu_score-$overtime_score;
  362. //更新考试结果表
  363. $params['exam_id'] = $ids;
  364. $params['total'] = $fault_score;//得分;
  365. $params['fault_one_score'] = $fault_one_score;//得分;
  366. $params['fault_two_score'] = $fault_two_score;//得分;
  367. $params['fault_three_score'] = $fault_three_score;//得分;
  368. $params['xianxian_score'] = $xianxian_score;//得分;
  369. $params['xianxian_content'] = !empty($xianxian_arr) ? json_encode($xianxian_arr):'';//错题;
  370. $params['yuanyin_socre'] = $yuanyin_socre;//得分;
  371. $params['yuanyin_content'] = !empty($yuanyin_arr) ? json_encode($yuanyin_arr) : '';//错题;
  372. $params['buwei_score'] = $buwei_score;//得分;
  373. $params['buwei_content'] = !empty($buwei_arr) ? json_encode($buwei_arr) :'';//错题;
  374. $params['fangfa_score'] = $fangfa_score;//得分;
  375. $params['fangfa_content'] = !empty($fangfa_arr) ? json_encode($fangfa_arr):'';//错题;
  376. // $params['jielun_score'] = $jielun_score;//得分;
  377. $params['overtime_score'] = $overtime_score;//得分;
  378. Db::name('real_exam_score')->insert($params);
  379. $this->exam_model->where(['exam_id'=>$ids])->update(['total_score'=>$fault_score]);
  380. Db::commit();
  381. } catch (ValidateException|PDOException|Exception $e) {
  382. Db::rollback();
  383. $this->error($e->getMessage());
  384. }
  385. if ($result === false) {
  386. $this->error(__('No rows were inserted'));
  387. }
  388. $this->success('交卷成功,待老师确认成绩','/ZQOtIMLKud.php/student/exam/index');
  389. }
  390. if(empty($row->starttime)){
  391. $row->start_time = date('Y-m-d H:i:s');
  392. $row->starttime = time();
  393. $row->exam_status = 4;
  394. $row->save();
  395. }
  396. $isloading =1;
  397. if(empty($row->other_replace)){
  398. $isloading = 0;
  399. $row->other_replace = '[{"fault_id":"","request_status":"0"}]';
  400. }
  401. if(empty($row->other_report)){
  402. $row->other_report = '[{"xx_id":"","yy_id":"","bw_id":"","pc_id":""}]';
  403. }
  404. //还未开始考试
  405. $row->limit_duration = $this->model->where(['exam_collection_id'=>$row['exam_collection_id']])->value('limit_duration');
  406. if(empty($row->starttime)){
  407. $timer = 60*$row->limit_duration;
  408. }else{
  409. $timer = $row->limit_duration*60 - abs(time() - $row->starttime);
  410. }
  411. $row->replace_list =Db::name('real_exam_comp_request')->where(['exam_id'=>$ids])->select();
  412. $this->assignConfig('ids',$ids);
  413. $this->assignConfig('timer',$timer);
  414. $this->assignConfig('isloading',$isloading);
  415. $this->view->assign('row', $row);
  416. $departmentdata = [];
  417. $departmentdata = Fault::where(['replace_part'=>1,'sim_type'=>$row->sim_type])->order('fault_id asc')->select();
  418. //更换件数据
  419. $this->view->assign('departmentdata', $departmentdata);
  420. //故障现象
  421. $xianxiang = Fault::where(['fault_type'=>1,'sim_type'=>$row->sim_type])->select();
  422. $this->view->assign('xianxiang', $xianxiang);
  423. //可能原因
  424. $yuanyin = Fault::where(['fault_type'=>2,'sim_type'=>$row->sim_type])->select();
  425. $this->view->assign('yuanyin', $yuanyin);
  426. //故障部位
  427. $buwei = Fault::where(['fault_type'=>3,'sim_type'=>$row->sim_type])->select();
  428. $this->view->assign('buwei', $buwei);
  429. //排除方法
  430. $paichu = Fault::where(['fault_type'=>4,'sim_type'=>$row->sim_type])->select();
  431. $this->view->assign('paichu', $paichu);
  432. return $this->view->fetch();
  433. }
  434. public function replace($ids = null)
  435. {
  436. if ($this->request->isPost()) {
  437. $params = $this->request->post('other_replace','');
  438. $other_report = $this->request->post('other_report','');
  439. $param = json_decode($params,true);
  440. if(!empty($param)){
  441. foreach ($param as $key=>$item){
  442. $isreplace = Db::name('real_exam_comp_request')->where(['exam_id'=>$ids,'fault_id'=>$item['fault_id']])->find();
  443. if(empty($isreplace)){
  444. $add = [
  445. 'exam_id'=>$ids,
  446. 'fault_id'=>$item['fault_id'],
  447. 'request_status'=>1,
  448. 'fault_name'=>Db::name('fault')->where('fault_id',$item['fault_id'])->value('replace_name'),
  449. 'create_by_user_id'=>$this->auth->id,
  450. 'create_by'=>$this->auth->nickname,
  451. 'createtime'=>time(),
  452. 'updatetime'=>time(),
  453. 'create_time'=>date('Y-m-d H:i:s'),
  454. 'update_time'=>date('Y-m-d H:i:s'),
  455. ];
  456. Db::name('real_exam_comp_request')->insert($add);
  457. $status = 1;
  458. }else{
  459. $status = $isreplace['request_status'];
  460. }
  461. $faultid_arr[] = [
  462. 'fault_id'=>$item['fault_id'],
  463. 'request_status'=>$status,
  464. ];
  465. }
  466. unset($item);
  467. $row = $this->exam_model->get($ids);
  468. $row-> other_replace = json_encode($faultid_arr);
  469. $row-> other_report = $other_report;
  470. $result = $row->save();
  471. }
  472. $this->success('申请成功,待老师审批');
  473. }
  474. }
  475. public function analysis($ids = null)
  476. {
  477. $row = $this->exam_model->get($ids);
  478. if(!$row){
  479. $this->error('未找到记录');
  480. }
  481. if ($this->request->isPost()) {
  482. $params = $this->request->post('row/a');
  483. //计算总分到学员考试表
  484. $this->success('操作成功','/ZQOtIMLKud.php/student/collection/index');
  485. }
  486. return $this->view->fetch();
  487. }
  488. }