Collection.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  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'];
  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. //// $this->redirect('/ZQOtIMLKud.php/student/collection/examing/ids/'.$isset['exam_id'].'?ref=addtabs');
  66. // echo "<script>location.href='/ZQOtIMLKud.php/student/collection/examing/ids/".$isset['exam_id']."';</script>";
  67. // //$this->redirect('/hotelmanage/room/displayindex/ids/1');
  68. // exit();
  69. echo "<script>location.href='/ZQOtIMLKud.php/student/collection/into/ids/".$isset['exam_collection_id']."'</script>";
  70. }
  71. die();
  72. //设置过滤方法
  73. $this->request->filter(['strip_tags', 'trim']);
  74. if (false === $this->request->isAjax()) {
  75. return $this->view->fetch();
  76. }
  77. //如果发送的来源是 Selectpage,则转发到 Selectpage
  78. if ($this->request->request('keyField')) {
  79. return $this->selectpage();
  80. }
  81. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  82. $list = $this->model
  83. ->where($where)->where($this->whereExtend)
  84. ->order($sort, $order)
  85. ->paginate($limit);
  86. foreach ($list as $k => $v){
  87. $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();
  88. if(isset($exam_isset)){
  89. $v->is_user_examed = 1;
  90. }else{
  91. $v->is_user_examed = 0;
  92. }
  93. }
  94. unset($v);
  95. $result = ['total' => $list->total(), 'rows' => $list->items()];
  96. return json($result);
  97. }
  98. //进入考试
  99. public function into($ids = null)
  100. {
  101. $row = $this->model->get($ids);
  102. if(!$row){
  103. $this->error('未找到记录');
  104. }
  105. $info = $this->exam_model->where(['user_id'=>$this->auth->id,'exam_collection_id'=>$ids,'exam_collection_type'=>3,'endtime'=>0])->find();
  106. if(!empty($info)){
  107. if($info['seat_id']>0 && $this->auth->seat_id!=$info['seat_id']){
  108. $this->error('已在其他座号有开始的考试,不允许换座号');
  109. }
  110. $this->exam_model->where('exam_id',$info['exam_id'])->update(['seat_id'=>$this->auth->seat_id]);
  111. $info['seat_id'] = $this->auth->seat_id;
  112. // $sim = Db::name('sim')->where('seat_id',$this->auth->seat_id)->find();
  113. $sim = Db::name('sim')->where('sim_type',$info['sim_type'])->find();
  114. $sim_text = '';
  115. if(!empty($sim)){
  116. if($sim['sim_state']==1){
  117. $sim_text = '在线';
  118. }else if($sim['sim_state']==2){
  119. $sim_text = '模拟器离线';
  120. }else if($sim['sim_state']==3){
  121. $sim_text = '网关离线';
  122. }else if($sim['sim_state']==4){
  123. $sim_text = '硬件故障异常';
  124. }else if($sim['sim_state']==5){
  125. $sim_text = '手动禁用';
  126. }
  127. }
  128. // 模拟器状态 0:可用初始化 1:在线 2:模拟器离线 3:网关离线 4:硬件故障异常 5:手动禁用
  129. $info['sim_text'] = $sim_text;
  130. }
  131. if(!empty($info['starttime']))
  132. {
  133. echo "<script>location.href='/ZQOtIMLKud.php/student/collection/examing/ids/".$info['exam_id']."'</script>";
  134. die();
  135. }
  136. $this->view->assign('info', $info);
  137. $this->view->assign('row', $row);
  138. $this->assignConfig('exam_id', $info['exam_id']);
  139. $this->assignConfig('url_type', config('site.url_type'));
  140. $this->assignConfig('is_fault', Env::get('app.is_fault'));
  141. return $this->view->fetch();
  142. }
  143. public function examing($ids = null)
  144. {
  145. $row = $this->exam_model->get($ids);
  146. if(!$row){
  147. $this->error('未找到记录');
  148. }
  149. if ($this->request->isPost()) {
  150. //先请求接口判断,再进行处理
  151. if(Env::get('app.is_fault')){
  152. $url = config('site.url_type').'/sim/real-exam/student/exam/submit/'.$ids;
  153. // /dev-api/sim/real-exam/student/exam/submit/{examId}
  154. $ret = json_decode(send_get($url),true);
  155. // halt($ret);
  156. if($ret['code']!=200){
  157. $this->error($ret['msg']);
  158. }
  159. }
  160. //计算分数,保存记录
  161. $params = $this->request->post('row/a');
  162. $result = false;
  163. $score = 100;
  164. $fault_one_score = 25;
  165. $fault_two_score = 25;
  166. $fault_three_score = 25;
  167. //故障现象
  168. $xianxian_score = 0;
  169. $xianxian_arr = [];
  170. $xianxian_content = [];
  171. //故障部位
  172. $buwei_score= 0;
  173. $buwei_arr = [];
  174. $buwei_content = [];
  175. //可能原因
  176. $yuanyin_socre= 0;
  177. $yuanyin_arr = [];
  178. $yuanyin_content = [];
  179. //排除方法
  180. $fangfa_score= 0;
  181. $fangfa_arr = [];
  182. $fangfa_content = [];
  183. Db::startTrans();
  184. try {
  185. //更新考试结束时间
  186. $row->end_time = date('Y-m-d H:i:s');
  187. $row->endtime = time();
  188. $row->exam_status = 5;
  189. $row->other_report = $params['other_report'];
  190. $result = $row->save();
  191. $info = $this->exam_model->where(['exam_id'=>$ids])->find();
  192. //更新故障是否正确
  193. $fault_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1])->select();
  194. if(!empty($fault_list)){
  195. foreach ($fault_list as $k =>$t){
  196. $answer_right = 2;
  197. if(!empty($t['sim_fault_question_value']) && !empty($t['sim_fault_answer_value'])){
  198. if($t['sim_fault_question_value']!=$t['sim_fault_answer_value'] ){
  199. //真实故障id 000200010001
  200. if($t['sim_fault_answer_value']=='00000000' && $t['fault_id'] !='000200010001'){
  201. $answer_right=2;
  202. }
  203. $answer_right=1;
  204. }
  205. }
  206. Db::name('real_exam_fault')->where(['ref_id'=>$t['ref_id']])->update(['answer_right'=>$answer_right]);
  207. }
  208. }
  209. //计算得分,故障是否有扣分 扣分制
  210. $fault_right_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1,'answer_right'=>['>',0]])->select();
  211. if(!empty($fault_right_list)){
  212. if($fault_right_list[0]['answer_right']==1){
  213. $fault_one_score = 0;
  214. }
  215. if($fault_right_list[1]['answer_right']==1){
  216. $fault_two_score = 0;
  217. }
  218. if($fault_right_list[2]['answer_right']==1){
  219. $fault_three_score = 0;
  220. }
  221. //根据故障部位 数组
  222. $fault_arr = [$fault_right_list[0]['fault_id'],$fault_right_list[1]['fault_id'],$fault_right_list[2]['fault_id']];
  223. //查找故障现象 数组
  224. $partent_fault_id = Fault::where(['fault_id'=>['in',$fault_arr]])->column('parent_fault_id');
  225. $issetValue = '';
  226. $issetValue_count = 0;
  227. //出题的 判断故障现象 是否有重复的,拿出重复的fault_id 和重复次数
  228. $countedValues = array_count_values($partent_fault_id);
  229. foreach ($countedValues as $value => $count) {
  230. if ($count > 1) {
  231. $issetValue = $value;
  232. $issetValue_count = $count;
  233. }
  234. }
  235. $other_report = json_decode($params['other_report'],true);
  236. if(!empty($other_report)){
  237. foreach ($other_report as $key => $em){
  238. //故障现象
  239. $xianxian_arr[] = $em['xx_id'];
  240. //故障部位
  241. $buwei_arr[] = $em['bw_id'];
  242. }
  243. //可能原因
  244. //排除方法
  245. }
  246. echo "<pre>";
  247. print_r($fault_arr);
  248. echo "<pre>";
  249. print_r($buwei_arr);
  250. $xxValue = '';
  251. $xxValue_count = 0;
  252. //维修报告 判断故障现象 是否有重复的,拿出重复的fault_id 和重复次数
  253. $xxcountedValues = array_count_values($xianxian_arr);
  254. foreach ($xxcountedValues as $v => $t) {
  255. if ($t > 1) {
  256. $xxValue = $v;
  257. $xxValue_count = $t;
  258. }
  259. }
  260. //故障现象 判断数量是否一致,
  261. if(count($partent_fault_id)!=count($xianxian_arr)){
  262. //少写
  263. $xianxian_arr_count = count($xianxian_arr) ;
  264. $xianxian_score = (3-1*$xianxian_arr_count)+$xianxian_score;
  265. //计算故障现象分数
  266. if($xianxian_arr_count==1){
  267. $count = count(array_keys($partent_fault_id, $xianxian_arr[0])); // 更准确的方法是使用下面
  268. $xianxian_score = $count>1? 1*$count+$xianxian_score:(3-1*$count)+$xianxian_score;
  269. }
  270. if($xianxian_arr_count==2){
  271. foreach ($partent_fault_id as $k1 =>$t){
  272. if(!in_array($t,$xianxian_arr)){
  273. //错写
  274. $xianxian_score = 1+$xianxian_score;
  275. echo "错写:".$t."@@@@".$xianxian_score."<br/>";
  276. }
  277. }
  278. foreach ($xianxian_arr as $k2 =>$t2){
  279. if(!in_array($t2,$partent_fault_id)){
  280. //多写
  281. $xianxian_score = 1+$xianxian_score;
  282. echo "多写:".$t2."@@@@".$xianxian_score."<br/>";
  283. }
  284. }
  285. }
  286. echo "<pre>";
  287. echo $xianxian_score;
  288. die('asdfasdf');
  289. }else{ //数量相同
  290. //计算故障现象分数
  291. foreach ($partent_fault_id as $k1 =>$t){
  292. if(!in_array($t,$xianxian_arr)){
  293. //少写
  294. $xianxian_score = 1+$xianxian_score;
  295. $xianxian_content[] = [
  296. 'cx_id'=>$t,
  297. 'cx_type'=>'少写',
  298. 'cx_name'=>Fault::where(['fault_id'=>$t])->value('name'),
  299. ];
  300. }
  301. }
  302. foreach ($xianxian_arr as $k2 =>$t2){
  303. if(!in_array($t2,$partent_fault_id)){
  304. //错写
  305. $xianxian_score = 1+$xianxian_score;
  306. $xianxian_content[] = [
  307. 'cx_id'=>$t2,
  308. 'cx_type'=>'错写',
  309. 'cx_name'=>Fault::where(['fault_id'=>$t2])->value('name'),
  310. ];
  311. //多写
  312. $xianxian_score = 1+$xianxian_score;
  313. // echo "多写:".$t2."@@@@".$xianxian_score."<br/>";
  314. $xianxian_content[] = [
  315. 'cx_id'=>$t2,
  316. 'cx_type'=>'多写',
  317. 'cx_name'=>Fault::where(['fault_id'=>$t2])->value('name'),
  318. ];
  319. }
  320. }
  321. if($xxValue_count!=$issetValue_count){
  322. //错写
  323. $xianxian_score = 1+$xianxian_score;
  324. $xianxian_content[] = [
  325. 'cx_id'=>$xxValue,
  326. 'cx_type'=>'错写',
  327. 'cx_name'=>Fault::where(['fault_id'=>$xxValue])->value('name'),
  328. ];
  329. //多写
  330. $xianxian_score = 1+$xianxian_score;
  331. $xianxian_content[] = [
  332. 'cx_id'=>$xxValue,
  333. 'cx_type'=>'多写',
  334. 'cx_name'=>Fault::where(['fault_id'=>$xxValue])->value('name'),
  335. ];
  336. // echo "多写:".$xxValue."####".$xianxian_score."<br/>";
  337. }
  338. }
  339. //故障部位 数量不相同
  340. if(count($fault_arr)!=count($buwei_arr)){
  341. }else{ //数量相同
  342. halt('数量相同');
  343. }
  344. // echo "<pre>";
  345. // echo $xianxian_score;
  346. // die();
  347. // if(count($other_report)<3){
  348. // $xianxian_score = 15-5*count($other_report)+$xianxian_score;
  349. // $buwei_score = 3-1*count($other_report)+$buwei_score;
  350. // $yuanyin_socre = 3-1*count($other_report)+$yuanyin_socre;
  351. // $fangfa_score = 3-1*count($other_report)+$fangfa_score;
  352. // }
  353. // foreach ($other_report as $key => $em){
  354. // //故障现象
  355. // if(!in_array($em['xx_id'],$partent_fault_id)){
  356. // $xianxian_score = 5+$xianxian_score;
  357. // $xianxian_arr[] = $em['xx_id'];
  358. // }
  359. //
  360. // //故障部位
  361. // if(!empty($em['bw_id'])){
  362. // $report_xx_id = Report::where(['bw_id'=>['in',$em['bw_id']]])->column('xx_id');
  363. // if(!in_array($em['xx_id'],$report_xx_id)){ //现象不对,直接扣分
  364. // $buwei_score = 1+$buwei_score;
  365. // $buwei_arr[] = $em['bw_id'];
  366. // }else{
  367. // //现象正确,判断是不是正确的选项
  368. // foreach (explode(',',$em['bw_id']) as $s => $bs){
  369. // if(!in_array($bs,$fault_arr)){
  370. // $buwei_score = 1+$buwei_score;
  371. // $buwei_arr[] = $bs;
  372. // }
  373. // }
  374. // }
  375. // }else{
  376. // //部位为空 +1
  377. // $buwei_score = 1+ $buwei_score;
  378. // }
  379. //
  380. //
  381. // //可能原因
  382. // if(!empty($em['yy_id'])){
  383. // $report_bw_id = Report::where(['yy_id'=>['in',$em['yy_id']]])->column('bw_id');
  384. // if(!in_array($em['bw_id'],$report_bw_id)){ //现象不对,直接扣分
  385. // $yuanyin_socre = 1+$yuanyin_socre;
  386. // $yuanyin_arr[] = $em['yy_id'];
  387. // }else{
  388. //
  389. // }
  390. // }else{
  391. // //部位为空 +1
  392. // $yuanyin_socre = 1+$yuanyin_socre;
  393. // }
  394. //
  395. // //排除方法
  396. // if(!empty($em['pc_id'])){
  397. // $report_pc_id = Report::where(['pc_id'=>['in',$em['pc_id']]])->column('bw_id');
  398. // if(!in_array($em['bw_id'],$report_pc_id)){ //现象不对,直接扣分
  399. // $fangfa_score = 1+$fangfa_score;
  400. // $fangfa_arr[] = $em['pc_id'];
  401. // }else{
  402. //
  403. // }
  404. // }else{
  405. // $fangfa_score = 1+$fangfa_score;
  406. // }
  407. // }
  408. }
  409. // echo "<pre>";
  410. // print_r($buwei_arr);
  411. // echo '原因:'.$yuanyin_socre.'<br/>';
  412. // echo '部位:'.$buwei_score.'<br/>';
  413. // echo '现象:'.$xianxian_score;
  414. // die();
  415. $weixiu_score = $xianxian_score+$yuanyin_socre+$buwei_score+$fangfa_score;
  416. if($weixiu_score>15){
  417. $weixiu_score = 15;
  418. }
  419. //是否超时
  420. $overtime_fen = intval((time()-$info['endtime']) / 60);
  421. if($overtime_fen>=10){
  422. $overtime_score = 10;
  423. }else if($overtime_fen>0 && $overtime_fen<10){
  424. $overtime_score = $overtime_fen ;
  425. }else{
  426. $overtime_score =0;
  427. }
  428. $fault_score = $score-$fault_one_score-$fault_two_score-$fault_three_score-$weixiu_score-$overtime_score;
  429. //更新考试结果表
  430. $params['exam_id'] = $ids;
  431. $params['total'] = $fault_score;//得分;
  432. $params['fault_one_score'] = $fault_one_score;//得分;
  433. $params['fault_two_score'] = $fault_two_score;//得分;
  434. $params['fault_three_score'] = $fault_three_score;//得分;
  435. $params['xianxian_score'] = $xianxian_score;//得分;
  436. $params['xianxian_content'] = json_encode($xianxian_content);//错题;
  437. // $params['yuanyin_socre'] = $yuanyin_socre;//得分;
  438. // $params['yuanyin_content'] = !empty($yuanyin_arr) ? json_encode($yuanyin_arr) : '';//错题;
  439. // $params['buwei_score'] = $buwei_score;//得分;
  440. // $params['buwei_content'] = !empty($buwei_arr) ? json_encode($buwei_arr) :'';//错题;
  441. // $params['fangfa_score'] = $fangfa_score;//得分;
  442. // $params['fangfa_content'] = !empty($fangfa_arr) ? json_encode($fangfa_arr):'';//错题;
  443. // $params['jielun_score'] = $jielun_score;//得分;
  444. $params['overtime_score'] = $overtime_score;//得分;
  445. Db::name('real_exam_score')->insert($params);
  446. $this->exam_model->where(['exam_id'=>$ids])->update(['total_score'=>$fault_score]);
  447. Db::commit();
  448. } catch (ValidateException|PDOException|Exception $e) {
  449. Db::rollback();
  450. $this->error($e->getMessage());
  451. }
  452. if ($result === false) {
  453. $this->error(__('No rows were inserted'));
  454. }
  455. $this->success('交卷成功,待老师确认成绩','/ZQOtIMLKud.php/student/exam/index');
  456. }
  457. if(empty($row->starttime)){
  458. $row->start_time = date('Y-m-d H:i:s');
  459. $row->starttime = time();
  460. $row->exam_status = 4;
  461. $row->save();
  462. }
  463. $isloading =1;
  464. if(empty($row->other_replace)){
  465. $isloading = 0;
  466. $row->other_replace = '[{"fault_id":"","request_status":"0"}]';
  467. }
  468. $row->other_report_text = !empty($row->other_report) ? json_decode($row->other_report,true) : [];
  469. $other_report_count = !empty($row->other_report) ? count(json_decode($row->other_report,true)) :0;
  470. //还未开始考试
  471. $row->limit_duration = $this->model->where(['exam_collection_id'=>$row['exam_collection_id']])->value('limit_duration');
  472. if(empty($row->starttime)){
  473. $timer = 60*$row->limit_duration;
  474. }else{
  475. $timer = $row->limit_duration*60 - abs(time() - $row->starttime);
  476. }
  477. $row->replace_list =Db::name('real_exam_comp_request')->where(['exam_id'=>$ids])->select();
  478. $this->assignConfig('ids',$ids);
  479. $this->assignConfig('timer',$timer);
  480. $this->assignConfig('isloading',$isloading);
  481. $this->assignConfig('other_report_count',$other_report_count);
  482. $this->view->assign('row', $row);
  483. $departmentdata = [];
  484. $departmentdata = Fault::where(['replace_part'=>1,'sim_type'=>$row->sim_type])->order('fault_id asc')->select();
  485. //更换件数据
  486. $this->view->assign('departmentdata', $departmentdata);
  487. //故障现象
  488. $xianxiang = Fault::where(['fault_type'=>1,'sim_type'=>$row->sim_type])->select();
  489. $this->view->assign('xianxiang', $xianxiang);
  490. //可能原因
  491. $yuanyin = Fault::where(['fault_type'=>2,'sim_type'=>$row->sim_type])->select();
  492. $this->view->assign('yuanyin', $yuanyin);
  493. //故障部位
  494. $buwei = Fault::where(['fault_type'=>3,'sim_type'=>$row->sim_type])->select();
  495. $this->view->assign('buwei', $buwei);
  496. //排除方法
  497. $paichu = Fault::where(['fault_type'=>4,'sim_type'=>$row->sim_type])->select();
  498. $this->view->assign('paichu', $paichu);
  499. return $this->view->fetch();
  500. }
  501. public function replace($ids = null)
  502. {
  503. if ($this->request->isPost()) {
  504. $params = $this->request->post('other_replace','');
  505. $other_report = $this->request->post('other_report','');
  506. $param = json_decode($params,true);
  507. if(!empty($param)){
  508. $faultid_arr = [];
  509. foreach ($param as $key=>$item){
  510. if(!empty($item['fault_id'])){
  511. $isreplace = Db::name('real_exam_comp_request')->where(['exam_id'=>$ids,'fault_id'=>$item['fault_id']])->find();
  512. if(empty($isreplace)){
  513. $add = [
  514. 'exam_id'=>$ids,
  515. 'fault_id'=>$item['fault_id'],
  516. 'request_status'=>1,
  517. 'fault_name'=>Db::name('fault')->where('fault_id',$item['fault_id'])->value('replace_name'),
  518. 'create_by_user_id'=>$this->auth->id,
  519. 'create_by'=>$this->auth->nickname,
  520. 'createtime'=>time(),
  521. 'updatetime'=>time(),
  522. 'create_time'=>date('Y-m-d H:i:s'),
  523. 'update_time'=>date('Y-m-d H:i:s'),
  524. ];
  525. Db::name('real_exam_comp_request')->insert($add);
  526. $status = 1;
  527. }else{
  528. $status = $isreplace['request_status'];
  529. }
  530. $faultid_arr[] = [
  531. 'fault_id'=>$item['fault_id'],
  532. 'request_status'=>$status,
  533. ];
  534. }
  535. }
  536. unset($item);
  537. $row = $this->exam_model->get($ids);
  538. $row-> other_replace = $faultid_arr ? json_encode($faultid_arr):'';
  539. $row-> other_report = $other_report;
  540. $result = $row->save();
  541. }
  542. $this->success('申请成功,待老师审批');
  543. }
  544. }
  545. /**
  546. * @Notes:添加维修报告
  547. * @Author: jxb
  548. * @Date: 2025/1/21
  549. * @Time: 10:29
  550. */
  551. public function addreport($ids = null){
  552. $row = $this->exam_model->get($ids);
  553. if(!$row){
  554. $this->error('未找到记录');
  555. }
  556. if ($this->request->isPost()) {
  557. $unwin = $this->request->post('unwin/a');
  558. $arr = [];
  559. if(!empty($unwin)){
  560. $xx_name = Fault::where('fault_id',$unwin['xx_id'])->value('name');
  561. $yy_name = Fault::where('fault_id','in',$unwin['yy_id'])->column('name');
  562. $bw_name = Fault::where('fault_id','in',$unwin['bw_id'])->column('name');
  563. $pc_name = Fault::where('fault_id','in',$unwin['pc_id'])->column('name');
  564. $arr = [
  565. 'xh_id' => $unwin['xh_id'],
  566. 'xx_id' => $unwin['xx_id'],
  567. 'xx_name'=>$xx_name,
  568. 'yy_id' => implode(',',$unwin['yy_id']),
  569. 'yy_name' => implode(',',$yy_name),
  570. 'bw_id' => implode(',',$unwin['bw_id']),
  571. 'bw_name' => implode(',',$bw_name),
  572. 'pc_id' => implode(',',$unwin['pc_id']),
  573. 'pc_name' => implode(',',$pc_name),
  574. ];
  575. }
  576. $other_report = !empty($row->other_report) ? json_decode($row->other_report,true) : [];
  577. array_push($other_report,$arr);
  578. $row->other_report = json_encode($other_report);
  579. $row->save();
  580. $this->success();
  581. }
  582. //故障现象
  583. $xianxiang = Fault::where(['fault_type'=>1,'sim_type'=>$row->sim_type])->select();
  584. $this->view->assign('xianxiang', $xianxiang);
  585. //可能原因
  586. $yuanyin = Fault::where(['fault_type'=>2,'sim_type'=>$row->sim_type])->column('fault_id,name');
  587. $this->view->assign('yuanyin', $yuanyin);
  588. //故障部位
  589. $buwei = Fault::where(['fault_type'=>3,'sim_type'=>$row->sim_type])->column('fault_id,name');
  590. $this->view->assign('buwei', $buwei);
  591. //排除方法
  592. $paichu = Fault::where(['fault_type'=>4,'sim_type'=>$row->sim_type])->column('fault_id,name');
  593. $this->view->assign('paichu', $paichu);
  594. $row->other_report_count = 0;
  595. if(!empty($row->other_report)){
  596. $row->other_report_count = count(json_decode($row->other_report,true));
  597. }
  598. $this->view->assign('row', $row);
  599. return $this->view->fetch();
  600. }
  601. /**
  602. * @Notes:编辑报告
  603. * @Author: jxb
  604. * @Date: 2025/1/21
  605. * @Time: 15:04
  606. */
  607. public function editreport($ids = null,$xh_id = null){
  608. $row = $this->exam_model->get($ids);
  609. if(!$row){
  610. $this->error('未找到记录');
  611. }
  612. if ($this->request->isPost()) {
  613. $unwin = $this->request->post('unwin/a');
  614. if(!empty($unwin)){
  615. $xx_name = Fault::where('fault_id',$unwin['xx_id'])->value('name');
  616. $yy_name = Fault::where('fault_id','in',$unwin['yy_id'])->column('name');
  617. $bw_name = Fault::where('fault_id','in',$unwin['bw_id'])->column('name');
  618. $pc_name = Fault::where('fault_id','in',$unwin['pc_id'])->column('name');
  619. $other_report = !empty($row->other_report) ? json_decode($row->other_report,true) : [];
  620. foreach ($other_report as $k =>$item){
  621. if($k==$xh_id){
  622. $other_report[$k]['xx_id'] =$unwin['xx_id'];
  623. $other_report[$k]['xx_name'] =$xx_name;
  624. $other_report[$k]['yy_id'] = implode(',',$unwin['yy_id']);
  625. $other_report[$k]['yy_name'] =implode(',',$yy_name);
  626. $other_report[$k]['bw_id'] = implode(',',$unwin['bw_id']);
  627. $other_report[$k]['bw_name'] =implode(',',$bw_name);
  628. $other_report[$k]['pc_id'] =implode(',',$unwin['pc_id']);
  629. $other_report[$k]['pc_name'] =implode(',',$pc_name);
  630. }
  631. }
  632. $row->other_report = json_encode($other_report);
  633. $row->save();
  634. }
  635. $this->success();
  636. }
  637. //故障现象
  638. $xianxiang = Fault::where(['fault_type'=>1,'sim_type'=>$row->sim_type])->select();
  639. $this->view->assign('xianxiang', $xianxiang);
  640. //可能原因
  641. $yuanyin = Fault::where(['fault_type'=>2,'sim_type'=>$row->sim_type])->column('fault_id,name');
  642. $this->view->assign('yuanyin', $yuanyin);
  643. //故障部位
  644. $buwei = Fault::where(['fault_type'=>3,'sim_type'=>$row->sim_type])->column('fault_id,name');
  645. $this->view->assign('buwei', $buwei);
  646. //排除方法
  647. $paichu = Fault::where(['fault_type'=>4,'sim_type'=>$row->sim_type])->column('fault_id,name');
  648. $this->view->assign('paichu', $paichu);
  649. $row->other_report_text = [];
  650. if(!empty($row->other_report)){
  651. $other_report = json_decode($row->other_report,true);
  652. foreach ($other_report as $k =>$item){
  653. if($k==$xh_id){
  654. $row->other_report_text = [
  655. 'xx_id'=>$item['xx_id'],
  656. 'yy_id'=>explode(',',$item['yy_id']),
  657. 'bw_id'=>explode(',',$item['bw_id']),
  658. 'pc_id'=>explode(',',$item['pc_id']),
  659. 'xh_id'=>$item['xh_id']
  660. ];
  661. }
  662. }
  663. }
  664. $this->view->assign('row', $row);
  665. return $this->view->fetch();
  666. }
  667. /**
  668. * @Notes:移除 维修报告
  669. * @Author: jxb
  670. * @Date: 2025/1/21
  671. * @Time: 14:45
  672. */
  673. public function delreport($ids = null){
  674. $row = $this->exam_model->get($ids);
  675. if(!$row){
  676. $this->error('未找到记录');
  677. }
  678. if ($this->request->isPost()) {
  679. $xh_id = $this->request->post('xh_id');
  680. if(!empty($row->other_report)){
  681. $other_report = json_decode($row->other_report,true);
  682. unset($other_report[$xh_id]);
  683. $row->other_report = json_encode($other_report);
  684. $row->save();
  685. }
  686. $this->success();
  687. }
  688. }
  689. public function analysis($ids = null)
  690. {
  691. $row = $this->exam_model->get($ids);
  692. if(!$row){
  693. $this->error('未找到记录');
  694. }
  695. if ($this->request->isPost()) {
  696. $params = $this->request->post('row/a');
  697. //计算总分到学员考试表
  698. $this->success('操作成功','/ZQOtIMLKud.php/student/collection/index');
  699. }
  700. return $this->view->fetch();
  701. }
  702. }