Collection.php 40 KB

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