Practice.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. <?php
  2. namespace app\admin\controller\student;
  3. use app\admin\model\department\Department;
  4. use app\admin\model\Fault;
  5. use app\admin\model\Report;
  6. use app\common\controller\Backend;
  7. use app\common\model\Config as ConfigModel;
  8. use think\Db;
  9. use think\Env;
  10. use think\exception\PDOException;
  11. use think\exception\ValidateException;
  12. /**
  13. * sim-练习集合管理
  14. *
  15. * @icon fa fa-circle-o
  16. */
  17. class Practice 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'] = 1;//练习
  34. $this->whereExtend['exam_collection_state'] = 2;
  35. }
  36. /**
  37. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  38. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  39. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  40. */
  41. public function index()
  42. {
  43. $isset = $this->model->alias('z')
  44. ->join('real_exam r','z.exam_collection_id=r.exam_collection_id','left')
  45. ->where('z.exam_collection_type=1 and z.exam_collection_state=2 and r.endtime=0 and r.user_id='.$this->auth->id)->find();
  46. if(empty($isset)){
  47. //提示页面,没有开始的考试
  48. return $this->view->fetch('tishi');
  49. }else{
  50. echo "<script>location.href='/admin/student/practice/into/ids/".$isset['exam_collection_id']."'</script>";
  51. }
  52. die();
  53. //设置过滤方法
  54. $this->request->filter(['strip_tags', 'trim']);
  55. if (false === $this->request->isAjax()) {
  56. return $this->view->fetch();
  57. }
  58. //如果发送的来源是 Selectpage,则转发到 Selectpage
  59. if ($this->request->request('keyField')) {
  60. return $this->selectpage();
  61. }
  62. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  63. $list = $this->model
  64. ->where($where)->where($this->whereExtend)
  65. ->order($sort, $order)
  66. ->paginate($limit);
  67. foreach ($list as $k => $v){
  68. $exam_isset = $this->exam_model->where(['user_id'=>$this->auth->id,'exam_collection_id'=>$v['exam_collection_id'],'exam_collection_type'=>1])->find();
  69. if(isset($exam_isset)){
  70. $v->is_user_examed = 1;
  71. }else{
  72. $v->is_user_examed = 0;
  73. }
  74. }
  75. unset($v);
  76. $result = ['total' => $list->total(), 'rows' => $list->items()];
  77. return json($result);
  78. }
  79. //进入考试
  80. public function into($ids = null)
  81. {
  82. $row = $this->model->get($ids);
  83. if(!$row){
  84. $this->error('未找到记录');
  85. }
  86. $info = $this->exam_model->where(['user_id'=>$this->auth->id,'exam_collection_id'=>$ids])->find();
  87. if(!empty($info)){
  88. if(!empty($this->auth->seat_id) && !empty($info['seat_id']) && $this->auth->seat_id!=$info['seat_id']){
  89. $this->error('已在其他座号有开始的练习,不允许换座号');
  90. }
  91. $sim = Db::name('sim')->where('sim_type',$info['sim_type'])->where('seat_id',$this->auth->seat_id)->find();
  92. if(empty($sim)){
  93. $this->error('未找到模拟器,不可练习');
  94. }
  95. $this->exam_model->where('exam_id',$info['exam_id'])->update(['seat_id'=>$this->auth->seat_id,'sim_id'=>$sim['sim_id']]);
  96. $info['seat_id'] = $this->auth->seat_id;
  97. $sim_text = '';
  98. if(!empty($sim)){
  99. if($sim['sim_state']==1){
  100. $sim_text = '在线';
  101. }else if($sim['sim_state']==2){
  102. $sim_text = '模拟器离线';
  103. }else if($sim['sim_state']==3){
  104. $sim_text = '网关离线';
  105. }else if($sim['sim_state']==4){
  106. $sim_text = '硬件故障异常';
  107. }else if($sim['sim_state']==5){
  108. $sim_text = '手动禁用';
  109. }
  110. }
  111. if($info['sim_type']=='0001'){
  112. $sim_type_text = 'FZD04B';
  113. }else if($info['sim_type']=='0002'){
  114. $sim_type_text = 'FZB006';
  115. }else if($info['sim_type']=='0003'){
  116. $sim_type_text = '防化兵型';
  117. }else{
  118. $sim_type_text = '';
  119. }
  120. // 模拟器状态 0:可用初始化 1:在线 2:模拟器离线 3:网关离线 4:硬件故障异常 5:手动禁用
  121. $info['sim_text'] = $sim_text;
  122. $info['sim_type_text'] = $sim_type_text;
  123. }
  124. if(!empty($info['starttime']))
  125. {
  126. echo "<script>location.href='/admin/student/practice/examing/ids/".$info['exam_id']."'</script>";
  127. die();
  128. }
  129. $this->assignConfig('exam_id', $info['exam_id']);
  130. $this->assignConfig('url_type', config('site.url_type'));
  131. $this->assignConfig('is_fault', Env::get('app.is_fault'));
  132. $this->view->assign('row', $row);
  133. return $this->view->fetch();
  134. }
  135. public function examing($ids = null)
  136. {
  137. $row = $this->exam_model->get($ids);
  138. if(!$row){
  139. $this->error('未找到记录');
  140. }
  141. if ($this->request->isPost()) {
  142. //先请求接口判断,再进行处理
  143. if(Env::get('app.is_fault')){
  144. $url = config('site.url_type').'/sim/real-exam/student/exercise/submit/'.$ids;
  145. // /dev-api/sim/real-exam/student/exam/submit/{examId}
  146. $ret = json_decode(send_get($url),true);
  147. // halt($ret);
  148. if($ret['code']!=200){
  149. $this->error($ret['msg']);
  150. }
  151. }
  152. //计算分数,保存记录
  153. $params = $this->request->post('row/a');
  154. $result = false;
  155. $score = 100;
  156. $fault_one_score = 25;
  157. $fault_two_score = 25;
  158. $fault_three_score = 25;
  159. //故障现象
  160. $xianxian_score = 0;
  161. $xianxian_arr = [];
  162. $xianxian_content = [];
  163. //故障部位
  164. $buwei_score= 0;
  165. $buwei_arr = [];
  166. $buwei_content = [];
  167. //可能原因
  168. $yuanyin_socre= 0;
  169. $yuanyin_arr = [];
  170. $yuanyin_content = [];
  171. //排除方法
  172. $fangfa_score= 0;
  173. $fangfa_arr = [];
  174. $fangfa_content = [];
  175. $other_content = [];
  176. $content = [];
  177. Db::startTrans();
  178. try {
  179. if(!empty($params['other_report'])){
  180. //获取数组
  181. $other_report = json_decode($params['other_report'],true);
  182. if(count($other_report)==1){
  183. $other_report[1] = [
  184. 'xh_id' => 1,
  185. 'xx_id' => '',
  186. 'xx_name' => '',
  187. 'yy_id' => '',
  188. 'yy_name' => '',
  189. 'bw_id' => '',
  190. 'bw_name' => '',
  191. 'pc_id' => '',
  192. 'pc_name' => ''
  193. ];
  194. $other_report[2] = [
  195. 'xh_id' => 2,
  196. 'xx_id' => '',
  197. 'xx_name' => '',
  198. 'yy_id' => '',
  199. 'yy_name' => '',
  200. 'bw_id' => '',
  201. 'bw_name' => '',
  202. 'pc_id' => '',
  203. 'pc_name' => ''
  204. ];
  205. }else if(count($other_report)==2){
  206. $other_report[2] = [
  207. 'xh_id' => 2,
  208. 'xx_id' => '',
  209. 'xx_name' => '',
  210. 'yy_id' => '',
  211. 'yy_name' => '',
  212. 'bw_id' => '',
  213. 'bw_name' => '',
  214. 'pc_id' => '',
  215. 'pc_name' => ''
  216. ];
  217. }
  218. $params['other_report'] = json_encode($other_report);
  219. }
  220. //更新考试结束时间
  221. $row->end_time = date('Y-m-d H:i:s');
  222. $row->endtime = time();
  223. $row->exam_status = 5;
  224. $row->other_report = $params['other_report'];
  225. $result = $row->save();
  226. $info = $this->exam_model->where(['exam_id'=>$ids])->find();
  227. //特殊判断结果 故障部位
  228. // 002型 薄膜开关FPC排线 蜂鸣器出声口 检测剂 干燥管 维护管
  229. // 003型 检测剂 干燥管 维护管
  230. $question_arr = ['0002GZBW0001','0002GZBW0003','0002GZBW0005','0002GZBW0009','0002GZBW0010','0003GZBW0006','0003GZBW0007','0003GZBW0008'];
  231. //更新故障是否正确
  232. $fault_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1])->select();
  233. if(!empty($fault_list)){
  234. foreach ($fault_list as $k =>$t){
  235. $answer_right = 2;
  236. //真实故障id 故障部位在 特殊故障部位里面
  237. if(in_array($t['fault_id'],$question_arr)){
  238. if(substr($t['sim_fault_answer_value'], -1,1)==0){
  239. $answer_right=1;
  240. }
  241. }else{
  242. if(!empty($t['sim_fault_question_value']) && !empty($t['sim_fault_answer_value'])){
  243. if($t['sim_fault_question_value']!=$t['sim_fault_answer_value'] ){
  244. $answer_right=1;
  245. }
  246. }
  247. }
  248. Db::name('real_exam_fault')->where(['ref_id'=>$t['ref_id']])->update(['answer_right'=>$answer_right]);
  249. }
  250. }
  251. //计算得分,故障是否有扣分 扣分制
  252. $fault_right_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1,'answer_right'=>['>',0]])->select();
  253. if(!empty($fault_right_list)){
  254. if($fault_right_list[0]['answer_right']==1){
  255. $fault_one_score = 0;
  256. }
  257. if($fault_right_list[1]['answer_right']==1){
  258. $fault_two_score = 0;
  259. }
  260. if($fault_right_list[2]['answer_right']==1){
  261. $fault_three_score = 0;
  262. }
  263. }
  264. $fault_right_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1])->select();
  265. //根据故障部位,查找故障现象
  266. $fault_arr = [$fault_right_list[0]['fault_id'],$fault_right_list[1]['fault_id'],$fault_right_list[2]['fault_id']];
  267. //根据故障部位查找,匹配的排除方法
  268. $paichu_arr = Report::where(['bw_id'=>['in',$fault_arr],'sim_type'=>$info['sim_type']])->column('pc_id');
  269. // //根据故障部位查找,匹配可能原因
  270. // $yy_arr = Report::where(['bw_id'=>['in',$fault_arr],'sim_type'=>$info['sim_type']])->column('yy_id');
  271. //查找故障现象 数组
  272. $partent_fault_id = Fault::where(['fault_id'=>['in',$fault_arr],'sim_type'=>$info['sim_type']])->column('parent_fault_id');
  273. //根据故障部位查找,匹配可能原因
  274. $yy_arr = Fault::where(['parent_fault_id'=>['in',$partent_fault_id],'sim_type'=>$info['sim_type'],'fault_type'=>2])->column('fault_id');
  275. if(!empty($other_report)){
  276. foreach ($other_report as $k => $v) {
  277. if(!empty($v['xx_id'])){
  278. if(in_array($v['xx_id'],$partent_fault_id)){
  279. //故障现象正确
  280. $kscore = 0;
  281. //故障部位 故障部位错误
  282. $buwei_id= '';
  283. $paichu_id= '';
  284. $yy_id = [];
  285. foreach($fault_arr as $kk1 =>$va1){
  286. $fault_find = Fault::where(['fault_id'=>$va1])->find();
  287. if($fault_find['parent_fault_id']==$v['xx_id']){
  288. $buwei_id = $fault_find['fault_id'];
  289. $paichu_id = $fault_find['ref_type4_fault_id'];
  290. $yy_id = Fault::where(['parent_fault_id'=>$fault_find['parent_fault_id'],'sim_type'=>$info['sim_type'],'fault_type'=>2])->column('fault_id');
  291. }
  292. }
  293. if($v['bw_id']!=$buwei_id){
  294. $buwei_score = 1+$buwei_score;
  295. $kscore = 1+$kscore;
  296. $content[] = [
  297. 'gzxz_id'=>$v['xx_id'],
  298. 'cx_id'=>$v['bw_id'],
  299. 'cx_type'=>'故障部位错写',
  300. 'cx_name'=>Fault::where(['fault_id'=>$v['bw_id']])->value('name'),
  301. ];
  302. }
  303. //故障部位少写
  304. //获取当前的故障部位
  305. if($buwei_id!=$v['bw_id']){
  306. $buwei_score = 1+$buwei_score;
  307. $kscore = 1+$kscore;
  308. $content[] = [
  309. 'gzxz_id'=>$v['xx_id'],
  310. 'cx_id'=>$buwei_id,
  311. 'cx_type'=>'故障部位少写',
  312. 'cx_name'=>Fault::where(['fault_id'=>$buwei_id])->value('name'),
  313. ];
  314. }
  315. //排除方法 错写
  316. if($v['pc_id']!=$paichu_id){
  317. $buwei_score = 1+$buwei_score;
  318. $kscore = 1+$kscore;
  319. $content[] = [
  320. 'gzxz_id'=>$v['xx_id'],
  321. 'cx_id'=>$v['pc_id'],
  322. 'cx_type'=>'排除方法错写',
  323. 'cx_name'=>Fault::where(['fault_id'=>$v['pc_id']])->value('name'),
  324. ];
  325. }
  326. //排放方法 少写
  327. if($paichu_id!=$v['pc_id']){
  328. $fangfa_score = 1+$fangfa_score;
  329. $kscore = 1+$kscore;
  330. $content[] = [
  331. 'gzxz_id'=>$v['xx_id'],
  332. 'cx_id'=>$v['pc_id'],
  333. 'cx_type'=>'排除方法少写',
  334. 'cx_name'=>Fault::where(['fault_id'=>$buwei_id])->value('name'),
  335. ];
  336. }
  337. //可能原因 错写
  338. foreach (explode(',',$v['yy_id']) as $key => $value) {
  339. if(!in_array($value,$yy_id)){
  340. $yuanyin_socre = 1+$yuanyin_socre;
  341. $kscore = 1+$kscore;
  342. $content[] = [
  343. 'gzxz_id'=>$v['xx_id'],
  344. 'cx_id'=>$value,
  345. 'cx_type'=>'可能原因错写',
  346. 'cx_name'=>Fault::where(['fault_id'=>$value])->value('name'),
  347. ];
  348. // echo $v['xx_id']."@@@".$value."@@@".$kscore."<br/>";
  349. }
  350. }
  351. //可能原因 少写
  352. foreach ($yy_id as $key1 => $value1) {
  353. $yy_id_arr = explode(',',$v['yy_id']);
  354. if(!in_array($value1,$yy_id_arr)){
  355. $yuanyin_socre = 1+$yuanyin_socre;
  356. $kscore = 1+$kscore;
  357. $content[] = [
  358. 'gzxz_id'=>$v['xx_id'],
  359. 'cx_id'=>$value1,
  360. 'cx_type'=>'可能原因少写',
  361. 'cx_name'=>Fault::where(['fault_id'=>$value1])->value('name'),
  362. ];
  363. }
  364. }
  365. if($kscore>5){
  366. $kscore = '-5';
  367. }else if($kscore>0){
  368. $kscore = '-'.$kscore;
  369. }else{
  370. $kscore=0;
  371. }
  372. $other_content[$k] = [
  373. 'gzxz_id'=>$v['xx_id'],
  374. 'xh_id' => $k,
  375. 'xx_id' => $v['xx_id'],
  376. 'xx_name' => $v['xx_name'],
  377. 'yy_id' =>$v['yy_id'],
  378. 'yy_name' => $v['yy_name'],
  379. 'bw_id' => $v['bw_id'],
  380. 'bw_name' => $v['bw_name'],
  381. 'pc_id' => $v['pc_id'],
  382. 'pc_name' => $v['pc_name'],
  383. 'cx_type'=>'',
  384. 'cx_name'=>$content,
  385. 'cx_score'=>$kscore,
  386. ];
  387. }else{
  388. $xianxian_score = 5+$xianxian_score;
  389. $other_content[$k] = [
  390. 'gzxz_id'=>$v['xx_id'],
  391. 'xh_id' => $k,
  392. 'xx_id' => $v['xx_id'],
  393. 'xx_name' => $v['xx_name'],
  394. 'yy_id' =>$v['yy_id'],
  395. 'yy_name' => $v['yy_name'],
  396. 'bw_id' => $v['bw_id'],
  397. 'bw_name' => $v['bw_name'],
  398. 'pc_id' => $v['pc_id'],
  399. 'pc_name' => $v['pc_name'],
  400. 'cx_type'=>'故障现象错写',
  401. 'cx_name'=>Fault::where(['fault_id'=>$v['xx_id']])->value('name'),
  402. 'cx_score'=>-5,
  403. ];
  404. }
  405. }else{
  406. $xianxian_score = 5+$xianxian_score;
  407. $other_content[$k] = [
  408. 'gzxz_id'=>'',
  409. 'xh_id' => $k,
  410. 'xx_id' => '',
  411. 'xx_name' => '',
  412. 'yy_id' => '',
  413. 'yy_name' => '',
  414. 'bw_id' => '',
  415. 'bw_name' => '',
  416. 'pc_id' => '',
  417. 'pc_name' => '',
  418. 'cx_type'=>'未作答',
  419. 'cx_name'=>'',
  420. 'cx_score'=>-5,
  421. ];
  422. }
  423. }
  424. }else{
  425. foreach ($partent_fault_id as $key => $em){
  426. $xianxian_score = 5+$xianxian_score;
  427. $other_content[] = [
  428. 'gzxz_id'=>$em,
  429. 'xh_id' => $key,
  430. 'xx_id' => '',
  431. 'xx_name' => '',
  432. 'yy_id' => '',
  433. 'yy_name' => '',
  434. 'bw_id' => '',
  435. 'bw_name' => '',
  436. 'pc_id' => '',
  437. 'pc_name' => '',
  438. 'cx_type'=>'未作答',
  439. 'cx_name'=>'',
  440. 'cx_score'=>-5,
  441. ];
  442. }
  443. unset($em);
  444. }
  445. // echo "故障现象得分:".$xianxian_score."<br/>";
  446. // echo "故障部位得分:".$buwei_score."<br/>";
  447. // echo "排除方法得分:".$fangfa_score."<br/>";
  448. // echo "可能原因得分:".$yuanyin_socre."<br/>";
  449. // die();
  450. $weixiu_score = $xianxian_score+$yuanyin_socre+$buwei_score+$fangfa_score;
  451. if($weixiu_score>15){
  452. $weixiu_score = 15;
  453. }
  454. //是否超时
  455. //$info['countdown_time'] 开始时间+考试时长+10分倒计时
  456. $countdown_time= strtotime(date('Y-m-d H:i:s', strtotime('-10 minute',$info['countdown_time'])));
  457. $overtime_fen = ceil((time()-$countdown_time) / 60);
  458. if($overtime_fen>=10){
  459. $overtime_score = 10;
  460. }else if($overtime_fen>0 && $overtime_fen<10){
  461. $overtime_score = $overtime_fen ;
  462. }else{
  463. $overtime_score =0;
  464. }
  465. $fault_score = $score-$fault_one_score-$fault_two_score-$fault_three_score-$weixiu_score-$overtime_score;
  466. //更新考试结果表
  467. $params['exam_id'] = $ids;
  468. $params['total'] = $fault_score;//得分;
  469. $params['fault_one_score'] = $fault_one_score;//得分;
  470. $params['fault_two_score'] = $fault_two_score;//得分;
  471. $params['fault_three_score'] = $fault_three_score;//得分;
  472. $params['xianxian_score'] = $xianxian_score;//得分;
  473. $params['xianxian_content'] = json_encode($xianxian_content);//错题;
  474. $params['yuanyin_socre'] = $yuanyin_socre;//得分;
  475. $params['yuanyin_content'] = json_encode($yuanyin_content);//错题;
  476. $params['buwei_score'] = $buwei_score;//得分;
  477. $params['buwei_content'] = json_encode($buwei_content);//错题;
  478. $params['fangfa_score'] = $fangfa_score;//得分;
  479. $params['fangfa_content'] = json_encode($fangfa_content);//错题;
  480. $params['other_jielun'] = json_encode($other_content);//每个答题的得分
  481. $params['overtime_score'] = $overtime_score;//得分;
  482. Db::name('real_exam_score')->insert($params);
  483. $this->exam_model->where(['exam_id'=>$ids])->update(['total_score'=>$fault_score]);
  484. Db::commit();
  485. } catch (ValidateException|PDOException|Exception $e) {
  486. Db::rollback();
  487. $this->error($e->getMessage());
  488. }
  489. if ($result === false) {
  490. $this->error(__('No rows were inserted'));
  491. }
  492. $this->success('交卷成功','/admin/student/practice/analysis/ids/'.$row['exam_id']);
  493. }
  494. if(empty($row->starttime)){
  495. $row->start_time = date('Y-m-d H:i:s');
  496. $row->starttime = time();
  497. $row->exam_status = 4;
  498. $row->save();
  499. }
  500. $isloading =1;
  501. if(empty($row->other_replace)){
  502. $isloading = 0;
  503. $row->other_replace = '[{"fault_id":"","request_status":"0"}]';
  504. }
  505. $row->other_report_text = !empty($row->other_report) ? json_decode($row->other_report,true) : [];
  506. //还未开始练习
  507. $row->limit_duration = $this->model->where(['exam_collection_id'=>$row['exam_collection_id']])->value('limit_duration');
  508. if(empty($row->starttime)){
  509. $timer = 60*$row->limit_duration;
  510. }else{
  511. $timer = $row->limit_duration*60 - abs(time() - $row->starttime);
  512. }
  513. if(empty($row->countdown_time)){
  514. $duration = 10+$row->limit_duration;
  515. $this->exam_model->where('exam_id',$ids)->update(['countdown_time'=>strtotime(date('Y-m-d H:i:s', strtotime('+'.$duration.' minute',$row->starttime)))]);
  516. }
  517. $departmentdata = [];
  518. $departmentdata = Fault::where(['replace_part'=>1,'sim_type'=>$row->sim_type])->order('fault_id asc')->select();
  519. $this->view->assign('departmentdata', $departmentdata);
  520. //故障现象
  521. $xianxiang = Fault::where(['fault_type'=>1,'sim_type'=>$row->sim_type])->select();
  522. $this->view->assign('xianxiang', $xianxiang);
  523. $row->replace_list =Db::name('real_exam_comp_request')->where(['exam_id'=>$ids])->select();
  524. $this->assignConfig('ids',$ids);
  525. $this->assignConfig('timer',$timer);
  526. $this->assignConfig('isloading',$isloading);
  527. $this->view->assign('row', $row);
  528. return $this->view->fetch();
  529. }
  530. public function analysis($ids = null)
  531. {
  532. if ($this->request->isPost()) {
  533. $params = $this->request->post('row/a');
  534. //计算总分到学员考试表
  535. $this->success('操作成功','/admin/student/practice/index');
  536. }
  537. $row = Db::name('real_exam_score')->where('exam_id', $ids)->find();
  538. if (!$row) {
  539. $this->error(__('No Results were found'));
  540. }
  541. $rows = $this->exam_model->get($ids);
  542. $row['seat_id'] = $rows->seat_id;
  543. $row['user_nickname'] = $rows->user_nickname;
  544. $row['user_username'] = $rows->user_username;
  545. $row['user_depart_id'] = $rows->user_depart_id;
  546. $row['user_depart_name'] = Department::where('id',$rows->user_depart_id)->value('name');
  547. $row['start_time'] = $rows->start_time;
  548. $row['end_time'] = $rows->end_time;
  549. $fault_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1])->select();
  550. $row['fault_name_one'] = !empty($fault_list[0]['fault_id']) ? Fault::where('fault_id',$fault_list[0]['fault_id'])->value('name'):'';
  551. $row['fault_name_two'] = !empty($fault_list[1]['fault_id']) ? Fault::where('fault_id',$fault_list[1]['fault_id'])->value('name'):'';
  552. $row['fault_name_three'] = !empty($fault_list[2]['fault_id']) ? Fault::where('fault_id',$fault_list[2]['fault_id'])->value('name'):'';
  553. $row['fault_score'] = 75-$row['fault_one_score']-$row['fault_two_score']-$row['fault_three_score'];
  554. $row['weixiu_score'] = 10-$row['overtime_score']??0;
  555. $other_jielun = !empty($row['other_jielun']) ? json_decode($row['other_jielun'],true):[];
  556. $koufen = 0;
  557. foreach ($other_jielun as $key => $value) {
  558. if(!empty($value['cx_score'])){
  559. $koufen = $koufen+abs($value['cx_score']);
  560. }
  561. }
  562. $report_score = 15-$koufen;
  563. $row['report_score'] = $report_score>0?$report_score:0;
  564. $total = $row['fault_score']+$row['report_score']+$row['weixiu_score'];
  565. Db::name('real_exam_score')->where('exam_id', $ids)->update(['total'=>$total]);
  566. Db::name('real_exam')->where('exam_id', $ids)->update(['total_score'=>$total]);
  567. $row['total'] = $total;
  568. $this->view->assign('other_jielun', $other_jielun);
  569. $diffInSeconds = $rows['endtime'] - $rows['starttime']; // 两个时间戳之间的差异(秒)
  570. $minutes = floor($diffInSeconds / 60); // 计算分钟数
  571. $seconds = $diffInSeconds % 60; // 计算剩余的秒数
  572. $row['shijian'] = $minutes.'分'.$seconds.'秒';
  573. $this->view->assign('row', $row);
  574. return $this->view->fetch();
  575. }
  576. }