Exercise.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  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 = [1,3,5];
  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. $other_content = [];
  160. Db::startTrans();
  161. try {
  162. //更新考试结束时间
  163. $row->end_time = date('Y-m-d H:i:s');
  164. $row->endtime = time();
  165. $row->exam_status = 5;
  166. $row->other_report = $params['other_report'];
  167. $result = $row->save();
  168. $info = $this->exam_model->where(['exam_id'=>$ids])->find();
  169. //更新故障是否正确
  170. $fault_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1])->select();
  171. if(!empty($fault_list)){
  172. foreach ($fault_list as $k =>$t){
  173. $answer_right = 2;
  174. if(!empty($t['sim_fault_question_value']) && !empty($t['sim_fault_answer_value'])){
  175. if($t['sim_fault_question_value']!=$t['sim_fault_answer_value'] ){
  176. //真实故障id 0002GZBW0001 薄膜开关FPC排线
  177. if($t['sim_fault_answer_value']=='00000000' && $t['fault_id'] !='0002GZBW0001'){
  178. $answer_right=2;
  179. }
  180. $answer_right=1;
  181. }
  182. }
  183. Db::name('real_exam_fault')->where(['ref_id'=>$t['ref_id']])->update(['answer_right'=>$answer_right]);
  184. }
  185. }
  186. //计算得分,故障是否有扣分 扣分制
  187. $fault_right_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1,'answer_right'=>['>',0]])->select();
  188. if(!empty($fault_right_list)){
  189. if($fault_right_list[0]['answer_right']==1){
  190. $fault_one_score = 0;
  191. }
  192. if($fault_right_list[1]['answer_right']==1){
  193. $fault_two_score = 0;
  194. }
  195. if($fault_right_list[2]['answer_right']==1){
  196. $fault_three_score = 0;
  197. }
  198. }
  199. $fault_right_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1])->select();
  200. //根据故障部位,查找故障现象
  201. $fault_arr = [$fault_right_list[0]['fault_id'],$fault_right_list[1]['fault_id'],$fault_right_list[2]['fault_id']];
  202. //根据故障部位查找,匹配的排除方法
  203. $paichu_arr = Report::where(['bw_id'=>['in',$fault_arr],'sim_type'=>$info['sim_type']])->column('pc_id');
  204. // //根据故障部位查找,匹配可能原因
  205. // $yy_arr = Report::where(['bw_id'=>['in',$fault_arr],'sim_type'=>$info['sim_type']])->column('yy_id');
  206. //查找故障现象 数组
  207. $partent_fault_id = Fault::where(['fault_id'=>['in',$fault_arr],'sim_type'=>$info['sim_type']])->column('parent_fault_id');
  208. //根据故障部位查找,匹配可能原因
  209. $yy_arr = Fault::where(['parent_fault_id'=>['in',$partent_fault_id],'sim_type'=>$info['sim_type'],'fault_type'=>2])->column('fault_id');
  210. //获取数组
  211. $other_report = json_decode($params['other_report'],true);
  212. if(!empty($other_report)){
  213. foreach ($other_report as $key => $em){
  214. //故障现象
  215. $xianxian_arr[] = $em['xx_id'];
  216. }
  217. foreach ($partent_fault_id as $k1 =>$t){
  218. $kscore = 0;
  219. if(!in_array($t,$xianxian_arr)){
  220. $xianxian_score = 5+$xianxian_score;
  221. $xianxian_content[] = [
  222. 'gzxz_id'=>$t,
  223. 'cx_id'=>$t,
  224. 'cx_type'=>'故障现象少写',
  225. 'cx_name'=>Fault::where(['fault_id'=>$t])->value('name'),
  226. 'cx_score'=>-5,
  227. ];
  228. $other_content[] = [
  229. 'gzxz_id'=>$t,
  230. 'cx_score'=>-5,
  231. ];
  232. }else{
  233. // echo "存在里面".$t."###".$k1."<br/>";
  234. $t1= $t;
  235. $jian = '';
  236. foreach ($other_report as $ky => $item) {
  237. if ($item['xx_id'] == $t) {
  238. $jian = $ky;
  239. }
  240. }
  241. // 故障部位算分 start
  242. //获取故障部位
  243. $buweiarr = Fault::where(['parent_fault_id'=>$t,'sim_type'=>$info['sim_type'],'fault_type'=>['in',[3,30]],'fault_state'=>0])
  244. ->column('fault_id');
  245. if(!in_array($other_report[$jian]['bw_id'],$buweiarr)){
  246. $buwei_score = 1+$buwei_score;
  247. $kscore = 1+$kscore;
  248. $xianxian_content[] = [
  249. 'gzxz_id'=>$t,
  250. 'cx_id'=>$other_report[$jian]['bw_id'],
  251. 'cx_type'=>'故障部位错写',
  252. 'cx_name'=>Fault::where(['fault_id'=>$other_report[$jian]['bw_id']])->value('name'),
  253. ];
  254. }
  255. //出题故障部位和获取的故障部位里面有重复的
  256. // 获取两个数组的交集
  257. $intersection = array_intersect($buweiarr, $fault_arr);
  258. // halt($intersection);
  259. foreach($intersection as $kk =>$va){
  260. if($other_report[$jian]['bw_id']!=$va){
  261. $buwei_score = 1+$buwei_score;
  262. $kscore = 1+$kscore;
  263. $xianxian_content[] = [
  264. 'gzxz_id'=>$t,
  265. 'cx_id'=>$va,
  266. 'cx_type'=>'故障部位少写',
  267. 'cx_name'=>Fault::where(['fault_id'=>$va])->value('name'),
  268. ];
  269. }
  270. }
  271. unset($va);
  272. // 故障部位算分 end
  273. // 排除方法算分 start
  274. $paichuarr = Fault::where(['parent_fault_id'=>$t,'sim_type'=>$info['sim_type'],'fault_type'=>4,'fault_state'=>0])
  275. ->column('fault_id');
  276. if(!in_array($other_report[$jian]['pc_id'],$paichuarr)){
  277. $fangfa_score = 1+$fangfa_score;
  278. $kscore = 1+$kscore;
  279. $xianxian_content[] = [
  280. 'gzxz_id'=>$t,
  281. 'cx_id'=>$other_report[$jian]['pc_id'],
  282. 'cx_type'=>'排除方法错写',
  283. 'cx_name'=>Fault::where(['fault_id'=>$other_report[$jian]['pc_id']])->value('name'),
  284. ];
  285. }
  286. //出题排除方法和获取的排除方法里面有重复的
  287. // 获取两个数组的交集
  288. $intersection1 = array_intersect($paichuarr, $paichu_arr);
  289. foreach($intersection1 as $kk1 =>$va1){
  290. if($other_report[$jian]['pc_id']!=$va1){
  291. $fangfa_score = 1+$fangfa_score;
  292. $kscore = 1+$kscore;
  293. $xianxian_content[] = [
  294. 'gzxz_id'=>$t,
  295. 'cx_id'=>$va1,
  296. 'cx_type'=>'排除方法少写',
  297. 'cx_name'=>Fault::where(['fault_id'=>$va1])->value('name'),
  298. ];
  299. }
  300. }
  301. unset($va1);
  302. // 排除方法算分 end
  303. // 可能原因算分 start
  304. $yuanyinarr = Fault::where(['parent_fault_id'=>$t,'sim_type'=>$info['sim_type'],'fault_type'=>2,'fault_state'=>0])
  305. ->column('fault_id');
  306. foreach (explode(',',$other_report[$jian]['yy_id']) as $key => $value) {
  307. if(!in_array($value,$yuanyinarr)){
  308. $yuanyin_socre = 1+$yuanyin_socre;
  309. $kscore = 1+$kscore;
  310. $xianxian_content[] = [
  311. 'gzxz_id'=>$t,
  312. 'cx_id'=>$value,
  313. 'cx_type'=>'可能原因错写',
  314. 'cx_name'=>Fault::where(['fault_id'=>$value])->value('name'),
  315. ];
  316. }
  317. }
  318. //出题可能原因和获取的可能原因里面有重复的
  319. // 获取两个数组的交集
  320. $intersection2 = array_intersect($yy_arr, $yuanyinarr);
  321. $intersection22 = array_intersect($intersection2, explode(',',$other_report[$jian]['yy_id']));
  322. foreach($yuanyinarr as $kk2 =>$va2){
  323. if(!in_array($va2,$intersection22)){
  324. $yuanyin_socre = 1+$yuanyin_socre;
  325. $kscore = 1+$kscore;
  326. $xianxian_content[] = [
  327. 'gzxz_id'=>$t,
  328. 'cx_id'=>$va2,
  329. 'cx_type'=>'可能原因少写',
  330. 'cx_name'=>Fault::where(['fault_id'=>$va2])->value('name'),
  331. ];
  332. }
  333. }
  334. unset($va2);
  335. // 可能原因算分 end
  336. if($kscore>5){
  337. $kscore = '-5';
  338. }else if($kscore>0){
  339. $kscore = '-'.$kscore;
  340. }else{
  341. $kscore=0;
  342. }
  343. // echo $t1."####".$kscore."<br/>";
  344. $other_content[] = [
  345. 'gzxz_id'=>$t,
  346. 'cx_score'=>$kscore,
  347. ];
  348. }
  349. }
  350. unset($em);
  351. // echo "<pre>";
  352. // print_r($xianxian_content);
  353. // echo "<pre>";
  354. // print_r($other_content);
  355. // die();
  356. }else{
  357. foreach ($partent_fault_id as $key => $em){
  358. $xianxian_score = 5+$xianxian_score;
  359. $xianxian_content[] = [
  360. 'gzxz_id'=>$em,
  361. 'cx_id'=>$em,
  362. 'cx_type'=>'未作答',
  363. // 'cx_name'=>Fault::where(['fault_id'=>$em])->value('name'),
  364. 'cx_name'=>'',
  365. ];
  366. $other_content[] = [
  367. 'gzxz_id'=>$em,
  368. 'cx_score'=>-5,
  369. ];
  370. }
  371. unset($em);
  372. }
  373. // //获取数组
  374. // $other_report = json_decode($params['other_report'],true);
  375. // if(!empty($other_report)){
  376. // foreach ($other_report as $key => $em){
  377. // //故障现象
  378. // $xianxian_arr[] = $em['xx_id'];
  379. // //故障部位
  380. // $buwei_arr[] = $em['bw_id'];
  381. // //可能原因
  382. // foreach(explode(',',$em['yy_id']) as $k3 =>$t13){
  383. // $yuanyin_arr[] = $t13;
  384. // }
  385. // //排除方法
  386. // $fangfa_arr[] = $em['pc_id'];
  387. // }
  388. // }
  389. // //故障现象 分数 start
  390. // foreach ($partent_fault_id as $k1 =>$t){
  391. // if(!in_array($t,$xianxian_arr)){
  392. // $xianxian_score = 1+$xianxian_score;
  393. // $xianxian_content[] = [
  394. // 'cx_id'=>$t,
  395. // 'cx_type'=>'少写',
  396. // 'cx_name'=>Fault::where(['fault_id'=>$t])->value('name'),
  397. // ];
  398. // }
  399. // }
  400. // foreach ($xianxian_arr as $k2 =>$t2){
  401. // if(!in_array($t2,$partent_fault_id)){
  402. // $xianxian_score = 1+$xianxian_score;
  403. // $xianxian_content[] = [
  404. // 'cx_id'=>$t2,
  405. // 'cx_type'=>'错写',
  406. // 'cx_name'=>Fault::where(['fault_id'=>$t2])->value('name'),
  407. // ];
  408. // }
  409. // }
  410. // //故障现象 end
  411. // //故障部位 start
  412. // foreach ($fault_arr as $k11 =>$t11){
  413. // if(!in_array($t11,$buwei_arr)){
  414. // $buwei_score = 1+$buwei_score;
  415. // $buwei_content[] = [
  416. // 'cx_id'=>$t11,
  417. // 'cx_type'=>'少写',
  418. // 'cx_name'=>Fault::where(['fault_id'=>$t11])->value('name'),
  419. // ];
  420. // }
  421. // }
  422. // foreach ($buwei_arr as $k12 =>$t12){
  423. // if(!empty($t12) && !in_array($t12,$fault_arr)){
  424. // //错写
  425. // $buwei_score = 1+$buwei_score;
  426. // $buwei_content[] = [
  427. // 'cx_id'=>$t12,
  428. // 'cx_type'=>'错写',
  429. // 'cx_name'=>Fault::where(['fault_id'=>$t12])->value('name'),
  430. // ];
  431. // }
  432. // }
  433. // //故障部位 end
  434. // //排除方法 start
  435. // //循环固定的排除方法,匹配作答的排除方法
  436. // foreach ($paichu_arr as $k21 =>$t21){
  437. // if(!in_array($t21,$fangfa_arr)){
  438. // $fangfa_score = 1+$fangfa_score;
  439. // $fangfa_content[] = [
  440. // 'cx_id'=>$t21,
  441. // 'cx_type'=>'少写',
  442. // 'cx_name'=>Fault::where(['fault_id'=>$t21])->value('name'),
  443. // ];
  444. // }
  445. // }
  446. // //循环作答的排除方法,,匹配固定的排除方法
  447. // foreach ($fangfa_arr as $k22 =>$t22){
  448. // if(!empty($t22) && !in_array($t22,$paichu_arr)){
  449. // $fangfa_score = 1+$fangfa_score;
  450. // $fangfa_content[] = [
  451. // 'cx_id'=>$t22,
  452. // 'cx_type'=>'错写',
  453. // 'cx_name'=>Fault::where(['fault_id'=>$t22])->value('name'),
  454. // ];
  455. // }
  456. // }
  457. // //排除方法 end
  458. // //可能原因 start
  459. // //循环固定的可能原因,匹配作答的可能原因
  460. // foreach ($yy_arr as $k31 =>$t31){
  461. // if(!in_array($t31,$yuanyin_arr)){
  462. // // echo $t31."<br/>";
  463. // $yuanyin_socre = 1+$yuanyin_socre;
  464. // $yuanyin_content[] = [
  465. // 'cx_id'=>$t31,
  466. // 'cx_type'=>'少写',
  467. // 'cx_name'=>Fault::where(['fault_id'=>$t31])->value('name'),
  468. // ];
  469. // }
  470. // }
  471. // //循环作答的排除方法,,匹配固定的排除方法
  472. // foreach ($yuanyin_arr as $k32 =>$t32){
  473. // if(!empty($t32) && !in_array($t32,$yy_arr)){
  474. // $yuanyin_socre = 1+$yuanyin_socre;
  475. // $yuanyin_content[] = [
  476. // 'cx_id'=>$t32,
  477. // 'cx_type'=>'错写',
  478. // 'cx_name'=>Fault::where(['fault_id'=>$t32])->value('name'),
  479. // ];
  480. // }
  481. // }
  482. // $uniqueArray = array_unique($yuanyin_arr);
  483. // $diff = array_diff_assoc($yuanyin_arr, $uniqueArray);
  484. // if(!empty($diff)){
  485. // foreach ($diff as $k323 =>$t323){
  486. // $yuanyin_socre = 1+$yuanyin_socre;
  487. // $yuanyin_content[] = [
  488. // 'cx_id'=>$t323,
  489. // 'cx_type'=>'错写',
  490. // 'cx_name'=>Fault::where(['fault_id'=>$t323])->value('name'),
  491. // ];
  492. // }
  493. // }
  494. // //可能原因 end
  495. $weixiu_score = $xianxian_score+$yuanyin_socre+$buwei_score+$fangfa_score;
  496. if($weixiu_score>15){
  497. $weixiu_score = 15;
  498. }
  499. //是否超时
  500. $overtime_fen = intval((time()-$info['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. $report_score = 15-$row['xianxian_score']-$row['yuanyin_socre']-$row['buwei_score']-$row['fangfa_score'];
  592. $row['report_score'] = $report_score>0?$report_score:0;
  593. $row['weixiu_score'] = 10-$row['overtime_score']??0;
  594. $row['xianxian_content_name'] = '';
  595. if(!empty($row['xianxian_content']))
  596. {
  597. $row['xianxian_content_name'] = json_decode($row['xianxian_content'],true);
  598. }
  599. $row['yuanyin_content_name'] = '';
  600. if(!empty($row['yuanyin_content']))
  601. {
  602. $row['yuanyin_content_name'] = json_decode($row['yuanyin_content'],true);
  603. }
  604. $row['buwei_content_name'] = '';
  605. if(!empty($row['buwei_content']))
  606. {
  607. $row['buwei_content_name'] = json_decode($row['buwei_content'],true);
  608. }
  609. $row['fangfa_content_name'] = '';
  610. if(!empty($row['fangfa_content']))
  611. {
  612. $row['fangfa_content_name'] = json_decode($row['fangfa_content'],true);
  613. }
  614. $other_report = !empty($row['other_report']) ? json_decode($row['other_report'],true):[];
  615. $other_jielun = !empty($row['other_jielun']) ? json_decode($row['other_jielun'],true):[];
  616. $fault_right_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1])->select();
  617. //根据故障部位 数组
  618. $fault_arr = [$fault_right_list[0]['fault_id'],$fault_right_list[1]['fault_id'],$fault_right_list[2]['fault_id']];
  619. //查找故障现象 数组
  620. $partent_fault_id = Fault::where(['fault_id'=>['in',$fault_arr],'sim_type'=>$rows['sim_type']])->column('parent_fault_id');
  621. $arr1= [];
  622. foreach ($partent_fault_id as $key => $value) {
  623. $arr1[] = [
  624. 'gzxz_id' => $value,
  625. 'xianxian_content' => $row['xianxian_content_name'],
  626. 'other_report' => $other_report,
  627. 'other_jielun' => $other_jielun,
  628. ];
  629. }
  630. $this->view->assign('other_report', $other_report);
  631. $this->view->assign('partent_fault_id', $arr1);
  632. $this->view->assign('row', $row);
  633. return $this->view->fetch();
  634. }
  635. }