Exercise.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  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('row/a');
  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,7];//array_rand($fault_list, 3);
  86. $fault_key1 = rand(0, 1);
  87. $fault_key2 = rand(2, 3);
  88. $fault_key3 = rand(4, 5);
  89. $fault_key = [$fault_key1,$fault_key2,$fault_key3];
  90. $flag = 0;
  91. if(!empty($fault_key) && in_array($key,$fault_key)){
  92. $flag = 1;
  93. }
  94. $add= [
  95. 'exam_id'=>$examid,
  96. 'fault_id'=>$item1['fault_id'],
  97. 'ref_type'=>2,
  98. 'flag'=>$flag,
  99. 'ref_state'=>0,
  100. 'createtime'=>time(),
  101. 'updatetime'=>time(),
  102. 'create_time'=>date('Y-m-d H:i:s'),
  103. 'update_time'=>date('Y-m-d H:i:s'),
  104. ];
  105. Db::name('real_exam_fault')->insert($add);
  106. }
  107. $count = $examid;
  108. Db::commit();
  109. } catch (PDOException|Exception $e) {
  110. Db::rollback();
  111. $this->error($e->getMessage());
  112. }
  113. if ($count) {
  114. $this->success('开始成功','/admin/student/exercise/examing/ids/'.$count);
  115. }
  116. $this->error(__('No rows were updated'));
  117. }
  118. }
  119. public function examing($ids = null)
  120. {
  121. $row = $this->exam_model->get($ids);
  122. if(!$row){
  123. $this->error('未找到记录');
  124. }
  125. if ($this->request->isPost()) {
  126. //先请求接口判断,再进行处理
  127. if(Env::get('app.is_fault')){
  128. $url = config('site.url_type').'/sim/real-exam/student/exam/submit/'.$ids;
  129. // /dev-api/sim/real-exam/student/exam/submit/{examId}
  130. $ret = json_decode(send_get($url),true);
  131. // halt($ret);
  132. if($ret['code']!=200){
  133. $this->error($ret['msg']);
  134. }
  135. }
  136. //计算分数,保存记录
  137. $params = $this->request->post('row/a');
  138. $result = false;
  139. $score = 100;
  140. $fault_one_score = 25;
  141. $fault_two_score = 25;
  142. $fault_three_score = 25;
  143. //故障现象
  144. $xianxian_score = 0;
  145. $xianxian_arr = [];
  146. $xianxian_content = [];
  147. //故障部位
  148. $buwei_score= 0;
  149. $buwei_arr = [];
  150. $buwei_content = [];
  151. //可能原因
  152. $yuanyin_socre= 0;
  153. $yuanyin_arr = [];
  154. $yuanyin_content = [];
  155. //排除方法
  156. $fangfa_score= 0;
  157. $fangfa_arr = [];
  158. $fangfa_content = [];
  159. Db::startTrans();
  160. try {
  161. //更新考试结束时间
  162. $row->end_time = date('Y-m-d H:i:s');
  163. $row->endtime = time();
  164. $row->exam_status = 5;
  165. $row->other_report = $params['other_report'];
  166. $result = $row->save();
  167. $info = $this->exam_model->where(['exam_id'=>$ids])->find();
  168. //更新故障是否正确
  169. $fault_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1])->select();
  170. if(!empty($fault_list)){
  171. foreach ($fault_list as $k =>$t){
  172. $answer_right = 2;
  173. if(!empty($t['sim_fault_question_value']) && !empty($t['sim_fault_answer_value'])){
  174. if($t['sim_fault_question_value']!=$t['sim_fault_answer_value'] ){
  175. //真实故障id 0002GZBW0001 薄膜开关FPC排线
  176. if($t['sim_fault_answer_value']=='00000000' && $t['fault_id'] !='0002GZBW0001'){
  177. $answer_right=2;
  178. }
  179. $answer_right=1;
  180. }
  181. }
  182. Db::name('real_exam_fault')->where(['ref_id'=>$t['ref_id']])->update(['answer_right'=>$answer_right]);
  183. }
  184. }
  185. //计算得分,故障是否有扣分 扣分制
  186. $fault_right_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1,'answer_right'=>['>',0]])->select();
  187. if(!empty($fault_right_list)){
  188. if($fault_right_list[0]['answer_right']==1){
  189. $fault_one_score = 0;
  190. }
  191. if($fault_right_list[1]['answer_right']==1){
  192. $fault_two_score = 0;
  193. }
  194. if($fault_right_list[2]['answer_right']==1){
  195. $fault_three_score = 0;
  196. }
  197. }
  198. $fault_right_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1])->select();
  199. //根据故障部位,查找故障现象
  200. $fault_arr = [$fault_right_list[0]['fault_id'],$fault_right_list[1]['fault_id'],$fault_right_list[2]['fault_id']];
  201. //根据故障部位查找,匹配的排除方法
  202. $paichu_arr = Report::where(['bw_id'=>['in',$fault_arr],'sim_type'=>$info['sim_type']])->column('pc_id');
  203. // //根据故障部位查找,匹配可能原因
  204. // $yy_arr = Report::where(['bw_id'=>['in',$fault_arr],'sim_type'=>$info['sim_type']])->column('yy_id');
  205. //查找故障现象 数组
  206. $partent_fault_id = Fault::where(['fault_id'=>['in',$fault_arr],'sim_type'=>$info['sim_type']])->column('parent_fault_id');
  207. //根据故障部位查找,匹配可能原因
  208. $yy_arr = Fault::where(['parent_fault_id'=>['in',$partent_fault_id],'sim_type'=>$info['sim_type'],'fault_type'=>2])->column('fault_id');
  209. //获取数组
  210. $other_report = json_decode($params['other_report'],true);
  211. if(!empty($other_report)){
  212. foreach ($other_report as $key => $em){
  213. //故障现象
  214. $xianxian_arr[] = $em['xx_id'];
  215. }
  216. foreach ($partent_fault_id as $k1 =>$t){
  217. if(!in_array($t,$xianxian_arr)){
  218. $xianxian_score = 5+$xianxian_score;
  219. $xianxian_content[] = [
  220. 'gzxz_id'=>$t,
  221. 'cx_id'=>$t,
  222. 'cx_type'=>'故障现象少写',
  223. 'cx_name'=>Fault::where(['fault_id'=>$t])->value('name'),
  224. ];
  225. }else{
  226. // echo "存在里面".$t."###".$k1."<br/>";
  227. $jian = '';
  228. foreach ($other_report as $ky => $item) {
  229. if ($item['xx_id'] == $t) {
  230. $jian = $ky;
  231. }
  232. }
  233. // echo $jian."<br/>";
  234. // 故障部位算分 start
  235. //获取故障部位
  236. $buweiarr = Fault::where(['parent_fault_id'=>$t,'sim_type'=>$info['sim_type'],'fault_type'=>['in',[3,30]],'fault_state'=>0])
  237. ->column('fault_id');
  238. if(!in_array($other_report[$jian]['bw_id'],$buweiarr)){
  239. $buwei_score = 1+$buwei_score;
  240. $xianxian_content[] = [
  241. 'gzxz_id'=>$t,
  242. 'cx_id'=>$other_report[$jian]['bw_id'],
  243. 'cx_type'=>'故障部位错写',
  244. 'cx_name'=>Fault::where(['fault_id'=>$other_report[$jian]['bw_id']])->value('name'),
  245. ];
  246. }
  247. //出题故障部位和获取的故障部位里面有重复的
  248. // 获取两个数组的交集
  249. $intersection = array_intersect($buweiarr, $fault_arr);
  250. // halt($intersection);
  251. foreach($intersection as $kk =>$va){
  252. if($other_report[$jian]['bw_id']!=$va){
  253. $buwei_score = 1+$buwei_score;
  254. $xianxian_content[] = [
  255. 'gzxz_id'=>$t,
  256. 'cx_id'=>$va,
  257. 'cx_type'=>'故障部位少写',
  258. 'cx_name'=>Fault::where(['fault_id'=>$va])->value('name'),
  259. ];
  260. }
  261. }
  262. unset($va);
  263. // 故障部位算分 end
  264. // 排除方法算分 start
  265. $paichuarr = Fault::where(['parent_fault_id'=>$t,'sim_type'=>$info['sim_type'],'fault_type'=>4,'fault_state'=>0])
  266. ->column('fault_id');
  267. if(!in_array($other_report[$jian]['pc_id'],$paichuarr)){
  268. $fangfa_score = 1+$fangfa_score;
  269. $xianxian_content[] = [
  270. 'gzxz_id'=>$t,
  271. 'cx_id'=>$other_report[$jian]['pc_id'],
  272. 'cx_type'=>'排除方法错写',
  273. 'cx_name'=>Fault::where(['fault_id'=>$other_report[$jian]['pc_id']])->value('name'),
  274. ];
  275. }
  276. //出题排除方法和获取的排除方法里面有重复的
  277. // 获取两个数组的交集
  278. $intersection1 = array_intersect($paichuarr, $paichu_arr);
  279. foreach($intersection1 as $kk1 =>$va1){
  280. if($other_report[$jian]['pc_id']!=$va1){
  281. $fangfa_score = 1+$fangfa_score;
  282. $xianxian_content[] = [
  283. 'gzxz_id'=>$t,
  284. 'cx_id'=>$va1,
  285. 'cx_type'=>'排除方法少写',
  286. 'cx_name'=>Fault::where(['fault_id'=>$va1])->value('name'),
  287. ];
  288. }
  289. }
  290. unset($va1);
  291. // 排除方法算分 end
  292. // 可能原因算分 start
  293. $yuanyinarr = Fault::where(['parent_fault_id'=>$t,'sim_type'=>$info['sim_type'],'fault_type'=>2,'fault_state'=>0])
  294. ->column('fault_id');
  295. foreach (explode(',',$other_report[$jian]['yy_id']) as $key => $value) {
  296. if(!in_array($value,$yuanyinarr)){
  297. $yuanyin_socre = 1+$yuanyin_socre;
  298. $xianxian_content[] = [
  299. 'gzxz_id'=>$t,
  300. 'cx_id'=>$value,
  301. 'cx_type'=>'可能原因错写',
  302. 'cx_name'=>Fault::where(['fault_id'=>$value])->value('name'),
  303. ];
  304. }
  305. }
  306. //出题可能原因和获取的可能原因里面有重复的
  307. // 获取两个数组的交集
  308. $intersection2 = array_intersect($yy_arr, $yuanyinarr);
  309. $intersection22 = array_intersect($intersection2, explode(',',$other_report[$jian]['yy_id']));
  310. foreach($yuanyinarr as $kk2 =>$va2){
  311. if(!in_array($va2,$intersection22)){
  312. $yuanyin_socre = 1+$yuanyin_socre;
  313. $xianxian_content[] = [
  314. 'gzxz_id'=>$t,
  315. 'cx_id'=>$va2,
  316. 'cx_type'=>'可能原因少写',
  317. 'cx_name'=>Fault::where(['fault_id'=>$va2])->value('name'),
  318. ];
  319. }
  320. }
  321. unset($va2);
  322. // 可能原因算分 end
  323. }
  324. }
  325. unset($em);
  326. }else{
  327. foreach ($partent_fault_id as $key => $em){
  328. $xianxian_score = 5+$xianxian_score;
  329. $xianxian_content[] = [
  330. 'gzxz_id'=>$em,
  331. 'cx_id'=>$em,
  332. 'cx_type'=>'故障现象少写',
  333. 'cx_name'=>Fault::where(['fault_id'=>$em])->value('name'),
  334. ];
  335. }
  336. unset($em);
  337. }
  338. // //获取数组
  339. // $other_report = json_decode($params['other_report'],true);
  340. // if(!empty($other_report)){
  341. // foreach ($other_report as $key => $em){
  342. // //故障现象
  343. // $xianxian_arr[] = $em['xx_id'];
  344. // //故障部位
  345. // $buwei_arr[] = $em['bw_id'];
  346. // //可能原因
  347. // foreach(explode(',',$em['yy_id']) as $k3 =>$t13){
  348. // $yuanyin_arr[] = $t13;
  349. // }
  350. // //排除方法
  351. // $fangfa_arr[] = $em['pc_id'];
  352. // }
  353. // }
  354. // //故障现象 分数 start
  355. // foreach ($partent_fault_id as $k1 =>$t){
  356. // if(!in_array($t,$xianxian_arr)){
  357. // $xianxian_score = 1+$xianxian_score;
  358. // $xianxian_content[] = [
  359. // 'cx_id'=>$t,
  360. // 'cx_type'=>'少写',
  361. // 'cx_name'=>Fault::where(['fault_id'=>$t])->value('name'),
  362. // ];
  363. // }
  364. // }
  365. // foreach ($xianxian_arr as $k2 =>$t2){
  366. // if(!in_array($t2,$partent_fault_id)){
  367. // $xianxian_score = 1+$xianxian_score;
  368. // $xianxian_content[] = [
  369. // 'cx_id'=>$t2,
  370. // 'cx_type'=>'错写',
  371. // 'cx_name'=>Fault::where(['fault_id'=>$t2])->value('name'),
  372. // ];
  373. // }
  374. // }
  375. // //故障现象 end
  376. // //故障部位 start
  377. // foreach ($fault_arr as $k11 =>$t11){
  378. // if(!in_array($t11,$buwei_arr)){
  379. // $buwei_score = 1+$buwei_score;
  380. // $buwei_content[] = [
  381. // 'cx_id'=>$t11,
  382. // 'cx_type'=>'少写',
  383. // 'cx_name'=>Fault::where(['fault_id'=>$t11])->value('name'),
  384. // ];
  385. // }
  386. // }
  387. // foreach ($buwei_arr as $k12 =>$t12){
  388. // if(!empty($t12) && !in_array($t12,$fault_arr)){
  389. // //错写
  390. // $buwei_score = 1+$buwei_score;
  391. // $buwei_content[] = [
  392. // 'cx_id'=>$t12,
  393. // 'cx_type'=>'错写',
  394. // 'cx_name'=>Fault::where(['fault_id'=>$t12])->value('name'),
  395. // ];
  396. // }
  397. // }
  398. // //故障部位 end
  399. // //排除方法 start
  400. // //循环固定的排除方法,匹配作答的排除方法
  401. // foreach ($paichu_arr as $k21 =>$t21){
  402. // if(!in_array($t21,$fangfa_arr)){
  403. // $fangfa_score = 1+$fangfa_score;
  404. // $fangfa_content[] = [
  405. // 'cx_id'=>$t21,
  406. // 'cx_type'=>'少写',
  407. // 'cx_name'=>Fault::where(['fault_id'=>$t21])->value('name'),
  408. // ];
  409. // }
  410. // }
  411. // //循环作答的排除方法,,匹配固定的排除方法
  412. // foreach ($fangfa_arr as $k22 =>$t22){
  413. // if(!empty($t22) && !in_array($t22,$paichu_arr)){
  414. // $fangfa_score = 1+$fangfa_score;
  415. // $fangfa_content[] = [
  416. // 'cx_id'=>$t22,
  417. // 'cx_type'=>'错写',
  418. // 'cx_name'=>Fault::where(['fault_id'=>$t22])->value('name'),
  419. // ];
  420. // }
  421. // }
  422. // //排除方法 end
  423. // //可能原因 start
  424. // //循环固定的可能原因,匹配作答的可能原因
  425. // foreach ($yy_arr as $k31 =>$t31){
  426. // if(!in_array($t31,$yuanyin_arr)){
  427. // // echo $t31."<br/>";
  428. // $yuanyin_socre = 1+$yuanyin_socre;
  429. // $yuanyin_content[] = [
  430. // 'cx_id'=>$t31,
  431. // 'cx_type'=>'少写',
  432. // 'cx_name'=>Fault::where(['fault_id'=>$t31])->value('name'),
  433. // ];
  434. // }
  435. // }
  436. // //循环作答的排除方法,,匹配固定的排除方法
  437. // foreach ($yuanyin_arr as $k32 =>$t32){
  438. // if(!empty($t32) && !in_array($t32,$yy_arr)){
  439. // $yuanyin_socre = 1+$yuanyin_socre;
  440. // $yuanyin_content[] = [
  441. // 'cx_id'=>$t32,
  442. // 'cx_type'=>'错写',
  443. // 'cx_name'=>Fault::where(['fault_id'=>$t32])->value('name'),
  444. // ];
  445. // }
  446. // }
  447. // $uniqueArray = array_unique($yuanyin_arr);
  448. // $diff = array_diff_assoc($yuanyin_arr, $uniqueArray);
  449. // if(!empty($diff)){
  450. // foreach ($diff as $k323 =>$t323){
  451. // $yuanyin_socre = 1+$yuanyin_socre;
  452. // $yuanyin_content[] = [
  453. // 'cx_id'=>$t323,
  454. // 'cx_type'=>'错写',
  455. // 'cx_name'=>Fault::where(['fault_id'=>$t323])->value('name'),
  456. // ];
  457. // }
  458. // }
  459. // //可能原因 end
  460. $weixiu_score = $xianxian_score+$yuanyin_socre+$buwei_score+$fangfa_score;
  461. if($weixiu_score>15){
  462. $weixiu_score = 15;
  463. }
  464. //是否超时
  465. $overtime_fen = intval((time()-$info['countdown_time']) / 60);
  466. if($overtime_fen>=10){
  467. $overtime_score = 10;
  468. }else if($overtime_fen>0 && $overtime_fen<10){
  469. $overtime_score = $overtime_fen ;
  470. }else{
  471. $overtime_score =0;
  472. }
  473. $fault_score = $score-$fault_one_score-$fault_two_score-$fault_three_score-$weixiu_score-$overtime_score;
  474. //更新考试结果表
  475. $params['exam_id'] = $ids;
  476. $params['total'] = $fault_score;//得分;
  477. $params['fault_one_score'] = $fault_one_score;//得分;
  478. $params['fault_two_score'] = $fault_two_score;//得分;
  479. $params['fault_three_score'] = $fault_three_score;//得分;
  480. $params['xianxian_score'] = $xianxian_score;//得分;
  481. $params['xianxian_content'] = json_encode($xianxian_content);//错题;
  482. $params['yuanyin_socre'] = $yuanyin_socre;//得分;
  483. $params['yuanyin_content'] = json_encode($yuanyin_content);//错题;
  484. $params['buwei_score'] = $buwei_score;//得分;
  485. $params['buwei_content'] = json_encode($buwei_content);//错题;
  486. $params['fangfa_score'] = $fangfa_score;//得分;
  487. $params['fangfa_content'] = json_encode($fangfa_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['xianxian_content_name'] = '';
  555. if(!empty($row['xianxian_content']))
  556. {
  557. $row['xianxian_content_name'] = json_decode($row['xianxian_content'],true);
  558. }
  559. $row['yuanyin_content_name'] = '';
  560. if(!empty($row['yuanyin_content']))
  561. {
  562. $row['yuanyin_content_name'] = json_decode($row['yuanyin_content'],true);
  563. }
  564. $row['buwei_content_name'] = '';
  565. if(!empty($row['buwei_content']))
  566. {
  567. $row['buwei_content_name'] = json_decode($row['buwei_content'],true);
  568. }
  569. $row['fangfa_content_name'] = '';
  570. if(!empty($row['fangfa_content']))
  571. {
  572. $row['fangfa_content_name'] = json_decode($row['fangfa_content'],true);
  573. }
  574. $other_report = !empty($row['other_report']) ? json_decode($row['other_report'],true):[];
  575. $fault_right_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1])->select();
  576. //根据故障部位 数组
  577. $fault_arr = [$fault_right_list[0]['fault_id'],$fault_right_list[1]['fault_id'],$fault_right_list[2]['fault_id']];
  578. //查找故障现象 数组
  579. $partent_fault_id = Fault::where(['fault_id'=>['in',$fault_arr],'sim_type'=>$rows['sim_type']])->column('parent_fault_id');
  580. $arr1= [];
  581. foreach ($partent_fault_id as $key => $value) {
  582. $arr1[] = [
  583. 'gzxz_id' => $value,
  584. 'xianxian_content' => $row['xianxian_content_name'],
  585. 'other_report' => $other_report
  586. ];
  587. }
  588. $this->view->assign('other_report', $other_report);
  589. $this->view->assign('partent_fault_id', $arr1);
  590. $this->view->assign('row', $row);
  591. return $this->view->fetch();
  592. }
  593. }