Exercise.php 31 KB

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