Collection.php 40 KB

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