Practice.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  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. $other_content = [];
  191. Db::startTrans();
  192. try {
  193. //更新考试结束时间
  194. $row->end_time = date('Y-m-d H:i:s');
  195. $row->endtime = time();
  196. $row->exam_status = 5;
  197. $row->other_report = $params['other_report'];
  198. $result = $row->save();
  199. $info = $this->exam_model->where(['exam_id'=>$ids])->find();
  200. //更新故障是否正确
  201. $fault_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1])->select();
  202. if(!empty($fault_list)){
  203. foreach ($fault_list as $k =>$t){
  204. $answer_right = 2;
  205. if(!empty($t['sim_fault_question_value']) && !empty($t['sim_fault_answer_value'])){
  206. if($t['sim_fault_question_value']!=$t['sim_fault_answer_value'] ){
  207. //真实故障id 0002GZBW0001 薄膜开关FPC排线
  208. if($t['sim_fault_answer_value']=='00000000' && $t['fault_id'] !='0002GZBW0001'){
  209. $answer_right=2;
  210. }
  211. $answer_right=1;
  212. }
  213. }
  214. Db::name('real_exam_fault')->where(['ref_id'=>$t['ref_id']])->update(['answer_right'=>$answer_right]);
  215. }
  216. }
  217. //计算得分,故障是否有扣分 扣分制
  218. $fault_right_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1,'answer_right'=>['>',0]])->select();
  219. if(!empty($fault_right_list)){
  220. if($fault_right_list[0]['answer_right']==1){
  221. $fault_one_score = 0;
  222. }
  223. if($fault_right_list[1]['answer_right']==1){
  224. $fault_two_score = 0;
  225. }
  226. if($fault_right_list[2]['answer_right']==1){
  227. $fault_three_score = 0;
  228. }
  229. }
  230. $fault_right_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1])->select();
  231. //根据故障部位,查找故障现象
  232. $fault_arr = [$fault_right_list[0]['fault_id'],$fault_right_list[1]['fault_id'],$fault_right_list[2]['fault_id']];
  233. //根据故障部位查找,匹配的排除方法
  234. $paichu_arr = Report::where(['bw_id'=>['in',$fault_arr],'sim_type'=>$info['sim_type']])->column('pc_id');
  235. // //根据故障部位查找,匹配可能原因
  236. // $yy_arr = Report::where(['bw_id'=>['in',$fault_arr],'sim_type'=>$info['sim_type']])->column('yy_id');
  237. //查找故障现象 数组
  238. $partent_fault_id = Fault::where(['fault_id'=>['in',$fault_arr],'sim_type'=>$info['sim_type']])->column('parent_fault_id');
  239. //根据故障部位查找,匹配可能原因
  240. $yy_arr = Fault::where(['parent_fault_id'=>['in',$partent_fault_id],'sim_type'=>$info['sim_type'],'fault_type'=>2])->column('fault_id');
  241. //获取数组
  242. $other_report = json_decode($params['other_report'],true);
  243. if(!empty($other_report)){
  244. foreach ($other_report as $key => $em){
  245. //故障现象
  246. $xianxian_arr[] = $em['xx_id'];
  247. }
  248. foreach ($partent_fault_id as $k1 =>$t){
  249. $kscore = 0;
  250. if(!in_array($t,$xianxian_arr)){
  251. $xianxian_score = 5+$xianxian_score;
  252. $xianxian_content[] = [
  253. 'gzxz_id'=>$t,
  254. 'cx_id'=>$t,
  255. 'cx_type'=>'故障现象少写',
  256. 'cx_name'=>Fault::where(['fault_id'=>$t])->value('name'),
  257. 'cx_score'=>-5,
  258. ];
  259. $other_content[] = [
  260. 'gzxz_id'=>$t,
  261. 'cx_score'=>-5,
  262. ];
  263. }else{
  264. // echo "存在里面".$t."###".$k1."<br/>";
  265. $t1= $t;
  266. $jian = '';
  267. foreach ($other_report as $ky => $item) {
  268. if ($item['xx_id'] == $t) {
  269. $jian = $ky;
  270. }
  271. }
  272. // 故障部位算分 start
  273. //获取故障部位
  274. $buweiarr = Fault::where(['parent_fault_id'=>$t,'sim_type'=>$info['sim_type'],'fault_type'=>['in',[3,30]],'fault_state'=>0])
  275. ->column('fault_id');
  276. if(!in_array($other_report[$jian]['bw_id'],$buweiarr)){
  277. $buwei_score = 1+$buwei_score;
  278. $kscore = 1+$kscore;
  279. $xianxian_content[] = [
  280. 'gzxz_id'=>$t,
  281. 'cx_id'=>$other_report[$jian]['bw_id'],
  282. 'cx_type'=>'故障部位错写',
  283. 'cx_name'=>Fault::where(['fault_id'=>$other_report[$jian]['bw_id']])->value('name'),
  284. ];
  285. }
  286. //出题故障部位和获取的故障部位里面有重复的
  287. // 获取两个数组的交集
  288. $intersection = array_intersect($buweiarr, $fault_arr);
  289. // halt($intersection);
  290. foreach($intersection as $kk =>$va){
  291. if($other_report[$jian]['bw_id']!=$va){
  292. $buwei_score = 1+$buwei_score;
  293. $kscore = 1+$kscore;
  294. $xianxian_content[] = [
  295. 'gzxz_id'=>$t,
  296. 'cx_id'=>$va,
  297. 'cx_type'=>'故障部位少写',
  298. 'cx_name'=>Fault::where(['fault_id'=>$va])->value('name'),
  299. ];
  300. }
  301. }
  302. unset($va);
  303. // 故障部位算分 end
  304. // 排除方法算分 start
  305. $paichuarr = Fault::where(['parent_fault_id'=>$t,'sim_type'=>$info['sim_type'],'fault_type'=>4,'fault_state'=>0])
  306. ->column('fault_id');
  307. if(!in_array($other_report[$jian]['pc_id'],$paichuarr)){
  308. $fangfa_score = 1+$fangfa_score;
  309. $kscore = 1+$kscore;
  310. $xianxian_content[] = [
  311. 'gzxz_id'=>$t,
  312. 'cx_id'=>$other_report[$jian]['pc_id'],
  313. 'cx_type'=>'排除方法错写',
  314. 'cx_name'=>Fault::where(['fault_id'=>$other_report[$jian]['pc_id']])->value('name'),
  315. ];
  316. }
  317. //出题排除方法和获取的排除方法里面有重复的
  318. // 获取两个数组的交集
  319. $intersection1 = array_intersect($paichuarr, $paichu_arr);
  320. foreach($intersection1 as $kk1 =>$va1){
  321. if($other_report[$jian]['pc_id']!=$va1){
  322. $fangfa_score = 1+$fangfa_score;
  323. $kscore = 1+$kscore;
  324. $xianxian_content[] = [
  325. 'gzxz_id'=>$t,
  326. 'cx_id'=>$va1,
  327. 'cx_type'=>'排除方法少写',
  328. 'cx_name'=>Fault::where(['fault_id'=>$va1])->value('name'),
  329. ];
  330. }
  331. }
  332. unset($va1);
  333. // 排除方法算分 end
  334. // 可能原因算分 start
  335. $yuanyinarr = Fault::where(['parent_fault_id'=>$t,'sim_type'=>$info['sim_type'],'fault_type'=>2,'fault_state'=>0])
  336. ->column('fault_id');
  337. foreach (explode(',',$other_report[$jian]['yy_id']) as $key => $value) {
  338. if(!in_array($value,$yuanyinarr)){
  339. $yuanyin_socre = 1+$yuanyin_socre;
  340. $kscore = 1+$kscore;
  341. $xianxian_content[] = [
  342. 'gzxz_id'=>$t,
  343. 'cx_id'=>$value,
  344. 'cx_type'=>'可能原因错写',
  345. 'cx_name'=>Fault::where(['fault_id'=>$value])->value('name'),
  346. ];
  347. }
  348. }
  349. //出题可能原因和获取的可能原因里面有重复的
  350. // 获取两个数组的交集
  351. $intersection2 = array_intersect($yy_arr, $yuanyinarr);
  352. $intersection22 = array_intersect($intersection2, explode(',',$other_report[$jian]['yy_id']));
  353. foreach($yuanyinarr as $kk2 =>$va2){
  354. if(!in_array($va2,$intersection22)){
  355. $yuanyin_socre = 1+$yuanyin_socre;
  356. $kscore = 1+$kscore;
  357. $xianxian_content[] = [
  358. 'gzxz_id'=>$t,
  359. 'cx_id'=>$va2,
  360. 'cx_type'=>'可能原因少写',
  361. 'cx_name'=>Fault::where(['fault_id'=>$va2])->value('name'),
  362. ];
  363. }
  364. }
  365. unset($va2);
  366. // 可能原因算分 end
  367. if($kscore>5){
  368. $kscore = '-5';
  369. }else if($kscore>0){
  370. $kscore = '-'.$kscore;
  371. }else{
  372. $kscore=0;
  373. }
  374. // echo $t1."####".$kscore."<br/>";
  375. $other_content[] = [
  376. 'gzxz_id'=>$t,
  377. 'cx_score'=>$kscore,
  378. ];
  379. }
  380. }
  381. unset($em);
  382. // echo "<pre>";
  383. // print_r($xianxian_content);
  384. // echo "<pre>";
  385. // print_r($other_content);
  386. // die();
  387. }else{
  388. foreach ($partent_fault_id as $key => $em){
  389. $xianxian_score = 5+$xianxian_score;
  390. $xianxian_content[] = [
  391. 'gzxz_id'=>$em,
  392. 'cx_id'=>$em,
  393. 'cx_type'=>'未作答',
  394. // 'cx_name'=>Fault::where(['fault_id'=>$em])->value('name'),
  395. 'cx_name'=>'',
  396. ];
  397. $other_content[] = [
  398. 'gzxz_id'=>$em,
  399. 'cx_score'=>-5,
  400. ];
  401. }
  402. unset($em);
  403. }
  404. // //获取数组
  405. // $other_report = json_decode($params['other_report'],true);
  406. // if(!empty($other_report)){
  407. // foreach ($other_report as $key => $em){
  408. // //故障现象
  409. // $xianxian_arr[] = $em['xx_id'];
  410. // //故障部位
  411. // $buwei_arr[] = $em['bw_id'];
  412. // //可能原因
  413. // foreach(explode(',',$em['yy_id']) as $k3 =>$t13){
  414. // $yuanyin_arr[] = $t13;
  415. // }
  416. // //排除方法
  417. // $fangfa_arr[] = $em['pc_id'];
  418. // }
  419. // }
  420. // //故障现象 分数 start
  421. // foreach ($partent_fault_id as $k1 =>$t){
  422. // if(!in_array($t,$xianxian_arr)){
  423. // $xianxian_score = 1+$xianxian_score;
  424. // $xianxian_content[] = [
  425. // 'cx_id'=>$t,
  426. // 'cx_type'=>'少写',
  427. // 'cx_name'=>Fault::where(['fault_id'=>$t])->value('name'),
  428. // ];
  429. // }
  430. // }
  431. // foreach ($xianxian_arr as $k2 =>$t2){
  432. // if(!in_array($t2,$partent_fault_id)){
  433. // $xianxian_score = 1+$xianxian_score;
  434. // $xianxian_content[] = [
  435. // 'cx_id'=>$t2,
  436. // 'cx_type'=>'错写',
  437. // 'cx_name'=>Fault::where(['fault_id'=>$t2])->value('name'),
  438. // ];
  439. // }
  440. // }
  441. // //故障现象 end
  442. // //故障部位 start
  443. // foreach ($fault_arr as $k11 =>$t11){
  444. // if(!in_array($t11,$buwei_arr)){
  445. // $buwei_score = 1+$buwei_score;
  446. // $buwei_content[] = [
  447. // 'cx_id'=>$t11,
  448. // 'cx_type'=>'少写',
  449. // 'cx_name'=>Fault::where(['fault_id'=>$t11])->value('name'),
  450. // ];
  451. // }
  452. // }
  453. // foreach ($buwei_arr as $k12 =>$t12){
  454. // if(!empty($t12) && !in_array($t12,$fault_arr)){
  455. // //错写
  456. // $buwei_score = 1+$buwei_score;
  457. // $buwei_content[] = [
  458. // 'cx_id'=>$t12,
  459. // 'cx_type'=>'错写',
  460. // 'cx_name'=>Fault::where(['fault_id'=>$t12])->value('name'),
  461. // ];
  462. // }
  463. // }
  464. // //故障部位 end
  465. // //排除方法 start
  466. // //循环固定的排除方法,匹配作答的排除方法
  467. // foreach ($paichu_arr as $k21 =>$t21){
  468. // if(!in_array($t21,$fangfa_arr)){
  469. // $fangfa_score = 1+$fangfa_score;
  470. // $fangfa_content[] = [
  471. // 'cx_id'=>$t21,
  472. // 'cx_type'=>'少写',
  473. // 'cx_name'=>Fault::where(['fault_id'=>$t21])->value('name'),
  474. // ];
  475. // }
  476. // }
  477. // //循环作答的排除方法,,匹配固定的排除方法
  478. // foreach ($fangfa_arr as $k22 =>$t22){
  479. // if(!empty($t22) && !in_array($t22,$paichu_arr)){
  480. // $fangfa_score = 1+$fangfa_score;
  481. // $fangfa_content[] = [
  482. // 'cx_id'=>$t22,
  483. // 'cx_type'=>'错写',
  484. // 'cx_name'=>Fault::where(['fault_id'=>$t22])->value('name'),
  485. // ];
  486. // }
  487. // }
  488. // //排除方法 end
  489. // //可能原因 start
  490. // //循环固定的可能原因,匹配作答的可能原因
  491. // foreach ($yy_arr as $k31 =>$t31){
  492. // if(!in_array($t31,$yuanyin_arr)){
  493. // // echo $t31."<br/>";
  494. // $yuanyin_socre = 1+$yuanyin_socre;
  495. // $yuanyin_content[] = [
  496. // 'cx_id'=>$t31,
  497. // 'cx_type'=>'少写',
  498. // 'cx_name'=>Fault::where(['fault_id'=>$t31])->value('name'),
  499. // ];
  500. // }
  501. // }
  502. // //循环作答的排除方法,,匹配固定的排除方法
  503. // foreach ($yuanyin_arr as $k32 =>$t32){
  504. // if(!empty($t32) && !in_array($t32,$yy_arr)){
  505. // $yuanyin_socre = 1+$yuanyin_socre;
  506. // $yuanyin_content[] = [
  507. // 'cx_id'=>$t32,
  508. // 'cx_type'=>'错写',
  509. // 'cx_name'=>Fault::where(['fault_id'=>$t32])->value('name'),
  510. // ];
  511. // }
  512. // }
  513. // $uniqueArray = array_unique($yuanyin_arr);
  514. // $diff = array_diff_assoc($yuanyin_arr, $uniqueArray);
  515. // if(!empty($diff)){
  516. // foreach ($diff as $k323 =>$t323){
  517. // $yuanyin_socre = 1+$yuanyin_socre;
  518. // $yuanyin_content[] = [
  519. // 'cx_id'=>$t323,
  520. // 'cx_type'=>'错写',
  521. // 'cx_name'=>Fault::where(['fault_id'=>$t323])->value('name'),
  522. // ];
  523. // }
  524. // }
  525. // //可能原因 end
  526. $weixiu_score = $xianxian_score+$yuanyin_socre+$buwei_score+$fangfa_score;
  527. if($weixiu_score>15){
  528. $weixiu_score = 15;
  529. }
  530. //是否超时
  531. $overtime_fen = intval((time()-$info['countdown_time']) / 60);
  532. if($overtime_fen>=10){
  533. $overtime_score = 10;
  534. }else if($overtime_fen>0 && $overtime_fen<10){
  535. $overtime_score = $overtime_fen ;
  536. }else{
  537. $overtime_score =0;
  538. }
  539. $fault_score = $score-$fault_one_score-$fault_two_score-$fault_three_score-$weixiu_score-$overtime_score;
  540. //更新考试结果表
  541. $params['exam_id'] = $ids;
  542. $params['total'] = $fault_score;//得分;
  543. $params['fault_one_score'] = $fault_one_score;//得分;
  544. $params['fault_two_score'] = $fault_two_score;//得分;
  545. $params['fault_three_score'] = $fault_three_score;//得分;
  546. $params['xianxian_score'] = $xianxian_score;//得分;
  547. $params['xianxian_content'] = json_encode($xianxian_content);//错题;
  548. $params['yuanyin_socre'] = $yuanyin_socre;//得分;
  549. $params['yuanyin_content'] = json_encode($yuanyin_content);//错题;
  550. $params['buwei_score'] = $buwei_score;//得分;
  551. $params['buwei_content'] = json_encode($buwei_content);//错题;
  552. $params['fangfa_score'] = $fangfa_score;//得分;
  553. $params['fangfa_content'] = json_encode($fangfa_content);//错题;
  554. $params['other_jielun'] = json_encode($other_content);//每个答题的得分
  555. $params['overtime_score'] = $overtime_score;//得分;
  556. Db::name('real_exam_score')->insert($params);
  557. $this->exam_model->where(['exam_id'=>$ids])->update(['total_score'=>$fault_score]);
  558. Db::commit();
  559. } catch (ValidateException|PDOException|Exception $e) {
  560. Db::rollback();
  561. $this->error($e->getMessage());
  562. }
  563. if ($result === false) {
  564. $this->error(__('No rows were inserted'));
  565. }
  566. $this->success('交卷成功','/admin/student/practice/analysis/ids/'.$row['exam_id']);
  567. }
  568. if(empty($row->starttime)){
  569. $row->start_time = date('Y-m-d H:i:s');
  570. $row->starttime = time();
  571. $row->exam_status = 4;
  572. $row->save();
  573. }
  574. $isloading =1;
  575. if(empty($row->other_replace)){
  576. $isloading = 0;
  577. $row->other_replace = '[{"fault_id":"","request_status":"0"}]';
  578. }
  579. $row->other_report_text = !empty($row->other_report) ? json_decode($row->other_report,true) : [];
  580. //还未开始练习
  581. $row->limit_duration = $this->model->where(['exam_collection_id'=>$row['exam_collection_id']])->value('limit_duration');
  582. if(empty($row->starttime)){
  583. $timer = 60*$row->limit_duration;
  584. }else{
  585. $timer = $row->limit_duration*60 - abs(time() - $row->starttime);
  586. }
  587. if(empty($row->countdown_time)){
  588. $duration = 10+$row->limit_duration;
  589. $this->exam_model->where('exam_id',$ids)->update(['countdown_time'=>strtotime(date('Y-m-d H:i:s', strtotime('+'.$duration.' minute',$row->starttime)))]);
  590. }
  591. $departmentdata = [];
  592. $departmentdata = Fault::where(['replace_part'=>1,'sim_type'=>$row->sim_type])->order('fault_id asc')->select();
  593. $this->view->assign('departmentdata', $departmentdata);
  594. //故障现象
  595. $xianxiang = Fault::where(['fault_type'=>1,'sim_type'=>$row->sim_type])->select();
  596. $this->view->assign('xianxiang', $xianxiang);
  597. $row->replace_list =Db::name('real_exam_comp_request')->where(['exam_id'=>$ids])->select();
  598. $this->assignConfig('ids',$ids);
  599. $this->assignConfig('timer',$timer);
  600. $this->assignConfig('isloading',$isloading);
  601. $this->view->assign('row', $row);
  602. return $this->view->fetch();
  603. }
  604. public function analysis($ids = null)
  605. {
  606. if ($this->request->isPost()) {
  607. $params = $this->request->post('row/a');
  608. //计算总分到学员考试表
  609. $this->success('操作成功','/admin/student/practice/index');
  610. }
  611. $row = Db::name('real_exam_score')->where('exam_id', $ids)->find();
  612. if (!$row) {
  613. $this->error(__('No Results were found'));
  614. }
  615. $rows = $this->exam_model->get($ids);
  616. $row['seat_id'] = $rows->seat_id;
  617. $row['user_nickname'] = $rows->user_nickname;
  618. $row['user_username'] = $rows->user_username;
  619. $row['user_depart_id'] = $rows->user_depart_id;
  620. $row['user_depart_name'] = Department::where('id',$rows->user_depart_id)->value('name');
  621. $row['start_time'] = $rows->start_time;
  622. $row['end_time'] = $rows->end_time;
  623. $fault_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1])->select();
  624. $row['fault_name_one'] = !empty($fault_list[0]['fault_id']) ? Fault::where('fault_id',$fault_list[0]['fault_id'])->value('name'):'';
  625. $row['fault_name_two'] = !empty($fault_list[1]['fault_id']) ? Fault::where('fault_id',$fault_list[1]['fault_id'])->value('name'):'';
  626. $row['fault_name_three'] = !empty($fault_list[2]['fault_id']) ? Fault::where('fault_id',$fault_list[2]['fault_id'])->value('name'):'';
  627. $row['fault_score'] = 75-$row['fault_one_score']-$row['fault_two_score']-$row['fault_three_score'];
  628. $report_score = 15-$row['xianxian_score']-$row['yuanyin_socre']-$row['buwei_score']-$row['fangfa_score'];
  629. $row['report_score'] = $report_score>0?$report_score:0;
  630. $row['xianxian_content_name'] = '';
  631. if(!empty($row['xianxian_content']))
  632. {
  633. $row['xianxian_content_name'] = json_decode($row['xianxian_content'],true);
  634. }
  635. $row['yuanyin_content_name'] = '';
  636. if(!empty($row['yuanyin_content']))
  637. {
  638. $row['yuanyin_content_name'] = json_decode($row['yuanyin_content'],true);
  639. }
  640. $row['buwei_content_name'] = '';
  641. if(!empty($row['buwei_content']))
  642. {
  643. $row['buwei_content_name'] = json_decode($row['buwei_content'],true);
  644. }
  645. $row['fangfa_content_name'] = '';
  646. if(!empty($row['fangfa_content']))
  647. {
  648. $row['fangfa_content_name'] = json_decode($row['fangfa_content'],true);
  649. }
  650. $other_report = !empty($row['other_report']) ? json_decode($row['other_report'],true):[];
  651. $other_jielun = !empty($row['other_jielun']) ? json_decode($row['other_jielun'],true):[];
  652. $fault_right_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1])->select();
  653. //根据故障部位 数组
  654. $fault_arr = [$fault_right_list[0]['fault_id'],$fault_right_list[1]['fault_id'],$fault_right_list[2]['fault_id']];
  655. //查找故障现象 数组
  656. $partent_fault_id = Fault::where(['fault_id'=>['in',$fault_arr],'sim_type'=>$rows['sim_type']])->column('parent_fault_id');
  657. $arr1= [];
  658. foreach ($partent_fault_id as $key => $value) {
  659. $arr1[] = [
  660. 'gzxz_id' => $value,
  661. 'xianxian_content' => $row['xianxian_content_name'],
  662. 'other_report' => $other_report,
  663. 'other_jielun' => $other_jielun,
  664. ];
  665. }
  666. $this->view->assign('other_report', $other_report);
  667. $this->view->assign('partent_fault_id', $arr1);
  668. $this->view->assign('row', $row);
  669. return $this->view->fetch();
  670. }
  671. }