Exercise.php 29 KB

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