Collection.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888
  1. <?php
  2. namespace app\admin\controller\student;
  3. use app\common\controller\Backend;
  4. use app\common\model\Config as ConfigModel;
  5. use app\admin\model\Report;
  6. use app\admin\model\Fault;
  7. use think\exception\DbException;
  8. use think\exception\PDOException;
  9. use think\exception\ValidateException;
  10. use think\response\Json;
  11. use think\Db;
  12. use think\Env;
  13. /**
  14. *
  15. * @icon fa fa-circle-o
  16. */
  17. class Collection 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. protected $noNeedLogin = ['addreport','editreport','delreport','countdown'];
  27. public function _initialize()
  28. {
  29. parent::_initialize();
  30. $this->model = new \app\admin\model\teacher\Collection;
  31. $this->exam_model = new \app\admin\model\teacher\Exams;
  32. $this->assignConfig('sim_sim_type', ConfigModel::getSimTypeList());
  33. $this->assignConfig('sim_question_setting_method', ConfigModel::getSimQuestionList());
  34. $this->whereExtend['exam_collection_type'] = 3;
  35. $this->whereExtend['exam_collection_state'] = 2;
  36. $this->assignConfig('sim_sim_type', ConfigModel::getSimTypeList());
  37. $groupIds = $this->auth->getGroupIds();
  38. //学员查看自己区队的考试集合
  39. if(in_array(8, $groupIds)){
  40. $departid = $this->auth->depart_id;
  41. $this->whereExtend[] = ['exp',Db::raw("FIND_IN_SET($departid,depart_ids)")];
  42. }
  43. }
  44. /**
  45. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  46. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  47. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  48. */
  49. /**
  50. * 查看
  51. *
  52. * @return string|Json
  53. * @throws \think\Exception
  54. * @throws DbException
  55. */
  56. public function index()
  57. {
  58. $isset = $this->model->alias('z')
  59. ->join('real_exam r','z.exam_collection_id=r.exam_collection_id','left')
  60. ->where('z.exam_collection_type=3 and z.exam_collection_state=2 and r.endtime=0 and r.user_id='.$this->auth->id)->find();
  61. if(empty($isset)){
  62. //提示页面,没有开始的考试
  63. return $this->view->fetch('tishi');
  64. }else{
  65. echo "<script>location.href='/admin/student/collection/into/ids/".$isset['exam_collection_id']."'</script>";
  66. }
  67. die();
  68. //设置过滤方法
  69. $this->request->filter(['strip_tags', 'trim']);
  70. if (false === $this->request->isAjax()) {
  71. return $this->view->fetch();
  72. }
  73. //如果发送的来源是 Selectpage,则转发到 Selectpage
  74. if ($this->request->request('keyField')) {
  75. return $this->selectpage();
  76. }
  77. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  78. $list = $this->model
  79. ->where($where)->where($this->whereExtend)
  80. ->order($sort, $order)
  81. ->paginate($limit);
  82. foreach ($list as $k => $v){
  83. $exam_isset = $this->exam_model->where(['user_id'=>$this->auth->id,'exam_collection_id'=>$v['exam_collection_id'],'exam_collection_type'=>3,'endtime'=>['>',0]])->find();
  84. if(isset($exam_isset)){
  85. $v->is_user_examed = 1;
  86. }else{
  87. $v->is_user_examed = 0;
  88. }
  89. }
  90. unset($v);
  91. $result = ['total' => $list->total(), 'rows' => $list->items()];
  92. return json($result);
  93. }
  94. //进入考试
  95. public function into($ids = null)
  96. {
  97. $row = $this->model->get($ids);
  98. if(!$row){
  99. $this->error('未找到记录');
  100. }
  101. $info = $this->exam_model->where(['user_id'=>$this->auth->id,'exam_collection_id'=>$ids,'exam_collection_type'=>3,'endtime'=>0])->find();
  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/collection/examing/ids/".$info['exam_id']."'</script>";
  132. die();
  133. }
  134. $this->view->assign('info', $info);
  135. $this->view->assign('row', $row);
  136. $this->assignConfig('exam_id', $info['exam_id']);
  137. $this->assignConfig('url_type', config('site.url_type'));
  138. $this->assignConfig('is_fault', Env::get('app.is_fault'));
  139. return $this->view->fetch();
  140. }
  141. public function examing($ids = null)
  142. {
  143. $row = $this->exam_model->get($ids);
  144. if(!$row){
  145. $this->error('未找到记录');
  146. }
  147. if ($this->request->isPost()) {
  148. //先请求接口判断,再进行处理
  149. if(Env::get('app.is_fault')){
  150. $url = config('site.url_type').'/sim/real-exam/student/exam/submit/'.$ids;
  151. $ret = json_decode(send_get($url),true);
  152. if($ret['code']!=200){
  153. $this->error($ret['msg']);
  154. }
  155. }
  156. //计算分数,保存记录
  157. $params = $this->request->post('row/a');
  158. $result = false;
  159. $score = 100;
  160. $fault_one_score = 25;
  161. $fault_two_score = 25;
  162. $fault_three_score = 25;
  163. //故障现象
  164. $xianxian_score = 0;
  165. $xianxian_arr = [];
  166. $xianxian_content = [];
  167. //故障部位
  168. $buwei_score= 0;
  169. $buwei_arr = [];
  170. $buwei_content = [];
  171. //可能原因
  172. $yuanyin_socre= 0;
  173. $yuanyin_arr = [];
  174. $yuanyin_content = [];
  175. //排除方法
  176. $fangfa_score= 0;
  177. $fangfa_arr = [];
  178. $fangfa_content = [];
  179. Db::startTrans();
  180. try {
  181. //更新考试结束时间
  182. $row->end_time = date('Y-m-d H:i:s');
  183. $row->endtime = time();
  184. $row->exam_status = 5;
  185. $row->other_report = $params['other_report'];
  186. $result = $row->save();
  187. $info = $this->exam_model->where(['exam_id'=>$ids])->find();
  188. //更新故障是否正确
  189. $fault_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1])->select();
  190. if(!empty($fault_list)){
  191. foreach ($fault_list as $k =>$t){
  192. $answer_right = 2;
  193. if(!empty($t['sim_fault_question_value']) && !empty($t['sim_fault_answer_value'])){
  194. if($t['sim_fault_question_value']!=$t['sim_fault_answer_value'] ){
  195. //真实故障id 0002GZBW0001 薄膜开关FPC排线
  196. if($t['sim_fault_answer_value']=='00000000' && $t['fault_id'] !='0002GZBW0001'){
  197. $answer_right=2;
  198. }
  199. $answer_right=1;
  200. }
  201. }
  202. Db::name('real_exam_fault')->where(['ref_id'=>$t['ref_id']])->update(['answer_right'=>$answer_right]);
  203. }
  204. }
  205. //计算得分,故障是否有扣分 扣分制
  206. $fault_right_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1,'answer_right'=>['>',0]])->select();
  207. if(!empty($fault_right_list)){
  208. if($fault_right_list[0]['answer_right']==1){
  209. $fault_one_score = 0;
  210. }
  211. if($fault_right_list[1]['answer_right']==1){
  212. $fault_two_score = 0;
  213. }
  214. if($fault_right_list[2]['answer_right']==1){
  215. $fault_three_score = 0;
  216. }
  217. }
  218. $fault_right_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1])->select();
  219. //根据故障部位 数组
  220. $fault_arr = [$fault_right_list[0]['fault_id'],$fault_right_list[1]['fault_id'],$fault_right_list[2]['fault_id']];
  221. //根据故障部位查找,匹配的排除方法
  222. $paichu_arr = Report::where(['bw_id'=>['in',$fault_arr],'sim_type'=>$info['sim_type']])->column('pc_id');
  223. //查找故障现象 数组
  224. $partent_fault_id = Fault::where(['fault_id'=>['in',$fault_arr],'sim_type'=>$info['sim_type']])->column('parent_fault_id');
  225. //根据故障部位查找,匹配可能原因
  226. $yy_arr = Fault::where(['parent_fault_id'=>['in',$partent_fault_id],'sim_type'=>$info['sim_type'],'fault_type'=>2])->column('fault_id');
  227. //获取数组
  228. $other_report = json_decode($params['other_report'],true);
  229. if(!empty($other_report)){
  230. foreach ($other_report as $key => $em){
  231. //故障现象
  232. $xianxian_arr[] = $em['xx_id'];
  233. }
  234. foreach ($partent_fault_id as $k1 =>$t){
  235. if(!in_array($t,$xianxian_arr)){
  236. $xianxian_score = 5+$xianxian_score;
  237. $xianxian_content[] = [
  238. 'gzxz_id'=>$t,
  239. 'cx_id'=>$t,
  240. 'cx_type'=>'故障现象少写',
  241. 'cx_name'=>Fault::where(['fault_id'=>$t])->value('name'),
  242. ];
  243. }else{
  244. // echo "存在里面".$t."###".$k1."<br/>";
  245. $jian = '';
  246. foreach ($other_report as $ky => $item) {
  247. if ($item['xx_id'] == $t) {
  248. $jian = $ky;
  249. }
  250. }
  251. // echo $jian."<br/>";
  252. // 故障部位算分 start
  253. //获取故障部位
  254. $buweiarr = Fault::where(['parent_fault_id'=>$t,'sim_type'=>$info['sim_type'],'fault_type'=>['in',[3,30]],'fault_state'=>0])
  255. ->column('fault_id');
  256. if(!in_array($other_report[$jian]['bw_id'],$buweiarr)){
  257. $buwei_score = 1+$buwei_score;
  258. $xianxian_content[] = [
  259. 'gzxz_id'=>$t,
  260. 'cx_id'=>$other_report[$jian]['bw_id'],
  261. 'cx_type'=>'故障部位错写',
  262. 'cx_name'=>Fault::where(['fault_id'=>$other_report[$jian]['bw_id']])->value('name'),
  263. ];
  264. }
  265. //出题故障部位和获取的故障部位里面有重复的
  266. // 获取两个数组的交集
  267. $intersection = array_intersect($buweiarr, $fault_arr);
  268. // halt($intersection);
  269. foreach($intersection as $kk =>$va){
  270. if($other_report[$jian]['bw_id']!=$va){
  271. $buwei_score = 1+$buwei_score;
  272. $xianxian_content[] = [
  273. 'gzxz_id'=>$t,
  274. 'cx_id'=>$va,
  275. 'cx_type'=>'故障部位少写',
  276. 'cx_name'=>Fault::where(['fault_id'=>$va])->value('name'),
  277. ];
  278. }
  279. }
  280. unset($va);
  281. // 故障部位算分 end
  282. // 排除方法算分 start
  283. $paichuarr = Fault::where(['parent_fault_id'=>$t,'sim_type'=>$info['sim_type'],'fault_type'=>4,'fault_state'=>0])
  284. ->column('fault_id');
  285. if(!in_array($other_report[$jian]['pc_id'],$paichuarr)){
  286. $fangfa_score = 1+$fangfa_score;
  287. $xianxian_content[] = [
  288. 'gzxz_id'=>$t,
  289. 'cx_id'=>$other_report[$jian]['pc_id'],
  290. 'cx_type'=>'排除方法错写',
  291. 'cx_name'=>Fault::where(['fault_id'=>$other_report[$jian]['pc_id']])->value('name'),
  292. ];
  293. }
  294. //出题排除方法和获取的排除方法里面有重复的
  295. // 获取两个数组的交集
  296. $intersection1 = array_intersect($paichuarr, $paichu_arr);
  297. foreach($intersection1 as $kk1 =>$va1){
  298. if($other_report[$jian]['pc_id']!=$va1){
  299. $fangfa_score = 1+$fangfa_score;
  300. $xianxian_content[] = [
  301. 'gzxz_id'=>$t,
  302. 'cx_id'=>$va1,
  303. 'cx_type'=>'排除方法少写',
  304. 'cx_name'=>Fault::where(['fault_id'=>$va1])->value('name'),
  305. ];
  306. }
  307. }
  308. unset($va1);
  309. // 排除方法算分 end
  310. // 可能原因算分 start
  311. $yuanyinarr = Fault::where(['parent_fault_id'=>$t,'sim_type'=>$info['sim_type'],'fault_type'=>2,'fault_state'=>0])
  312. ->column('fault_id');
  313. foreach (explode(',',$other_report[$jian]['yy_id']) as $key => $value) {
  314. if(!in_array($value,$yuanyinarr)){
  315. $yuanyin_socre = 1+$yuanyin_socre;
  316. $xianxian_content[] = [
  317. 'gzxz_id'=>$t,
  318. 'cx_id'=>$value,
  319. 'cx_type'=>'可能原因错写',
  320. 'cx_name'=>Fault::where(['fault_id'=>$value])->value('name'),
  321. ];
  322. }
  323. }
  324. //出题可能原因和获取的可能原因里面有重复的
  325. // 获取两个数组的交集
  326. $intersection2 = array_intersect($yy_arr, $yuanyinarr);
  327. $intersection22 = array_intersect($intersection2, explode(',',$other_report[$jian]['yy_id']));
  328. foreach($yuanyinarr as $kk2 =>$va2){
  329. if(!in_array($va2,$intersection22)){
  330. $yuanyin_socre = 1+$yuanyin_socre;
  331. $xianxian_content[] = [
  332. 'gzxz_id'=>$t,
  333. 'cx_id'=>$va2,
  334. 'cx_type'=>'可能原因少写',
  335. 'cx_name'=>Fault::where(['fault_id'=>$va2])->value('name'),
  336. ];
  337. }
  338. }
  339. unset($va2);
  340. // 可能原因算分 end
  341. }
  342. }
  343. unset($em);
  344. }else{
  345. foreach ($partent_fault_id as $key => $em){
  346. $xianxian_score = 5+$xianxian_score;
  347. $xianxian_content[] = [
  348. 'gzxz_id'=>$em,
  349. 'cx_id'=>$em,
  350. 'cx_type'=>'故障现象少写',
  351. 'cx_name'=>Fault::where(['fault_id'=>$em])->value('name'),
  352. ];
  353. }
  354. unset($em);
  355. }
  356. // echo "故障现象得分:".$xianxian_score."<br/>";
  357. // echo "故障部位得分:".$buwei_score."<br/>";
  358. // echo "排除方法得分:".$fangfa_score."<br/>";
  359. // echo "可能原因得分:".$yuanyin_socre."<br/>";
  360. // echo "<pre>";
  361. // print_r($xianxian_content);
  362. // die();
  363. // $other_report = json_decode($params['other_report'],true);
  364. // if(!empty($other_report)){
  365. // foreach ($other_report as $key => $em){
  366. // //故障现象
  367. // $xianxian_arr[] = $em['xx_id'];
  368. // //故障部位
  369. // $buwei_arr[] = $em['bw_id'];
  370. // //可能原因
  371. // foreach(explode(',',$em['yy_id']) as $k3 =>$t13){
  372. // $yuanyin_arr[] = $t13;
  373. // }
  374. // //排除方法
  375. // $fangfa_arr[] = $em['pc_id'];
  376. // }
  377. // }
  378. // //故障现象 分数 start
  379. // foreach ($partent_fault_id as $k1 =>$t){
  380. // if(!in_array($t,$xianxian_arr)){
  381. // $xianxian_score = 1+$xianxian_score;
  382. // $xianxian_content[] = [
  383. // 'cx_id'=>$t,
  384. // 'cx_type'=>'少写',
  385. // 'cx_name'=>Fault::where(['fault_id'=>$t])->value('name'),
  386. // ];
  387. // }
  388. // }
  389. // foreach ($xianxian_arr as $k2 =>$t2){
  390. // if(!in_array($t2,$partent_fault_id)){
  391. // $xianxian_score = 1+$xianxian_score;
  392. // $xianxian_content[] = [
  393. // 'cx_id'=>$t2,
  394. // 'cx_type'=>'错写',
  395. // 'cx_name'=>Fault::where(['fault_id'=>$t2])->value('name'),
  396. // ];
  397. // }
  398. // }
  399. // //故障现象 end
  400. // //故障部位 start
  401. // foreach ($fault_arr as $k11 =>$t11){
  402. // if(!in_array($t11,$buwei_arr)){
  403. // $buwei_score = 1+$buwei_score;
  404. // $buwei_content[] = [
  405. // 'cx_id'=>$t11,
  406. // 'cx_type'=>'少写',
  407. // 'cx_name'=>Fault::where(['fault_id'=>$t11])->value('name'),
  408. // ];
  409. // }
  410. // }
  411. // foreach ($buwei_arr as $k12 =>$t12){
  412. // if(!empty($t12) && !in_array($t12,$fault_arr)){
  413. // //错写
  414. // $buwei_score = 1+$buwei_score;
  415. // $buwei_content[] = [
  416. // 'cx_id'=>$t12,
  417. // 'cx_type'=>'错写',
  418. // 'cx_name'=>Fault::where(['fault_id'=>$t12])->value('name'),
  419. // ];
  420. // }
  421. // }
  422. // //故障部位 end
  423. // //排除方法 start
  424. // //循环固定的排除方法,匹配作答的排除方法
  425. // foreach ($paichu_arr as $k21 =>$t21){
  426. // if(!in_array($t21,$fangfa_arr)){
  427. // $fangfa_score = 1+$fangfa_score;
  428. // $fangfa_content[] = [
  429. // 'cx_id'=>$t21,
  430. // 'cx_type'=>'少写',
  431. // 'cx_name'=>Fault::where(['fault_id'=>$t21])->value('name'),
  432. // ];
  433. // }
  434. // }
  435. // //循环作答的排除方法,,匹配固定的排除方法
  436. // foreach ($fangfa_arr as $k22 =>$t22){
  437. // if(!empty($t22) && !in_array($t22,$paichu_arr)){
  438. // $fangfa_score = 1+$fangfa_score;
  439. // $fangfa_content[] = [
  440. // 'cx_id'=>$t22,
  441. // 'cx_type'=>'错写',
  442. // 'cx_name'=>Fault::where(['fault_id'=>$t22])->value('name'),
  443. // ];
  444. // }
  445. // }
  446. // //排除方法 end
  447. // //可能原因 start
  448. // //循环固定的可能原因,匹配作答的可能原因
  449. // foreach ($yy_arr as $k31 =>$t31){
  450. // if(!in_array($t31,$yuanyin_arr)){
  451. // // echo $t31."<br/>";
  452. // $yuanyin_socre = 1+$yuanyin_socre;
  453. // $yuanyin_content[] = [
  454. // 'cx_id'=>$t31,
  455. // 'cx_type'=>'少写',
  456. // 'cx_name'=>Fault::where(['fault_id'=>$t31])->value('name'),
  457. // ];
  458. // }
  459. // }
  460. // //循环作答的排除方法,匹配固定的排除方法
  461. // foreach ($yuanyin_arr as $k32 =>$t32){
  462. // if(!empty($t32) && !in_array($t32,$yy_arr)){
  463. // $yuanyin_socre = 1+$yuanyin_socre;
  464. // $yuanyin_content[] = [
  465. // 'cx_id'=>$t32,
  466. // 'cx_type'=>'错写',
  467. // 'cx_name'=>Fault::where(['fault_id'=>$t32])->value('name'),
  468. // ];
  469. // }
  470. // }
  471. // //判断答案是否有重复回答的
  472. // $uniqueArray = array_unique($yuanyin_arr);
  473. // $diff = array_diff_assoc($yuanyin_arr, $uniqueArray);
  474. // if(!empty($diff)){
  475. // foreach ($diff as $k323 =>$t323){
  476. // $yuanyin_socre = 1+$yuanyin_socre;
  477. // $yuanyin_content[] = [
  478. // 'cx_id'=>$t323,
  479. // 'cx_type'=>'错写',
  480. // 'cx_name'=>Fault::where(['fault_id'=>$t323])->value('name'),
  481. // ];
  482. // }
  483. // }
  484. // //可能原因 end
  485. $weixiu_score = $xianxian_score+$yuanyin_socre+$buwei_score+$fangfa_score;
  486. if($weixiu_score>15){
  487. $weixiu_score = 15;
  488. }
  489. //是否超时
  490. $overtime_fen = intval((time()-$info['countdown_time']) / 60);
  491. if($overtime_fen>=10){
  492. $overtime_score = 10;
  493. }else if($overtime_fen>0 && $overtime_fen<10){
  494. $overtime_score = $overtime_fen ;
  495. }else{
  496. $overtime_score =0;
  497. }
  498. $fault_score = $score-$fault_one_score-$fault_two_score-$fault_three_score-$weixiu_score-$overtime_score;
  499. //更新考试结果表
  500. $params['exam_id'] = $ids;
  501. $params['total'] = $fault_score;//得分;
  502. $params['fault_one_score'] = $fault_one_score;//得分;
  503. $params['fault_two_score'] = $fault_two_score;//得分;
  504. $params['fault_three_score'] = $fault_three_score;//得分;
  505. $params['xianxian_score'] = $xianxian_score;//得分;
  506. $params['xianxian_content'] = json_encode($xianxian_content);//错题;
  507. $params['yuanyin_socre'] = $yuanyin_socre;//得分;
  508. $params['yuanyin_content'] = json_encode($yuanyin_content);//错题;
  509. $params['buwei_score'] = $buwei_score;//得分;
  510. $params['buwei_content'] = json_encode($buwei_content);//错题;
  511. $params['fangfa_score'] = $fangfa_score;//得分;
  512. $params['fangfa_content'] = json_encode($fangfa_content);//错题;
  513. $params['overtime_score'] = $overtime_score;//得分;
  514. Db::name('real_exam_score')->insert($params);
  515. $this->exam_model->where(['exam_id'=>$ids])->update(['total_score'=>$fault_score]);
  516. Db::commit();
  517. } catch (ValidateException|PDOException|Exception $e) {
  518. Db::rollback();
  519. $this->error($e->getMessage());
  520. }
  521. if ($result === false) {
  522. $this->error(__('No rows were inserted'));
  523. }
  524. $this->success('交卷成功,待老师确认成绩','/admin/student/exam/index');
  525. }
  526. if(empty($row->starttime)){
  527. $row->start_time = date('Y-m-d H:i:s');
  528. $row->starttime = time();
  529. $row->exam_status = 4;
  530. $row->save();
  531. }
  532. $isloading =1;
  533. if(empty($row->other_replace)){
  534. $isloading = 0;
  535. $row->other_replace = '[{"fault_id":"","request_status":"0"}]';
  536. }
  537. $row->other_report_text = !empty($row->other_report) ? json_decode($row->other_report,true) : [];
  538. $other_report_count = !empty($row->other_report) ? count(json_decode($row->other_report,true)) :0;
  539. //还未开始考试
  540. $row->limit_duration = $this->model->where(['exam_collection_id'=>$row['exam_collection_id']])->value('limit_duration');
  541. if(empty($row->starttime)){
  542. $timer = 60*$row->limit_duration;
  543. }else{
  544. $timer = $row->limit_duration*60 - abs(time() - $row->starttime);
  545. }
  546. if(empty($row->countdown_time)){
  547. $duration = 10+$row->limit_duration;
  548. $this->exam_model->where('exam_id',$ids)->update(['countdown_time'=>strtotime(date('Y-m-d H:i:s', strtotime('+'.$duration.' minute',$row->starttime)))]);
  549. }
  550. $row->replace_list =Db::name('real_exam_comp_request')->where(['exam_id'=>$ids])->select();
  551. $this->assignConfig('ids',$ids);
  552. $this->assignConfig('timer',$timer);
  553. $this->assignConfig('isloading',$isloading);
  554. $this->assignConfig('other_report_count',$other_report_count);
  555. $this->view->assign('row', $row);
  556. $departmentdata = [];
  557. $departmentdata = Fault::where(['replace_part'=>1,'sim_type'=>$row->sim_type])->order('fault_id asc')->select();
  558. //更换件数据
  559. $this->view->assign('departmentdata', $departmentdata);
  560. //故障现象
  561. $xianxiang = Fault::where(['fault_type'=>1,'sim_type'=>$row->sim_type])->select();
  562. $this->view->assign('xianxiang', $xianxiang);
  563. //可能原因
  564. $yuanyin = Fault::where(['fault_type'=>2,'sim_type'=>$row->sim_type])->select();
  565. $this->view->assign('yuanyin', $yuanyin);
  566. //故障部位
  567. $buwei = Fault::where(['fault_type'=>3,'sim_type'=>$row->sim_type])->select();
  568. $this->view->assign('buwei', $buwei);
  569. //排除方法
  570. $paichu = Fault::where(['fault_type'=>4,'sim_type'=>$row->sim_type])->select();
  571. $this->view->assign('paichu', $paichu);
  572. return $this->view->fetch();
  573. }
  574. public function replace($ids = null)
  575. {
  576. if ($this->request->isPost()) {
  577. $params = $this->request->post('other_replace','');
  578. $other_report = $this->request->post('other_report','');
  579. $param = json_decode($params,true);
  580. if(!empty($param)){
  581. $faultid_arr = [];
  582. foreach ($param as $key=>$item){
  583. if(!empty($item['fault_id'])){
  584. $isreplace = Db::name('real_exam_comp_request')->where(['exam_id'=>$ids,'fault_id'=>$item['fault_id']])->find();
  585. if(empty($isreplace)){
  586. $add = [
  587. 'exam_id'=>$ids,
  588. 'fault_id'=>$item['fault_id'],
  589. 'request_status'=>1,
  590. 'fault_name'=>Db::name('fault')->where('fault_id',$item['fault_id'])->value('replace_name'),
  591. 'create_by_user_id'=>$this->auth->id,
  592. 'create_by'=>$this->auth->nickname,
  593. 'createtime'=>time(),
  594. 'updatetime'=>time(),
  595. 'create_time'=>date('Y-m-d H:i:s'),
  596. 'update_time'=>date('Y-m-d H:i:s'),
  597. ];
  598. Db::name('real_exam_comp_request')->insert($add);
  599. $status = 1;
  600. }else{
  601. $status = $isreplace['request_status'];
  602. }
  603. $faultid_arr[] = [
  604. 'fault_id'=>$item['fault_id'],
  605. 'request_status'=>$status,
  606. ];
  607. }
  608. }
  609. unset($item);
  610. $row = $this->exam_model->get($ids);
  611. $row-> other_replace = $faultid_arr ? json_encode($faultid_arr):'';
  612. $row-> other_report = $other_report;
  613. $result = $row->save();
  614. }
  615. $this->success('申请成功,待老师审批');
  616. }
  617. }
  618. /**
  619. * @Notes:添加维修报告
  620. * @Author: jxb
  621. * @Date: 2025/1/21
  622. * @Time: 10:29
  623. */
  624. public function addreport($ids = null){
  625. $row = $this->exam_model->get($ids);
  626. if(!$row){
  627. $this->error('未找到记录');
  628. }
  629. if ($this->request->isPost()) {
  630. $unwin = $this->request->post('unwin/a');
  631. $arr = [];
  632. if(!empty($unwin)){
  633. if(empty($unwin['xx_id'])){
  634. $this->error('故障现象选项有空白项');
  635. }
  636. if(empty($unwin['yy_id'][0])){
  637. $this->error('可能原因选项有空白项');
  638. }
  639. if(empty($unwin['bw_id'])){
  640. $this->error('故障部位选项有空白项');
  641. }
  642. if(empty($unwin['pc_id'])){
  643. $this->error('排除方法选项有空白项');
  644. }
  645. $xx_name = Fault::where('fault_id',$unwin['xx_id'])->value('name');
  646. $yy_name = Fault::where('fault_id','in',$unwin['yy_id'])->column('name');
  647. $bw_name = Fault::where('fault_id',$unwin['bw_id'])->value('name');
  648. $pc_name = Fault::where('fault_id',$unwin['pc_id'])->value('name');
  649. $arr = [
  650. 'xh_id' => $unwin['xh_id'],
  651. 'xx_id' => $unwin['xx_id'],
  652. 'xx_name'=>$xx_name,
  653. 'yy_id' => implode(',',$unwin['yy_id']),
  654. 'yy_name' => implode(',',$yy_name),
  655. 'bw_id' => $unwin['bw_id'],
  656. 'bw_name' => $bw_name,
  657. 'pc_id' => $unwin['pc_id'],
  658. 'pc_name' => $pc_name,
  659. ];
  660. }
  661. $other_report = !empty($row->other_report) ? json_decode($row->other_report,true) : [];
  662. array_push($other_report,$arr);
  663. $row->other_report = json_encode($other_report);
  664. $row->save();
  665. $this->success();
  666. }
  667. //故障现象
  668. $xianxiang = Fault::where(['fault_type'=>1,'sim_type'=>$row->sim_type])->select();
  669. $this->view->assign('xianxiang', $xianxiang);
  670. //可能原因
  671. $yuanyin = Fault::where(['fault_type'=>2,'sim_type'=>$row->sim_type])->column('fault_id,name');
  672. $this->view->assign('yuanyin', $yuanyin);
  673. //故障部位
  674. $buwei = Fault::where(['fault_type'=>3,'sim_type'=>$row->sim_type])->column('fault_id,name');
  675. $this->view->assign('buwei', $buwei);
  676. //排除方法
  677. $paichu = Fault::where(['fault_type'=>4,'sim_type'=>$row->sim_type])->column('fault_id,name');
  678. $this->view->assign('paichu', $paichu);
  679. $row->other_report_count = 0;
  680. $xxid = [];
  681. if(!empty($row->other_report)){
  682. $row->other_report_count = count(json_decode($row->other_report,true));
  683. $otherreport = json_decode($row->other_report,true);
  684. foreach ($otherreport as $k =>$item){
  685. array_push($xxid,$item['xx_id']);
  686. }
  687. }
  688. $row->xxid = $xxid;
  689. $this->view->assign('row', $row);
  690. return $this->view->fetch();
  691. }
  692. /**
  693. * @Notes:编辑报告
  694. * @Author: jxb
  695. * @Date: 2025/1/21
  696. * @Time: 15:04
  697. */
  698. public function editreport($ids = null,$xh_id = null){
  699. $row = $this->exam_model->get($ids);
  700. if(!$row){
  701. $this->error('未找到记录');
  702. }
  703. if ($this->request->isPost()) {
  704. $unwin = $this->request->post('unwin/a');
  705. if(!empty($unwin)){
  706. if(empty($unwin['xx_id'])){
  707. $this->error('故障现象选项有空白项');
  708. }
  709. if(empty($unwin['yy_id'][0])){
  710. $this->error('可能原因选项有空白项');
  711. }
  712. if(empty($unwin['bw_id'])){
  713. $this->error('故障部位选项有空白项');
  714. }
  715. if(empty($unwin['pc_id'])){
  716. $this->error('排除方法选项有空白项');
  717. }
  718. $xx_name = Fault::where('fault_id',$unwin['xx_id'])->value('name');
  719. $yy_name = Fault::where('fault_id','in',$unwin['yy_id'])->column('name');
  720. $bw_name = Fault::where('fault_id',$unwin['bw_id'])->value('name');
  721. $pc_name = Fault::where('fault_id',$unwin['pc_id'])->value('name');
  722. $other_report = !empty($row->other_report) ? json_decode($row->other_report,true) : [];
  723. foreach ($other_report as $k =>$item){
  724. if($k==$xh_id){
  725. $other_report[$k]['xx_id'] =$unwin['xx_id'];
  726. $other_report[$k]['xx_name'] =$xx_name;
  727. $other_report[$k]['yy_id'] = implode(',',$unwin['yy_id']);
  728. $other_report[$k]['yy_name'] =implode(',',$yy_name);
  729. $other_report[$k]['bw_id'] = $unwin['bw_id'];
  730. $other_report[$k]['bw_name'] =$bw_name;
  731. $other_report[$k]['pc_id'] =$unwin['pc_id'];
  732. $other_report[$k]['pc_name'] =$pc_name;
  733. }
  734. }
  735. $row->other_report = json_encode($other_report);
  736. $row->save();
  737. }
  738. $this->success();
  739. }
  740. //故障现象
  741. $xianxiang = Fault::where(['fault_type'=>1,'sim_type'=>$row->sim_type])->select();
  742. $this->view->assign('xianxiang', $xianxiang);
  743. //可能原因
  744. $yuanyin = Fault::where(['fault_type'=>2,'sim_type'=>$row->sim_type])->column('fault_id,name');
  745. $this->view->assign('yuanyin', $yuanyin);
  746. //故障部位
  747. $buwei = Fault::where(['fault_type'=>3,'sim_type'=>$row->sim_type])->column('fault_id,name');
  748. $this->view->assign('buwei', $buwei);
  749. //排除方法
  750. $paichu = Fault::where(['fault_type'=>4,'sim_type'=>$row->sim_type])->column('fault_id,name');
  751. $this->view->assign('paichu', $paichu);
  752. $row->other_report_text = [];
  753. if(!empty($row->other_report)){
  754. $other_report = json_decode($row->other_report,true);
  755. foreach ($other_report as $k =>$item){
  756. if($k==$xh_id){
  757. $row->other_report_text = [
  758. 'xx_id'=>$item['xx_id'],
  759. 'yy_id'=>explode(',',$item['yy_id']),
  760. 'bw_id'=>$item['bw_id'],
  761. 'pc_id'=>$item['pc_id'],
  762. 'xh_id'=>$item['xh_id']
  763. ];
  764. }
  765. }
  766. }
  767. $this->view->assign('row', $row);
  768. return $this->view->fetch();
  769. }
  770. /**
  771. * @Notes:移除 维修报告
  772. * @Author: jxb
  773. * @Date: 2025/1/21
  774. * @Time: 14:45
  775. */
  776. public function delreport($ids = null){
  777. $row = $this->exam_model->get($ids);
  778. if(!$row){
  779. $this->error('未找到记录');
  780. }
  781. if ($this->request->isPost()) {
  782. $xh_id = $this->request->post('xh_id');
  783. if(!empty($row->other_report)){
  784. $other_report = json_decode($row->other_report,true);
  785. unset($other_report[$xh_id]);
  786. $row->other_report = json_encode($other_report);
  787. $row->save();
  788. }
  789. $this->success();
  790. }
  791. }
  792. public function countdown($ids = null){
  793. $row = $this->exam_model->get($ids);
  794. if(!$row){
  795. $this->error('未找到记录');
  796. }
  797. // 计算差值
  798. // $time = strtotime(date('Y-m-d H:i:s', strtotime('+10 minute',$row->countdown_time)));
  799. $diff = $row->countdown_time-time();
  800. // 将差值转换为秒
  801. $seconds = $diff;
  802. $minutes = floor($seconds / 60);
  803. $seconds = $seconds % 60;
  804. if($minutes==0 && $seconds==0){
  805. $a = 0;
  806. }else{
  807. $a = '已经超时,'.$minutes.'分'.$seconds.'秒后系统自动交卷。';
  808. }
  809. $this->success($a);
  810. }
  811. public function analysis($ids = null)
  812. {
  813. $row = $this->exam_model->get($ids);
  814. if(!$row){
  815. $this->error('未找到记录');
  816. }
  817. if ($this->request->isPost()) {
  818. $params = $this->request->post('row/a');
  819. //计算总分到学员考试表
  820. $this->success('操作成功','/admin/student/collection/index');
  821. }
  822. return $this->view->fetch();
  823. }
  824. }