Collection.php 40 KB

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