Collection.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932
  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. $other_content = [];
  180. Db::startTrans();
  181. try {
  182. //更新考试结束时间
  183. $row->end_time = date('Y-m-d H:i:s');
  184. $row->endtime = time();
  185. $row->exam_status = 5;
  186. $row->other_report = $params['other_report'];
  187. $result = $row->save();
  188. $info = $this->exam_model->where(['exam_id'=>$ids])->find();
  189. //更新故障是否正确
  190. $fault_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1])->select();
  191. if(!empty($fault_list)){
  192. foreach ($fault_list as $k =>$t){
  193. $answer_right = 2;
  194. if(!empty($t['sim_fault_question_value']) && !empty($t['sim_fault_answer_value'])){
  195. if($t['sim_fault_question_value']!=$t['sim_fault_answer_value'] ){
  196. //真实故障id 0002GZBW0001 薄膜开关FPC排线
  197. if($t['sim_fault_answer_value']=='00000000' && $t['fault_id'] !='0002GZBW0001'){
  198. $answer_right=2;
  199. }
  200. $answer_right=1;
  201. }
  202. }
  203. Db::name('real_exam_fault')->where(['ref_id'=>$t['ref_id']])->update(['answer_right'=>$answer_right]);
  204. }
  205. }
  206. //计算得分,故障是否有扣分 扣分制
  207. $fault_right_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1,'answer_right'=>['>',0]])->select();
  208. if(!empty($fault_right_list)){
  209. if($fault_right_list[0]['answer_right']==1){
  210. $fault_one_score = 0;
  211. }
  212. if($fault_right_list[1]['answer_right']==1){
  213. $fault_two_score = 0;
  214. }
  215. if($fault_right_list[2]['answer_right']==1){
  216. $fault_three_score = 0;
  217. }
  218. }
  219. $fault_right_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1])->select();
  220. //根据故障部位 数组
  221. $fault_arr = [$fault_right_list[0]['fault_id'],$fault_right_list[1]['fault_id'],$fault_right_list[2]['fault_id']];
  222. //根据故障部位查找,匹配的排除方法
  223. $paichu_arr = Report::where(['bw_id'=>['in',$fault_arr],'sim_type'=>$info['sim_type']])->column('pc_id');
  224. //查找故障现象 数组
  225. $partent_fault_id = Fault::where(['fault_id'=>['in',$fault_arr],'sim_type'=>$info['sim_type']])->column('parent_fault_id');
  226. //根据故障部位查找,匹配可能原因
  227. $yy_arr = Fault::where(['parent_fault_id'=>['in',$partent_fault_id],'sim_type'=>$info['sim_type'],'fault_type'=>2])->column('fault_id');
  228. //获取数组
  229. $other_report = json_decode($params['other_report'],true);
  230. if(!empty($other_report)){
  231. foreach ($other_report as $key => $em){
  232. //故障现象
  233. $xianxian_arr[] = $em['xx_id'];
  234. }
  235. foreach ($partent_fault_id as $k1 =>$t){
  236. $kscore = 0;
  237. if(!in_array($t,$xianxian_arr)){
  238. $xianxian_score = 5+$xianxian_score;
  239. $xianxian_content[] = [
  240. 'gzxz_id'=>$t,
  241. 'cx_id'=>$t,
  242. 'cx_type'=>'故障现象少写',
  243. 'cx_name'=>Fault::where(['fault_id'=>$t])->value('name'),
  244. 'cx_score'=>-5,
  245. ];
  246. $other_content[] = [
  247. 'gzxz_id'=>$t,
  248. 'cx_score'=>-5,
  249. ];
  250. }else{
  251. // echo "存在里面".$t."###".$k1."<br/>";
  252. $t1= $t;
  253. $jian = '';
  254. foreach ($other_report as $ky => $item) {
  255. if ($item['xx_id'] == $t) {
  256. $jian = $ky;
  257. }
  258. }
  259. // 故障部位算分 start
  260. //获取故障部位
  261. $buweiarr = Fault::where(['parent_fault_id'=>$t,'sim_type'=>$info['sim_type'],'fault_type'=>['in',[3,30]],'fault_state'=>0])
  262. ->column('fault_id');
  263. if(!in_array($other_report[$jian]['bw_id'],$buweiarr)){
  264. $buwei_score = 1+$buwei_score;
  265. $kscore = 1+$kscore;
  266. $xianxian_content[] = [
  267. 'gzxz_id'=>$t,
  268. 'cx_id'=>$other_report[$jian]['bw_id'],
  269. 'cx_type'=>'故障部位错写',
  270. 'cx_name'=>Fault::where(['fault_id'=>$other_report[$jian]['bw_id']])->value('name'),
  271. ];
  272. }
  273. //出题故障部位和获取的故障部位里面有重复的
  274. // 获取两个数组的交集
  275. $intersection = array_intersect($buweiarr, $fault_arr);
  276. // halt($intersection);
  277. foreach($intersection as $kk =>$va){
  278. if($other_report[$jian]['bw_id']!=$va){
  279. $buwei_score = 1+$buwei_score;
  280. $kscore = 1+$kscore;
  281. $xianxian_content[] = [
  282. 'gzxz_id'=>$t,
  283. 'cx_id'=>$va,
  284. 'cx_type'=>'故障部位少写',
  285. 'cx_name'=>Fault::where(['fault_id'=>$va])->value('name'),
  286. ];
  287. }
  288. }
  289. unset($va);
  290. // 故障部位算分 end
  291. // 排除方法算分 start
  292. $paichuarr = Fault::where(['parent_fault_id'=>$t,'sim_type'=>$info['sim_type'],'fault_type'=>4,'fault_state'=>0])
  293. ->column('fault_id');
  294. if(!in_array($other_report[$jian]['pc_id'],$paichuarr)){
  295. $fangfa_score = 1+$fangfa_score;
  296. $kscore = 1+$kscore;
  297. $xianxian_content[] = [
  298. 'gzxz_id'=>$t,
  299. 'cx_id'=>$other_report[$jian]['pc_id'],
  300. 'cx_type'=>'排除方法错写',
  301. 'cx_name'=>Fault::where(['fault_id'=>$other_report[$jian]['pc_id']])->value('name'),
  302. ];
  303. }
  304. //出题排除方法和获取的排除方法里面有重复的
  305. // 获取两个数组的交集
  306. $intersection1 = array_intersect($paichuarr, $paichu_arr);
  307. foreach($intersection1 as $kk1 =>$va1){
  308. if($other_report[$jian]['pc_id']!=$va1){
  309. $fangfa_score = 1+$fangfa_score;
  310. $kscore = 1+$kscore;
  311. $xianxian_content[] = [
  312. 'gzxz_id'=>$t,
  313. 'cx_id'=>$va1,
  314. 'cx_type'=>'排除方法少写',
  315. 'cx_name'=>Fault::where(['fault_id'=>$va1])->value('name'),
  316. ];
  317. }
  318. }
  319. unset($va1);
  320. // 排除方法算分 end
  321. // 可能原因算分 start
  322. $yuanyinarr = Fault::where(['parent_fault_id'=>$t,'sim_type'=>$info['sim_type'],'fault_type'=>2,'fault_state'=>0])
  323. ->column('fault_id');
  324. foreach (explode(',',$other_report[$jian]['yy_id']) as $key => $value) {
  325. if(!in_array($value,$yuanyinarr)){
  326. $yuanyin_socre = 1+$yuanyin_socre;
  327. $kscore = 1+$kscore;
  328. $xianxian_content[] = [
  329. 'gzxz_id'=>$t,
  330. 'cx_id'=>$value,
  331. 'cx_type'=>'可能原因错写',
  332. 'cx_name'=>Fault::where(['fault_id'=>$value])->value('name'),
  333. ];
  334. }
  335. }
  336. //出题可能原因和获取的可能原因里面有重复的
  337. // 获取两个数组的交集
  338. $intersection2 = array_intersect($yy_arr, $yuanyinarr);
  339. $intersection22 = array_intersect($intersection2, explode(',',$other_report[$jian]['yy_id']));
  340. foreach($yuanyinarr as $kk2 =>$va2){
  341. if(!in_array($va2,$intersection22)){
  342. $yuanyin_socre = 1+$yuanyin_socre;
  343. $kscore = 1+$kscore;
  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. if($kscore>5){
  355. $kscore = '-5';
  356. }else if($kscore>0){
  357. $kscore = '-'.$kscore;
  358. }else{
  359. $kscore=0;
  360. }
  361. // echo $t1."####".$kscore."<br/>";
  362. $other_content[] = [
  363. 'gzxz_id'=>$t,
  364. 'cx_score'=>$kscore,
  365. ];
  366. }
  367. }
  368. unset($em);
  369. // echo "<pre>";
  370. // print_r($xianxian_content);
  371. // echo "<pre>";
  372. // print_r($other_content);
  373. // die();
  374. }else{
  375. foreach ($partent_fault_id as $key => $em){
  376. $xianxian_score = 5+$xianxian_score;
  377. $xianxian_content[] = [
  378. 'gzxz_id'=>$em,
  379. 'cx_id'=>$em,
  380. 'cx_type'=>'未作答',
  381. // 'cx_name'=>Fault::where(['fault_id'=>$em])->value('name'),
  382. 'cx_name'=>'',
  383. ];
  384. $other_content[] = [
  385. 'gzxz_id'=>$em,
  386. 'cx_score'=>-5,
  387. ];
  388. }
  389. unset($em);
  390. }
  391. // echo "故障现象得分:".$xianxian_score."<br/>";
  392. // echo "故障部位得分:".$buwei_score."<br/>";
  393. // echo "排除方法得分:".$fangfa_score."<br/>";
  394. // echo "可能原因得分:".$yuanyin_socre."<br/>";
  395. // echo "<pre>";
  396. // print_r($xianxian_content);
  397. // echo "<pre>";
  398. // print_r($other_content);
  399. // die();
  400. // $other_report = json_decode($params['other_report'],true);
  401. // if(!empty($other_report)){
  402. // foreach ($other_report as $key => $em){
  403. // //故障现象
  404. // $xianxian_arr[] = $em['xx_id'];
  405. // //故障部位
  406. // $buwei_arr[] = $em['bw_id'];
  407. // //可能原因
  408. // foreach(explode(',',$em['yy_id']) as $k3 =>$t13){
  409. // $yuanyin_arr[] = $t13;
  410. // }
  411. // //排除方法
  412. // $fangfa_arr[] = $em['pc_id'];
  413. // }
  414. // }
  415. // //故障现象 分数 start
  416. // foreach ($partent_fault_id as $k1 =>$t){
  417. // if(!in_array($t,$xianxian_arr)){
  418. // $xianxian_score = 1+$xianxian_score;
  419. // $xianxian_content[] = [
  420. // 'cx_id'=>$t,
  421. // 'cx_type'=>'少写',
  422. // 'cx_name'=>Fault::where(['fault_id'=>$t])->value('name'),
  423. // ];
  424. // }
  425. // }
  426. // foreach ($xianxian_arr as $k2 =>$t2){
  427. // if(!in_array($t2,$partent_fault_id)){
  428. // $xianxian_score = 1+$xianxian_score;
  429. // $xianxian_content[] = [
  430. // 'cx_id'=>$t2,
  431. // 'cx_type'=>'错写',
  432. // 'cx_name'=>Fault::where(['fault_id'=>$t2])->value('name'),
  433. // ];
  434. // }
  435. // }
  436. // //故障现象 end
  437. // //故障部位 start
  438. // foreach ($fault_arr as $k11 =>$t11){
  439. // if(!in_array($t11,$buwei_arr)){
  440. // $buwei_score = 1+$buwei_score;
  441. // $buwei_content[] = [
  442. // 'cx_id'=>$t11,
  443. // 'cx_type'=>'少写',
  444. // 'cx_name'=>Fault::where(['fault_id'=>$t11])->value('name'),
  445. // ];
  446. // }
  447. // }
  448. // foreach ($buwei_arr as $k12 =>$t12){
  449. // if(!empty($t12) && !in_array($t12,$fault_arr)){
  450. // //错写
  451. // $buwei_score = 1+$buwei_score;
  452. // $buwei_content[] = [
  453. // 'cx_id'=>$t12,
  454. // 'cx_type'=>'错写',
  455. // 'cx_name'=>Fault::where(['fault_id'=>$t12])->value('name'),
  456. // ];
  457. // }
  458. // }
  459. // //故障部位 end
  460. // //排除方法 start
  461. // //循环固定的排除方法,匹配作答的排除方法
  462. // foreach ($paichu_arr as $k21 =>$t21){
  463. // if(!in_array($t21,$fangfa_arr)){
  464. // $fangfa_score = 1+$fangfa_score;
  465. // $fangfa_content[] = [
  466. // 'cx_id'=>$t21,
  467. // 'cx_type'=>'少写',
  468. // 'cx_name'=>Fault::where(['fault_id'=>$t21])->value('name'),
  469. // ];
  470. // }
  471. // }
  472. // //循环作答的排除方法,,匹配固定的排除方法
  473. // foreach ($fangfa_arr as $k22 =>$t22){
  474. // if(!empty($t22) && !in_array($t22,$paichu_arr)){
  475. // $fangfa_score = 1+$fangfa_score;
  476. // $fangfa_content[] = [
  477. // 'cx_id'=>$t22,
  478. // 'cx_type'=>'错写',
  479. // 'cx_name'=>Fault::where(['fault_id'=>$t22])->value('name'),
  480. // ];
  481. // }
  482. // }
  483. // //排除方法 end
  484. // //可能原因 start
  485. // //循环固定的可能原因,匹配作答的可能原因
  486. // foreach ($yy_arr as $k31 =>$t31){
  487. // if(!in_array($t31,$yuanyin_arr)){
  488. // // echo $t31."<br/>";
  489. // $yuanyin_socre = 1+$yuanyin_socre;
  490. // $yuanyin_content[] = [
  491. // 'cx_id'=>$t31,
  492. // 'cx_type'=>'少写',
  493. // 'cx_name'=>Fault::where(['fault_id'=>$t31])->value('name'),
  494. // ];
  495. // }
  496. // }
  497. // //循环作答的排除方法,匹配固定的排除方法
  498. // foreach ($yuanyin_arr as $k32 =>$t32){
  499. // if(!empty($t32) && !in_array($t32,$yy_arr)){
  500. // $yuanyin_socre = 1+$yuanyin_socre;
  501. // $yuanyin_content[] = [
  502. // 'cx_id'=>$t32,
  503. // 'cx_type'=>'错写',
  504. // 'cx_name'=>Fault::where(['fault_id'=>$t32])->value('name'),
  505. // ];
  506. // }
  507. // }
  508. // //判断答案是否有重复回答的
  509. // $uniqueArray = array_unique($yuanyin_arr);
  510. // $diff = array_diff_assoc($yuanyin_arr, $uniqueArray);
  511. // if(!empty($diff)){
  512. // foreach ($diff as $k323 =>$t323){
  513. // $yuanyin_socre = 1+$yuanyin_socre;
  514. // $yuanyin_content[] = [
  515. // 'cx_id'=>$t323,
  516. // 'cx_type'=>'错写',
  517. // 'cx_name'=>Fault::where(['fault_id'=>$t323])->value('name'),
  518. // ];
  519. // }
  520. // }
  521. // //可能原因 end
  522. $weixiu_score = $xianxian_score+$yuanyin_socre+$buwei_score+$fangfa_score;
  523. if($weixiu_score>15){
  524. $weixiu_score = 15;
  525. }
  526. //是否超时
  527. $overtime_fen = intval((time()-$info['countdown_time']) / 60);
  528. if($overtime_fen>=10){
  529. $overtime_score = 10;
  530. }else if($overtime_fen>0 && $overtime_fen<10){
  531. $overtime_score = $overtime_fen ;
  532. }else{
  533. $overtime_score =0;
  534. }
  535. $fault_score = $score-$fault_one_score-$fault_two_score-$fault_three_score-$weixiu_score-$overtime_score;
  536. //更新考试结果表
  537. $params['exam_id'] = $ids;
  538. $params['total'] = $fault_score;//得分;
  539. $params['fault_one_score'] = $fault_one_score;//得分;
  540. $params['fault_two_score'] = $fault_two_score;//得分;
  541. $params['fault_three_score'] = $fault_three_score;//得分;
  542. $params['xianxian_score'] = $xianxian_score;//得分;
  543. $params['xianxian_content'] = json_encode($xianxian_content);//错题;
  544. $params['yuanyin_socre'] = $yuanyin_socre;//得分;
  545. $params['yuanyin_content'] = json_encode($yuanyin_content);//错题;
  546. $params['buwei_score'] = $buwei_score;//得分;
  547. $params['buwei_content'] = json_encode($buwei_content);//错题;
  548. $params['fangfa_score'] = $fangfa_score;//得分;
  549. $params['fangfa_content'] = json_encode($fangfa_content);//错题;
  550. $params['other_jielun'] = json_encode($other_content);//每个答题的得分
  551. $params['overtime_score'] = $overtime_score;//得分;
  552. Db::name('real_exam_score')->insert($params);
  553. $this->exam_model->where(['exam_id'=>$ids])->update(['total_score'=>$fault_score]);
  554. Db::commit();
  555. } catch (ValidateException|PDOException|Exception $e) {
  556. Db::rollback();
  557. $this->error($e->getMessage());
  558. }
  559. if ($result === false) {
  560. $this->error(__('No rows were inserted'));
  561. }
  562. $this->success('交卷成功,待老师确认成绩','/admin/student/exam/index');
  563. }
  564. if(empty($row->starttime)){
  565. $row->start_time = date('Y-m-d H:i:s');
  566. $row->starttime = time();
  567. $row->exam_status = 4;
  568. $row->save();
  569. }
  570. $isloading =1;
  571. if(empty($row->other_replace)){
  572. $isloading = 0;
  573. $row->other_replace = '[{"fault_id":"","request_status":"0"}]';
  574. }
  575. $row->other_report_text = !empty($row->other_report) ? json_decode($row->other_report,true) : [];
  576. $other_report_count = !empty($row->other_report) ? count(json_decode($row->other_report,true)) :0;
  577. //还未开始考试
  578. $row->limit_duration = $this->model->where(['exam_collection_id'=>$row['exam_collection_id']])->value('limit_duration');
  579. if(empty($row->starttime)){
  580. $timer = 60*$row->limit_duration;
  581. }else{
  582. $timer = $row->limit_duration*60 - abs(time() - $row->starttime);
  583. }
  584. if(empty($row->countdown_time)){
  585. $duration = 10+$row->limit_duration;
  586. $this->exam_model->where('exam_id',$ids)->update(['countdown_time'=>strtotime(date('Y-m-d H:i:s', strtotime('+'.$duration.' minute',$row->starttime)))]);
  587. }
  588. $row->replace_list =Db::name('real_exam_comp_request')->where(['exam_id'=>$ids])->select();
  589. $this->assignConfig('ids',$ids);
  590. $this->assignConfig('timer',$timer);
  591. $this->assignConfig('isloading',$isloading);
  592. $this->assignConfig('other_report_count',$other_report_count);
  593. $this->view->assign('row', $row);
  594. $departmentdata = [];
  595. $departmentdata = Fault::where(['replace_part'=>1,'sim_type'=>$row->sim_type])->order('fault_id asc')->select();
  596. //更换件数据
  597. $this->view->assign('departmentdata', $departmentdata);
  598. //故障现象
  599. $xianxiang = Fault::where(['fault_type'=>1,'sim_type'=>$row->sim_type])->select();
  600. $this->view->assign('xianxiang', $xianxiang);
  601. //可能原因
  602. $yuanyin = Fault::where(['fault_type'=>2,'sim_type'=>$row->sim_type])->select();
  603. $this->view->assign('yuanyin', $yuanyin);
  604. //故障部位
  605. $buwei = Fault::where(['fault_type'=>3,'sim_type'=>$row->sim_type])->select();
  606. $this->view->assign('buwei', $buwei);
  607. //排除方法
  608. $paichu = Fault::where(['fault_type'=>4,'sim_type'=>$row->sim_type])->select();
  609. $this->view->assign('paichu', $paichu);
  610. return $this->view->fetch();
  611. }
  612. public function replace($ids = null)
  613. {
  614. if ($this->request->isPost()) {
  615. $params = $this->request->post('other_replace','');
  616. $other_report = $this->request->post('other_report','');
  617. $param = json_decode($params,true);
  618. if(!empty($param)){
  619. $faultid_arr = [];
  620. foreach ($param as $key=>$item){
  621. if(!empty($item['fault_id'])){
  622. $isreplace = Db::name('real_exam_comp_request')->where(['exam_id'=>$ids,'fault_id'=>$item['fault_id']])->find();
  623. if(empty($isreplace)){
  624. $add = [
  625. 'exam_id'=>$ids,
  626. 'fault_id'=>$item['fault_id'],
  627. 'request_status'=>1,
  628. 'fault_name'=>Db::name('fault')->where('fault_id',$item['fault_id'])->value('replace_name'),
  629. 'create_by_user_id'=>$this->auth->id,
  630. 'create_by'=>$this->auth->nickname,
  631. 'createtime'=>time(),
  632. 'updatetime'=>time(),
  633. 'create_time'=>date('Y-m-d H:i:s'),
  634. 'update_time'=>date('Y-m-d H:i:s'),
  635. ];
  636. Db::name('real_exam_comp_request')->insert($add);
  637. $status = 1;
  638. }else{
  639. $status = $isreplace['request_status'];
  640. }
  641. $faultid_arr[] = [
  642. 'fault_id'=>$item['fault_id'],
  643. 'request_status'=>$status,
  644. ];
  645. }
  646. }
  647. unset($item);
  648. $row = $this->exam_model->get($ids);
  649. $row-> other_replace = $faultid_arr ? json_encode($faultid_arr):'';
  650. $row-> other_report = $other_report;
  651. $result = $row->save();
  652. }
  653. $this->success('申请成功,待老师审批');
  654. }
  655. }
  656. /**
  657. * @Notes:添加维修报告
  658. * @Author: jxb
  659. * @Date: 2025/1/21
  660. * @Time: 10:29
  661. */
  662. public function addreport($ids = null){
  663. $row = $this->exam_model->get($ids);
  664. if(!$row){
  665. $this->error('未找到记录');
  666. }
  667. if ($this->request->isPost()) {
  668. $unwin = $this->request->post('unwin/a');
  669. $arr = [];
  670. if(!empty($unwin)){
  671. if(empty($unwin['xx_id'])){
  672. $this->error('故障现象选项有空白项');
  673. }
  674. if(empty($unwin['yy_id'][0])){
  675. $this->error('可能原因选项有空白项');
  676. }
  677. if(empty($unwin['bw_id'])){
  678. $this->error('故障部位选项有空白项');
  679. }
  680. if(empty($unwin['pc_id'])){
  681. $this->error('排除方法选项有空白项');
  682. }
  683. $xx_name = Fault::where('fault_id',$unwin['xx_id'])->value('name');
  684. $yy_name = Fault::where('fault_id','in',$unwin['yy_id'])->column('name');
  685. $bw_name = Fault::where('fault_id',$unwin['bw_id'])->value('name');
  686. $pc_name = Fault::where('fault_id',$unwin['pc_id'])->value('name');
  687. $arr = [
  688. 'xh_id' => $unwin['xh_id'],
  689. 'xx_id' => $unwin['xx_id'],
  690. 'xx_name'=>$xx_name,
  691. 'yy_id' => implode(',',$unwin['yy_id']),
  692. 'yy_name' => implode(',',$yy_name),
  693. 'bw_id' => $unwin['bw_id'],
  694. 'bw_name' => $bw_name,
  695. 'pc_id' => $unwin['pc_id'],
  696. 'pc_name' => $pc_name,
  697. ];
  698. }
  699. $other_report = !empty($row->other_report) ? json_decode($row->other_report,true) : [];
  700. array_push($other_report,$arr);
  701. $row->other_report = json_encode($other_report);
  702. $row->save();
  703. $this->success();
  704. }
  705. //故障现象
  706. $xianxiang = Fault::where(['fault_type'=>1,'sim_type'=>$row->sim_type])->select();
  707. $this->view->assign('xianxiang', $xianxiang);
  708. //可能原因
  709. $yuanyin = Fault::where(['fault_type'=>2,'sim_type'=>$row->sim_type])->column('fault_id,name');
  710. $this->view->assign('yuanyin', $yuanyin);
  711. //故障部位
  712. $buwei = Fault::where(['fault_type'=>3,'sim_type'=>$row->sim_type])->column('fault_id,name');
  713. $this->view->assign('buwei', $buwei);
  714. //排除方法
  715. $paichu = Fault::where(['fault_type'=>4,'sim_type'=>$row->sim_type])->column('fault_id,name');
  716. $this->view->assign('paichu', $paichu);
  717. $row->other_report_count = 0;
  718. $xxid = [];
  719. if(!empty($row->other_report)){
  720. $row->other_report_count = count(json_decode($row->other_report,true));
  721. $otherreport = json_decode($row->other_report,true);
  722. foreach ($otherreport as $k =>$item){
  723. array_push($xxid,$item['xx_id']);
  724. }
  725. }
  726. $row->xxid = $xxid;
  727. $this->view->assign('row', $row);
  728. return $this->view->fetch();
  729. }
  730. /**
  731. * @Notes:编辑报告
  732. * @Author: jxb
  733. * @Date: 2025/1/21
  734. * @Time: 15:04
  735. */
  736. public function editreport($ids = null,$xh_id = null){
  737. $row = $this->exam_model->get($ids);
  738. if(!$row){
  739. $this->error('未找到记录');
  740. }
  741. if ($this->request->isPost()) {
  742. $unwin = $this->request->post('unwin/a');
  743. if(!empty($unwin)){
  744. if(empty($unwin['xx_id'])){
  745. $this->error('故障现象选项有空白项');
  746. }
  747. if(empty($unwin['yy_id'][0])){
  748. $this->error('可能原因选项有空白项');
  749. }
  750. if(empty($unwin['bw_id'])){
  751. $this->error('故障部位选项有空白项');
  752. }
  753. if(empty($unwin['pc_id'])){
  754. $this->error('排除方法选项有空白项');
  755. }
  756. $xx_name = Fault::where('fault_id',$unwin['xx_id'])->value('name');
  757. $yy_name = Fault::where('fault_id','in',$unwin['yy_id'])->column('name');
  758. $bw_name = Fault::where('fault_id',$unwin['bw_id'])->value('name');
  759. $pc_name = Fault::where('fault_id',$unwin['pc_id'])->value('name');
  760. $other_report = !empty($row->other_report) ? json_decode($row->other_report,true) : [];
  761. foreach ($other_report as $k =>$item){
  762. if($k==$xh_id){
  763. $other_report[$k]['xx_id'] =$unwin['xx_id'];
  764. $other_report[$k]['xx_name'] =$xx_name;
  765. $other_report[$k]['yy_id'] = implode(',',$unwin['yy_id']);
  766. $other_report[$k]['yy_name'] =implode(',',$yy_name);
  767. $other_report[$k]['bw_id'] = $unwin['bw_id'];
  768. $other_report[$k]['bw_name'] =$bw_name;
  769. $other_report[$k]['pc_id'] =$unwin['pc_id'];
  770. $other_report[$k]['pc_name'] =$pc_name;
  771. }
  772. }
  773. $row->other_report = json_encode($other_report);
  774. $row->save();
  775. }
  776. $this->success();
  777. }
  778. //故障现象
  779. $xianxiang = Fault::where(['fault_type'=>1,'sim_type'=>$row->sim_type])->select();
  780. $this->view->assign('xianxiang', $xianxiang);
  781. //可能原因
  782. $yuanyin = Fault::where(['fault_type'=>2,'sim_type'=>$row->sim_type])->column('fault_id,name');
  783. $this->view->assign('yuanyin', $yuanyin);
  784. //故障部位
  785. $buwei = Fault::where(['fault_type'=>3,'sim_type'=>$row->sim_type])->column('fault_id,name');
  786. $this->view->assign('buwei', $buwei);
  787. //排除方法
  788. $paichu = Fault::where(['fault_type'=>4,'sim_type'=>$row->sim_type])->column('fault_id,name');
  789. $this->view->assign('paichu', $paichu);
  790. $row->other_report_text = [];
  791. if(!empty($row->other_report)){
  792. $other_report = json_decode($row->other_report,true);
  793. foreach ($other_report as $k =>$item){
  794. if($k==$xh_id){
  795. $row->other_report_text = [
  796. 'xx_id'=>$item['xx_id'],
  797. 'yy_id'=>explode(',',$item['yy_id']),
  798. 'bw_id'=>$item['bw_id'],
  799. 'pc_id'=>$item['pc_id'],
  800. 'xh_id'=>$item['xh_id']
  801. ];
  802. }
  803. }
  804. }
  805. $this->view->assign('row', $row);
  806. return $this->view->fetch();
  807. }
  808. /**
  809. * @Notes:移除 维修报告
  810. * @Author: jxb
  811. * @Date: 2025/1/21
  812. * @Time: 14:45
  813. */
  814. public function delreport($ids = null){
  815. $row = $this->exam_model->get($ids);
  816. if(!$row){
  817. $this->error('未找到记录');
  818. }
  819. if ($this->request->isPost()) {
  820. $xh_id = $this->request->post('xh_id');
  821. if(!empty($row->other_report)){
  822. $other_report = json_decode($row->other_report,true);
  823. unset($other_report[$xh_id]);
  824. $row->other_report = json_encode($other_report);
  825. $row->save();
  826. }
  827. $this->success();
  828. }
  829. }
  830. public function countdown($ids = null){
  831. $row = $this->exam_model->get($ids);
  832. if(!$row){
  833. $this->error('未找到记录');
  834. }
  835. // 计算差值
  836. // $time = strtotime(date('Y-m-d H:i:s', strtotime('+10 minute',$row->countdown_time)));
  837. $diff = $row->countdown_time-time();
  838. // 将差值转换为秒
  839. $seconds = $diff;
  840. $minutes = floor($seconds / 60);
  841. $seconds = $seconds % 60;
  842. if($minutes==0 && $seconds==0){
  843. $a = 0;
  844. }else{
  845. $a = '已经超时,'.$minutes.'分'.$seconds.'秒后系统自动交卷。';
  846. }
  847. $this->success($a);
  848. }
  849. public function analysis($ids = null)
  850. {
  851. $row = $this->exam_model->get($ids);
  852. if(!$row){
  853. $this->error('未找到记录');
  854. }
  855. if ($this->request->isPost()) {
  856. $params = $this->request->post('row/a');
  857. //计算总分到学员考试表
  858. $this->success('操作成功','/admin/student/collection/index');
  859. }
  860. return $this->view->fetch();
  861. }
  862. }