Collection.php 39 KB

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