Practice.php 32 KB

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