Exercise.php 29 KB

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