Collection.php 40 KB

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