Practice.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  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 Practice 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->assignConfig('sim_sim_type', ConfigModel::getSimTypeList());
  32. $this->assignConfig('sim_question_setting_method', ConfigModel::getSimQuestionList());
  33. $this->whereExtend['exam_collection_type'] = 1;//练习
  34. $this->whereExtend['exam_collection_state'] = 2;
  35. }
  36. /**
  37. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  38. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  39. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  40. */
  41. public function index()
  42. {
  43. $isset = $this->model->alias('z')
  44. ->join('real_exam r','z.exam_collection_id=r.exam_collection_id','left')
  45. ->where('z.exam_collection_type=1 and z.exam_collection_state=2 and r.endtime=0 and r.user_id='.$this->auth->id)->find();
  46. if(empty($isset)){
  47. //提示页面,没有开始的考试
  48. return $this->view->fetch('tishi');
  49. }else{
  50. echo "<script>location.href='/admin/student/practice/into/ids/".$isset['exam_collection_id']."'</script>";
  51. }
  52. die();
  53. //设置过滤方法
  54. $this->request->filter(['strip_tags', 'trim']);
  55. if (false === $this->request->isAjax()) {
  56. return $this->view->fetch();
  57. }
  58. //如果发送的来源是 Selectpage,则转发到 Selectpage
  59. if ($this->request->request('keyField')) {
  60. return $this->selectpage();
  61. }
  62. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  63. $list = $this->model
  64. ->where($where)->where($this->whereExtend)
  65. ->order($sort, $order)
  66. ->paginate($limit);
  67. foreach ($list as $k => $v){
  68. $exam_isset = $this->exam_model->where(['user_id'=>$this->auth->id,'exam_collection_id'=>$v['exam_collection_id'],'exam_collection_type'=>1])->find();
  69. if(isset($exam_isset)){
  70. $v->is_user_examed = 1;
  71. }else{
  72. $v->is_user_examed = 0;
  73. }
  74. }
  75. unset($v);
  76. $result = ['total' => $list->total(), 'rows' => $list->items()];
  77. return json($result);
  78. }
  79. //进入考试
  80. public function into($ids = null)
  81. {
  82. $row = $this->model->get($ids);
  83. if(!$row){
  84. $this->error('未找到记录');
  85. }
  86. $info = $this->exam_model->where(['user_id'=>$this->auth->id,'exam_collection_id'=>$ids])->find();
  87. // if(empty($info)){
  88. // $arr = [
  89. // 'exam_collection_id' => $ids,
  90. // 'user_id' => $this->auth->id,
  91. // 'user_username' => $this->auth->username,
  92. // 'user_nickname' => $this->auth->nickname,
  93. // 'user_depart_id' => $this->auth->depart_id,
  94. // 'exam_collection_name' => $row->exam_collection_name,
  95. // 'exam_collection_type' =>1,
  96. // 'sim_type' => $row->sim_type,
  97. // 'seat_id' => 1,
  98. // 'sim_id' => 12,
  99. // ];
  100. // $this->exam_model->save($arr);
  101. // }
  102. if(!empty($info)){
  103. if(!empty($this->auth->seat_id) && !empty($info['seat_id']) && $this->auth->seat_id!=$info['seat_id']){
  104. $this->error('已在其他座号有开始的练习,不允许换座号');
  105. }
  106. $sim = Db::name('sim')->where('sim_type',$info['sim_type'])->where('seat_id',$this->auth->seat_id)->find();
  107. if(empty($sim)){
  108. $this->error('未找到模拟器,不可练习');
  109. }
  110. $this->exam_model->where('exam_id',$info['exam_id'])->update(['seat_id'=>$this->auth->seat_id,'sim_id'=>$sim['sim_id']]);
  111. $info['seat_id'] = $this->auth->seat_id;
  112. $sim_text = '';
  113. if(!empty($sim)){
  114. if($sim['sim_state']==1){
  115. $sim_text = '在线';
  116. }else if($sim['sim_state']==2){
  117. $sim_text = '模拟器离线';
  118. }else if($sim['sim_state']==3){
  119. $sim_text = '网关离线';
  120. }else if($sim['sim_state']==4){
  121. $sim_text = '硬件故障异常';
  122. }else if($sim['sim_state']==5){
  123. $sim_text = '手动禁用';
  124. }
  125. }
  126. // 模拟器状态 0:可用初始化 1:在线 2:模拟器离线 3:网关离线 4:硬件故障异常 5:手动禁用
  127. $info['sim_text'] = $sim_text;
  128. }
  129. if(!empty($info['starttime']))
  130. {
  131. echo "<script>location.href='/admin/student/practice/examing/ids/".$info['exam_id']."'</script>";
  132. die();
  133. }
  134. // if ($this->request->isPost()) {
  135. // $exam_collection_id = $this->request->post('exam_collection_id');
  136. // if(empty($info->starttime)){
  137. // $info->start_time = date('Y-m-d H:i:s');
  138. // $info->starttime = time();
  139. // }
  140. // $info->exam_status = 4;
  141. // $info->save();
  142. // $this->success('开始成功','/admin/student/practice/examing/ids/'.$info['exam_id']);
  143. // }
  144. $this->assignConfig('exam_id', $info['exam_id']);
  145. $this->assignConfig('url_type', config('site.url_type'));
  146. $this->assignConfig('is_fault', Env::get('app.is_fault'));
  147. $this->view->assign('row', $row);
  148. return $this->view->fetch();
  149. }
  150. public function examing($ids = null)
  151. {
  152. $row = $this->exam_model->get($ids);
  153. if(!$row){
  154. $this->error('未找到记录');
  155. }
  156. if ($this->request->isPost()) {
  157. //先请求接口判断,再进行处理
  158. if(Env::get('app.is_fault')){
  159. $url = config('site.url_type').'/sim/real-exam/student/exercise/submit/'.$ids;
  160. // /dev-api/sim/real-exam/student/exam/submit/{examId}
  161. $ret = json_decode(send_get($url),true);
  162. // halt($ret);
  163. if($ret['code']!=200){
  164. $this->error($ret['msg']);
  165. }
  166. }
  167. //计算分数,保存记录
  168. $params = $this->request->post('row/a');
  169. $result = false;
  170. $score = 100;
  171. $fault_one_score = 25;
  172. $fault_two_score = 25;
  173. $fault_three_score = 25;
  174. //故障现象
  175. $xianxian_score = 0;
  176. $xianxian_arr = [];
  177. $xianxian_content = [];
  178. //故障部位
  179. $buwei_score= 0;
  180. $buwei_arr = [];
  181. $buwei_content = [];
  182. //可能原因
  183. $yuanyin_socre= 0;
  184. $yuanyin_arr = [];
  185. $yuanyin_content = [];
  186. //排除方法
  187. $fangfa_score= 0;
  188. $fangfa_arr = [];
  189. $fangfa_content = [];
  190. Db::startTrans();
  191. try {
  192. //更新考试结束时间
  193. $row->end_time = date('Y-m-d H:i:s');
  194. $row->endtime = time();
  195. $row->exam_status = 5;
  196. $row->other_report = $params['other_report'];
  197. $result = $row->save();
  198. $info = $this->exam_model->where(['exam_id'=>$ids])->find();
  199. //更新故障是否正确
  200. $fault_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1])->select();
  201. if(!empty($fault_list)){
  202. foreach ($fault_list as $k =>$t){
  203. $answer_right = 2;
  204. if(!empty($t['sim_fault_question_value']) && !empty($t['sim_fault_answer_value'])){
  205. if($t['sim_fault_question_value']!=$t['sim_fault_answer_value'] ){
  206. //真实故障id 0002GZBW0001 薄膜开关FPC排线
  207. if($t['sim_fault_answer_value']=='00000000' && $t['fault_id'] !='0002GZBW0001'){
  208. $answer_right=2;
  209. }
  210. $answer_right=1;
  211. }
  212. }
  213. Db::name('real_exam_fault')->where(['ref_id'=>$t['ref_id']])->update(['answer_right'=>$answer_right]);
  214. }
  215. }
  216. //计算得分,故障是否有扣分 扣分制
  217. $fault_right_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1,'answer_right'=>['>',0]])->select();
  218. if(!empty($fault_right_list)){
  219. if($fault_right_list[0]['answer_right']==1){
  220. $fault_one_score = 0;
  221. }
  222. if($fault_right_list[1]['answer_right']==1){
  223. $fault_two_score = 0;
  224. }
  225. if($fault_right_list[2]['answer_right']==1){
  226. $fault_three_score = 0;
  227. }
  228. }
  229. $fault_right_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1])->select();
  230. //根据故障部位,查找故障现象
  231. $fault_arr = [$fault_right_list[0]['fault_id'],$fault_right_list[1]['fault_id'],$fault_right_list[2]['fault_id']];
  232. //根据故障部位查找,匹配的排除方法
  233. $paichu_arr = Report::where(['bw_id'=>['in',$fault_arr],'sim_type'=>$info['sim_type']])->column('pc_id');
  234. // //根据故障部位查找,匹配可能原因
  235. // $yy_arr = Report::where(['bw_id'=>['in',$fault_arr],'sim_type'=>$info['sim_type']])->column('yy_id');
  236. //查找故障现象 数组
  237. $partent_fault_id = Fault::where(['fault_id'=>['in',$fault_arr],'sim_type'=>$info['sim_type']])->column('parent_fault_id');
  238. //根据故障部位查找,匹配可能原因
  239. $yy_arr = Fault::where(['parent_fault_id'=>['in',$partent_fault_id],'sim_type'=>$info['sim_type'],'fault_type'=>2])->column('fault_id');
  240. //获取数组
  241. $other_report = json_decode($params['other_report'],true);
  242. if(!empty($other_report)){
  243. foreach ($other_report as $key => $em){
  244. //故障现象
  245. $xianxian_arr[] = $em['xx_id'];
  246. }
  247. foreach ($partent_fault_id as $k1 =>$t){
  248. if(!in_array($t,$xianxian_arr)){
  249. $xianxian_score = 5+$xianxian_score;
  250. $xianxian_content[] = [
  251. 'gzxz_id'=>$t,
  252. 'cx_id'=>$t,
  253. 'cx_type'=>'故障现象少写',
  254. 'cx_name'=>Fault::where(['fault_id'=>$t])->value('name'),
  255. ];
  256. }else{
  257. // echo "存在里面".$t."###".$k1."<br/>";
  258. $jian = '';
  259. foreach ($other_report as $ky => $item) {
  260. if ($item['xx_id'] == $t) {
  261. $jian = $ky;
  262. }
  263. }
  264. // echo $jian."<br/>";
  265. // 故障部位算分 start
  266. //获取故障部位
  267. $buweiarr = Fault::where(['parent_fault_id'=>$t,'sim_type'=>$info['sim_type'],'fault_type'=>['in',[3,30]],'fault_state'=>0])
  268. ->column('fault_id');
  269. if(!in_array($other_report[$jian]['bw_id'],$buweiarr)){
  270. $buwei_score = 1+$buwei_score;
  271. $xianxian_content[] = [
  272. 'gzxz_id'=>$t,
  273. 'cx_id'=>$other_report[$jian]['bw_id'],
  274. 'cx_type'=>'故障部位错写',
  275. 'cx_name'=>Fault::where(['fault_id'=>$other_report[$jian]['bw_id']])->value('name'),
  276. ];
  277. }
  278. //出题故障部位和获取的故障部位里面有重复的
  279. // 获取两个数组的交集
  280. $intersection = array_intersect($buweiarr, $fault_arr);
  281. // halt($intersection);
  282. foreach($intersection as $kk =>$va){
  283. if($other_report[$jian]['bw_id']!=$va){
  284. $buwei_score = 1+$buwei_score;
  285. $xianxian_content[] = [
  286. 'gzxz_id'=>$t,
  287. 'cx_id'=>$va,
  288. 'cx_type'=>'故障部位少写',
  289. 'cx_name'=>Fault::where(['fault_id'=>$va])->value('name'),
  290. ];
  291. }
  292. }
  293. unset($va);
  294. // 故障部位算分 end
  295. // 排除方法算分 start
  296. $paichuarr = Fault::where(['parent_fault_id'=>$t,'sim_type'=>$info['sim_type'],'fault_type'=>4,'fault_state'=>0])
  297. ->column('fault_id');
  298. if(!in_array($other_report[$jian]['pc_id'],$paichuarr)){
  299. $fangfa_score = 1+$fangfa_score;
  300. $xianxian_content[] = [
  301. 'gzxz_id'=>$t,
  302. 'cx_id'=>$other_report[$jian]['pc_id'],
  303. 'cx_type'=>'排除方法错写',
  304. 'cx_name'=>Fault::where(['fault_id'=>$other_report[$jian]['pc_id']])->value('name'),
  305. ];
  306. }
  307. //出题排除方法和获取的排除方法里面有重复的
  308. // 获取两个数组的交集
  309. $intersection1 = array_intersect($paichuarr, $paichu_arr);
  310. foreach($intersection1 as $kk1 =>$va1){
  311. if($other_report[$jian]['pc_id']!=$va1){
  312. $fangfa_score = 1+$fangfa_score;
  313. $xianxian_content[] = [
  314. 'gzxz_id'=>$t,
  315. 'cx_id'=>$va1,
  316. 'cx_type'=>'排除方法少写',
  317. 'cx_name'=>Fault::where(['fault_id'=>$va1])->value('name'),
  318. ];
  319. }
  320. }
  321. unset($va1);
  322. // 排除方法算分 end
  323. // 可能原因算分 start
  324. $yuanyinarr = Fault::where(['parent_fault_id'=>$t,'sim_type'=>$info['sim_type'],'fault_type'=>2,'fault_state'=>0])
  325. ->column('fault_id');
  326. foreach (explode(',',$other_report[$jian]['yy_id']) as $key => $value) {
  327. if(!in_array($value,$yuanyinarr)){
  328. $yuanyin_socre = 1+$yuanyin_socre;
  329. $xianxian_content[] = [
  330. 'gzxz_id'=>$t,
  331. 'cx_id'=>$value,
  332. 'cx_type'=>'可能原因错写',
  333. 'cx_name'=>Fault::where(['fault_id'=>$value])->value('name'),
  334. ];
  335. }
  336. }
  337. //出题可能原因和获取的可能原因里面有重复的
  338. // 获取两个数组的交集
  339. $intersection2 = array_intersect($yy_arr, $yuanyinarr);
  340. $intersection22 = array_intersect($intersection2, explode(',',$other_report[$jian]['yy_id']));
  341. foreach($yuanyinarr as $kk2 =>$va2){
  342. if(!in_array($va2,$intersection22)){
  343. $yuanyin_socre = 1+$yuanyin_socre;
  344. $xianxian_content[] = [
  345. 'gzxz_id'=>$t,
  346. 'cx_id'=>$va2,
  347. 'cx_type'=>'可能原因少写',
  348. 'cx_name'=>Fault::where(['fault_id'=>$va2])->value('name'),
  349. ];
  350. }
  351. }
  352. unset($va2);
  353. // 可能原因算分 end
  354. }
  355. }
  356. unset($em);
  357. }else{
  358. foreach ($partent_fault_id as $key => $em){
  359. $xianxian_score = 5+$xianxian_score;
  360. $xianxian_content[] = [
  361. 'gzxz_id'=>$em,
  362. 'cx_id'=>$em,
  363. 'cx_type'=>'故障现象少写',
  364. 'cx_name'=>Fault::where(['fault_id'=>$em])->value('name'),
  365. ];
  366. }
  367. unset($em);
  368. }
  369. // //获取数组
  370. // $other_report = json_decode($params['other_report'],true);
  371. // if(!empty($other_report)){
  372. // foreach ($other_report as $key => $em){
  373. // //故障现象
  374. // $xianxian_arr[] = $em['xx_id'];
  375. // //故障部位
  376. // $buwei_arr[] = $em['bw_id'];
  377. // //可能原因
  378. // foreach(explode(',',$em['yy_id']) as $k3 =>$t13){
  379. // $yuanyin_arr[] = $t13;
  380. // }
  381. // //排除方法
  382. // $fangfa_arr[] = $em['pc_id'];
  383. // }
  384. // }
  385. // //故障现象 分数 start
  386. // foreach ($partent_fault_id as $k1 =>$t){
  387. // if(!in_array($t,$xianxian_arr)){
  388. // $xianxian_score = 1+$xianxian_score;
  389. // $xianxian_content[] = [
  390. // 'cx_id'=>$t,
  391. // 'cx_type'=>'少写',
  392. // 'cx_name'=>Fault::where(['fault_id'=>$t])->value('name'),
  393. // ];
  394. // }
  395. // }
  396. // foreach ($xianxian_arr as $k2 =>$t2){
  397. // if(!in_array($t2,$partent_fault_id)){
  398. // $xianxian_score = 1+$xianxian_score;
  399. // $xianxian_content[] = [
  400. // 'cx_id'=>$t2,
  401. // 'cx_type'=>'错写',
  402. // 'cx_name'=>Fault::where(['fault_id'=>$t2])->value('name'),
  403. // ];
  404. // }
  405. // }
  406. // //故障现象 end
  407. // //故障部位 start
  408. // foreach ($fault_arr as $k11 =>$t11){
  409. // if(!in_array($t11,$buwei_arr)){
  410. // $buwei_score = 1+$buwei_score;
  411. // $buwei_content[] = [
  412. // 'cx_id'=>$t11,
  413. // 'cx_type'=>'少写',
  414. // 'cx_name'=>Fault::where(['fault_id'=>$t11])->value('name'),
  415. // ];
  416. // }
  417. // }
  418. // foreach ($buwei_arr as $k12 =>$t12){
  419. // if(!empty($t12) && !in_array($t12,$fault_arr)){
  420. // //错写
  421. // $buwei_score = 1+$buwei_score;
  422. // $buwei_content[] = [
  423. // 'cx_id'=>$t12,
  424. // 'cx_type'=>'错写',
  425. // 'cx_name'=>Fault::where(['fault_id'=>$t12])->value('name'),
  426. // ];
  427. // }
  428. // }
  429. // //故障部位 end
  430. // //排除方法 start
  431. // //循环固定的排除方法,匹配作答的排除方法
  432. // foreach ($paichu_arr as $k21 =>$t21){
  433. // if(!in_array($t21,$fangfa_arr)){
  434. // $fangfa_score = 1+$fangfa_score;
  435. // $fangfa_content[] = [
  436. // 'cx_id'=>$t21,
  437. // 'cx_type'=>'少写',
  438. // 'cx_name'=>Fault::where(['fault_id'=>$t21])->value('name'),
  439. // ];
  440. // }
  441. // }
  442. // //循环作答的排除方法,,匹配固定的排除方法
  443. // foreach ($fangfa_arr as $k22 =>$t22){
  444. // if(!empty($t22) && !in_array($t22,$paichu_arr)){
  445. // $fangfa_score = 1+$fangfa_score;
  446. // $fangfa_content[] = [
  447. // 'cx_id'=>$t22,
  448. // 'cx_type'=>'错写',
  449. // 'cx_name'=>Fault::where(['fault_id'=>$t22])->value('name'),
  450. // ];
  451. // }
  452. // }
  453. // //排除方法 end
  454. // //可能原因 start
  455. // //循环固定的可能原因,匹配作答的可能原因
  456. // foreach ($yy_arr as $k31 =>$t31){
  457. // if(!in_array($t31,$yuanyin_arr)){
  458. // // echo $t31."<br/>";
  459. // $yuanyin_socre = 1+$yuanyin_socre;
  460. // $yuanyin_content[] = [
  461. // 'cx_id'=>$t31,
  462. // 'cx_type'=>'少写',
  463. // 'cx_name'=>Fault::where(['fault_id'=>$t31])->value('name'),
  464. // ];
  465. // }
  466. // }
  467. // //循环作答的排除方法,,匹配固定的排除方法
  468. // foreach ($yuanyin_arr as $k32 =>$t32){
  469. // if(!empty($t32) && !in_array($t32,$yy_arr)){
  470. // $yuanyin_socre = 1+$yuanyin_socre;
  471. // $yuanyin_content[] = [
  472. // 'cx_id'=>$t32,
  473. // 'cx_type'=>'错写',
  474. // 'cx_name'=>Fault::where(['fault_id'=>$t32])->value('name'),
  475. // ];
  476. // }
  477. // }
  478. // $uniqueArray = array_unique($yuanyin_arr);
  479. // $diff = array_diff_assoc($yuanyin_arr, $uniqueArray);
  480. // if(!empty($diff)){
  481. // foreach ($diff as $k323 =>$t323){
  482. // $yuanyin_socre = 1+$yuanyin_socre;
  483. // $yuanyin_content[] = [
  484. // 'cx_id'=>$t323,
  485. // 'cx_type'=>'错写',
  486. // 'cx_name'=>Fault::where(['fault_id'=>$t323])->value('name'),
  487. // ];
  488. // }
  489. // }
  490. // //可能原因 end
  491. $weixiu_score = $xianxian_score+$yuanyin_socre+$buwei_score+$fangfa_score;
  492. if($weixiu_score>15){
  493. $weixiu_score = 15;
  494. }
  495. //是否超时
  496. $overtime_fen = intval((time()-$info['countdown_time']) / 60);
  497. if($overtime_fen>=10){
  498. $overtime_score = 10;
  499. }else if($overtime_fen>0 && $overtime_fen<10){
  500. $overtime_score = $overtime_fen ;
  501. }else{
  502. $overtime_score =0;
  503. }
  504. $fault_score = $score-$fault_one_score-$fault_two_score-$fault_three_score-$weixiu_score-$overtime_score;
  505. //更新考试结果表
  506. $params['exam_id'] = $ids;
  507. $params['total'] = $fault_score;//得分;
  508. $params['fault_one_score'] = $fault_one_score;//得分;
  509. $params['fault_two_score'] = $fault_two_score;//得分;
  510. $params['fault_three_score'] = $fault_three_score;//得分;
  511. $params['xianxian_score'] = $xianxian_score;//得分;
  512. $params['xianxian_content'] = json_encode($xianxian_content);//错题;
  513. $params['yuanyin_socre'] = $yuanyin_socre;//得分;
  514. $params['yuanyin_content'] = json_encode($yuanyin_content);//错题;
  515. $params['buwei_score'] = $buwei_score;//得分;
  516. $params['buwei_content'] = json_encode($buwei_content);//错题;
  517. $params['fangfa_score'] = $fangfa_score;//得分;
  518. $params['fangfa_content'] = json_encode($fangfa_content);//错题;
  519. $params['overtime_score'] = $overtime_score;//得分;
  520. Db::name('real_exam_score')->insert($params);
  521. $this->exam_model->where(['exam_id'=>$ids])->update(['total_score'=>$fault_score]);
  522. Db::commit();
  523. } catch (ValidateException|PDOException|Exception $e) {
  524. Db::rollback();
  525. $this->error($e->getMessage());
  526. }
  527. if ($result === false) {
  528. $this->error(__('No rows were inserted'));
  529. }
  530. $this->success('交卷成功','/admin/student/practice/analysis/ids/'.$row['exam_id']);
  531. }
  532. if(empty($row->starttime)){
  533. $row->start_time = date('Y-m-d H:i:s');
  534. $row->starttime = time();
  535. $row->exam_status = 4;
  536. $row->save();
  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. //还未开始练习
  545. $row->limit_duration = $this->model->where(['exam_collection_id'=>$row['exam_collection_id']])->value('limit_duration');
  546. if(empty($row->starttime)){
  547. $timer = 60*$row->limit_duration;
  548. }else{
  549. $timer = $row->limit_duration*60 - abs(time() - $row->starttime);
  550. }
  551. if(empty($row->countdown_time)){
  552. $duration = 10+$row->limit_duration;
  553. $this->exam_model->where('exam_id',$ids)->update(['countdown_time'=>strtotime(date('Y-m-d H:i:s', strtotime('+'.$duration.' minute',$row->starttime)))]);
  554. }
  555. $departmentdata = [];
  556. $departmentdata = Fault::where(['replace_part'=>1,'sim_type'=>$row->sim_type])->order('fault_id asc')->select();
  557. $this->view->assign('departmentdata', $departmentdata);
  558. //故障现象
  559. $xianxiang = Fault::where(['fault_type'=>1,'sim_type'=>$row->sim_type])->select();
  560. $this->view->assign('xianxiang', $xianxiang);
  561. $row->replace_list =Db::name('real_exam_comp_request')->where(['exam_id'=>$ids])->select();
  562. $this->assignConfig('ids',$ids);
  563. $this->assignConfig('timer',$timer);
  564. $this->assignConfig('isloading',$isloading);
  565. $this->view->assign('row', $row);
  566. return $this->view->fetch();
  567. }
  568. public function analysis($ids = null)
  569. {
  570. if ($this->request->isPost()) {
  571. $params = $this->request->post('row/a');
  572. //计算总分到学员考试表
  573. $this->success('操作成功','/admin/student/practice/index');
  574. }
  575. $row = Db::name('real_exam_score')->where('exam_id', $ids)->find();
  576. if (!$row) {
  577. $this->error(__('No Results were found'));
  578. }
  579. $rows = $this->exam_model->get($ids);
  580. $row['seat_id'] = $rows->seat_id;
  581. $row['user_nickname'] = $rows->user_nickname;
  582. $row['user_username'] = $rows->user_username;
  583. $row['user_depart_id'] = $rows->user_depart_id;
  584. $row['user_depart_name'] = Department::where('id',$rows->user_depart_id)->value('name');
  585. $row['start_time'] = $rows->start_time;
  586. $row['end_time'] = $rows->end_time;
  587. $fault_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1])->select();
  588. $row['fault_name_one'] = !empty($fault_list[0]['fault_id']) ? Fault::where('fault_id',$fault_list[0]['fault_id'])->value('name'):'';
  589. $row['fault_name_two'] = !empty($fault_list[1]['fault_id']) ? Fault::where('fault_id',$fault_list[1]['fault_id'])->value('name'):'';
  590. $row['fault_name_three'] = !empty($fault_list[2]['fault_id']) ? Fault::where('fault_id',$fault_list[2]['fault_id'])->value('name'):'';
  591. $row['xianxian_content_name'] = '';
  592. if(!empty($row['xianxian_content']))
  593. {
  594. $row['xianxian_content_name'] = json_decode($row['xianxian_content'],true);
  595. }
  596. $row['yuanyin_content_name'] = '';
  597. if(!empty($row['yuanyin_content']))
  598. {
  599. $row['yuanyin_content_name'] = json_decode($row['yuanyin_content'],true);
  600. }
  601. $row['buwei_content_name'] = '';
  602. if(!empty($row['buwei_content']))
  603. {
  604. $row['buwei_content_name'] = json_decode($row['buwei_content'],true);
  605. }
  606. $row['fangfa_content_name'] = '';
  607. if(!empty($row['fangfa_content']))
  608. {
  609. $row['fangfa_content_name'] = json_decode($row['fangfa_content'],true);
  610. }
  611. $other_report = !empty($row['other_report']) ? json_decode($row['other_report'],true):[];
  612. $fault_right_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1])->select();
  613. //根据故障部位 数组
  614. $fault_arr = [$fault_right_list[0]['fault_id'],$fault_right_list[1]['fault_id'],$fault_right_list[2]['fault_id']];
  615. //查找故障现象 数组
  616. $partent_fault_id = Fault::where(['fault_id'=>['in',$fault_arr],'sim_type'=>$rows['sim_type']])->column('parent_fault_id');
  617. $arr1= [];
  618. foreach ($partent_fault_id as $key => $value) {
  619. $arr1[] = [
  620. 'gzxz_id' => $value,
  621. 'xianxian_content' => $row['xianxian_content_name'],
  622. 'other_report' => $other_report
  623. ];
  624. }
  625. $this->view->assign('other_report', $other_report);
  626. $this->view->assign('partent_fault_id', $arr1);
  627. $this->view->assign('row', $row);
  628. return $this->view->fetch();
  629. }
  630. }