Collection.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  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(!empty($this->auth->seat_id) && !empty($info['seat_id']) && $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. $ret = json_decode(send_get($url),true);
  154. // halt($ret);
  155. if($ret['code']!=200){
  156. $this->error($ret['msg']);
  157. }
  158. }
  159. //计算分数,保存记录
  160. $params = $this->request->post('row/a');
  161. $result = false;
  162. $score = 100;
  163. $fault_one_score = 25;
  164. $fault_two_score = 25;
  165. $fault_three_score = 25;
  166. //故障现象
  167. $xianxian_score = 0;
  168. $xianxian_arr = [];
  169. $xianxian_content = [];
  170. //故障部位
  171. $buwei_score= 0;
  172. $buwei_arr = [];
  173. $buwei_content = [];
  174. //可能原因
  175. $yuanyin_socre= 0;
  176. $yuanyin_arr = [];
  177. $yuanyin_content = [];
  178. //排除方法
  179. $fangfa_score= 0;
  180. $fangfa_arr = [];
  181. $fangfa_content = [];
  182. Db::startTrans();
  183. try {
  184. //更新考试结束时间
  185. $row->end_time = date('Y-m-d H:i:s');
  186. $row->endtime = time();
  187. $row->exam_status = 5;
  188. $row->other_report = $params['other_report'];
  189. $result = $row->save();
  190. $info = $this->exam_model->where(['exam_id'=>$ids])->find();
  191. //更新故障是否正确
  192. $fault_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1])->select();
  193. if(!empty($fault_list)){
  194. foreach ($fault_list as $k =>$t){
  195. $answer_right = 2;
  196. if(!empty($t['sim_fault_question_value']) && !empty($t['sim_fault_answer_value'])){
  197. if($t['sim_fault_question_value']!=$t['sim_fault_answer_value'] ){
  198. //真实故障id 000200010001
  199. if($t['sim_fault_answer_value']=='00000000' && $t['fault_id'] !='000200010001'){
  200. $answer_right=2;
  201. }
  202. $answer_right=1;
  203. }
  204. }
  205. Db::name('real_exam_fault')->where(['ref_id'=>$t['ref_id']])->update(['answer_right'=>$answer_right]);
  206. }
  207. }
  208. //计算得分,故障是否有扣分 扣分制
  209. $fault_right_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1,'answer_right'=>['>',0]])->select();
  210. if(!empty($fault_right_list)){
  211. if($fault_right_list[0]['answer_right']==1){
  212. $fault_one_score = 0;
  213. }
  214. if($fault_right_list[1]['answer_right']==1){
  215. $fault_two_score = 0;
  216. }
  217. if($fault_right_list[2]['answer_right']==1){
  218. $fault_three_score = 0;
  219. }
  220. //根据故障部位 数组
  221. $fault_arr = [$fault_right_list[0]['fault_id'],$fault_right_list[1]['fault_id'],$fault_right_list[2]['fault_id']];
  222. //根据故障部位查找,匹配的排除方法
  223. $paichu_arr = Report::where(['bw_id'=>['in',$fault_arr]])->column('pc_id');
  224. //根据故障部位查找,匹配可能原因
  225. $yy_arr = Report::where(['bw_id'=>['in',$fault_arr]])->column('yy_id');
  226. //查找故障现象 数组
  227. $partent_fault_id = Fault::where(['fault_id'=>['in',$fault_arr]])->column('parent_fault_id');
  228. $issetValue = '';
  229. $issetValue_count = 0;
  230. //出题的 判断故障现象 是否有重复的,拿出重复的fault_id 和重复次数
  231. $countedValues = array_count_values($partent_fault_id);
  232. foreach ($countedValues as $value => $count) {
  233. if ($count > 1) {
  234. $issetValue = $value;
  235. $issetValue_count = $count;
  236. }
  237. }
  238. $other_report = json_decode($params['other_report'],true);
  239. if(!empty($other_report)){
  240. foreach ($other_report as $key => $em){
  241. //故障现象
  242. $xianxian_arr[] = $em['xx_id'];
  243. //故障部位
  244. $buwei_arr[] = $em['bw_id'];
  245. //可能原因
  246. $yuanyin_arr[] = $em['yy_id'];
  247. //排除方法
  248. $fangfa_arr[] = $em['pc_id'];
  249. }
  250. }
  251. $xxValue = '';
  252. $xxValue_count = 0;
  253. //维修报告 判断故障现象 是否有重复的,拿出重复的fault_id 和重复次数
  254. $xxcountedValues = array_count_values($xianxian_arr);
  255. foreach ($xxcountedValues as $v => $t) {
  256. if ($t > 1) {
  257. $xxValue = $v;
  258. $xxValue_count = $t;
  259. }
  260. }
  261. //故障现象 判断数量是否一致,
  262. if(count($partent_fault_id)!=count($xianxian_arr)){
  263. foreach ($partent_fault_id as $k0 =>$t0){
  264. if(!in_array($t0,$xianxian_arr)){
  265. //错写
  266. $xianxian_score = 1+$xianxian_score;
  267. // echo "错写:".$t0."@@@@".$xianxian_score."<br/>";
  268. $xianxian_content[] = [
  269. 'cx_id'=>$t0,
  270. 'cx_type'=>'错写',
  271. 'cx_name'=>Fault::where(['fault_id'=>$t0])->value('name'),
  272. ];
  273. $xianxian_score = 1+$xianxian_score;
  274. // echo "少写:".$t0."@@@@".$xianxian_score."<br/>";
  275. $xianxian_content[] = [
  276. 'cx_id'=>$t0,
  277. 'cx_type'=>'少写',
  278. 'cx_name'=>Fault::where(['fault_id'=>$t0])->value('name'),
  279. ];
  280. }
  281. }
  282. foreach ($xianxian_arr as $k01 =>$t01){
  283. if(!in_array($t01,$partent_fault_id)){
  284. $xianxian_score = 1+$xianxian_score;
  285. // echo "多写:".$t01."@@@@".$xianxian_score."<br/>";
  286. $xianxian_content[] = [
  287. 'cx_id'=>$t01,
  288. 'cx_type'=>'多写',
  289. 'cx_name'=>Fault::where(['fault_id'=>$t01])->value('name'),
  290. ];
  291. }
  292. }
  293. }else{ //数量相同
  294. //计算故障现象分数
  295. foreach ($partent_fault_id as $k1 =>$t){
  296. if(!in_array($t,$xianxian_arr)){
  297. $xianxian_score = 1+$xianxian_score;
  298. $xianxian_content[] = [
  299. 'cx_id'=>$t,
  300. 'cx_type'=>'少写',
  301. 'cx_name'=>Fault::where(['fault_id'=>$t])->value('name'),
  302. ];
  303. }
  304. }
  305. foreach ($xianxian_arr as $k2 =>$t2){
  306. if(!in_array($t2,$partent_fault_id)){
  307. $xianxian_score = 1+$xianxian_score;
  308. $xianxian_content[] = [
  309. 'cx_id'=>$t2,
  310. 'cx_type'=>'错写',
  311. 'cx_name'=>Fault::where(['fault_id'=>$t2])->value('name'),
  312. ];
  313. $xianxian_score = 1+$xianxian_score;
  314. // echo "多写:".$t2."@@@@".$xianxian_score."<br/>";
  315. $xianxian_content[] = [
  316. 'cx_id'=>$t2,
  317. 'cx_type'=>'多写',
  318. 'cx_name'=>Fault::where(['fault_id'=>$t2])->value('name'),
  319. ];
  320. }
  321. }
  322. if($xxValue_count!=$issetValue_count){
  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. //故障部位 start
  340. foreach ($fault_arr as $k11 =>$t11){
  341. if(!in_array($t11,$buwei_arr)){
  342. $buwei_score = 1+$buwei_score;
  343. $buwei_content[] = [
  344. 'cx_id'=>$t11,
  345. 'cx_type'=>'少写',
  346. 'cx_name'=>Fault::where(['fault_id'=>$t11])->value('name'),
  347. ];
  348. }
  349. }
  350. foreach ($buwei_arr as $k12 =>$t12){
  351. if(!empty($t12) && !in_array($t12,$fault_arr)){
  352. //错写
  353. $buwei_score = 1+$buwei_score;
  354. $buwei_content[] = [
  355. 'cx_id'=>$t12,
  356. 'cx_type'=>'错写',
  357. 'cx_name'=>Fault::where(['fault_id'=>$t12])->value('name'),
  358. ];
  359. //多写
  360. $buwei_score = 1+$buwei_score;
  361. $buwei_content[] = [
  362. 'cx_id'=>$t12,
  363. 'cx_type'=>'多写',
  364. 'cx_name'=>Fault::where(['fault_id'=>$t12])->value('name'),
  365. ];
  366. }
  367. }
  368. //故障部位 end
  369. //排除方法 start
  370. //循环固定的排除方法,匹配作答的排除方法
  371. foreach ($paichu_arr as $k21 =>$t21){
  372. if(!in_array($t21,$fangfa_arr)){
  373. $fangfa_score = 1+$fangfa_score;
  374. $fangfa_content[] = [
  375. 'cx_id'=>$t21,
  376. 'cx_type'=>'少写',
  377. 'cx_name'=>Fault::where(['fault_id'=>$t21])->value('name'),
  378. ];
  379. }
  380. }
  381. //循环作答的排除方法,,匹配固定的排除方法
  382. foreach ($fangfa_arr as $k22 =>$t22){
  383. if(!empty($t22) && !in_array($t22,$paichu_arr)){
  384. $fangfa_score = 1+$fangfa_score;
  385. $fangfa_content[] = [
  386. 'cx_id'=>$t22,
  387. 'cx_type'=>'错写',
  388. 'cx_name'=>Fault::where(['fault_id'=>$t22])->value('name'),
  389. ];
  390. $fangfa_score = 1+$fangfa_score;
  391. $fangfa_content[] = [
  392. 'cx_id'=>$t22,
  393. 'cx_type'=>'多写',
  394. 'cx_name'=>Fault::where(['fault_id'=>$t22])->value('name'),
  395. ];
  396. }
  397. }
  398. //排除方法 end
  399. //可能原因 start
  400. //循环固定的可能原因,匹配作答的可能原因
  401. foreach ($yy_arr as $k31 =>$t31){
  402. if(!in_array($t31,$yuanyin_arr)){
  403. $yuanyin_socre = 1+$yuanyin_socre;
  404. $yuanyin_content[] = [
  405. 'cx_id'=>$t31,
  406. 'cx_type'=>'少写',
  407. 'cx_name'=>Fault::where(['fault_id'=>$t31])->value('name'),
  408. ];
  409. }
  410. }
  411. //循环作答的排除方法,,匹配固定的排除方法
  412. foreach ($yuanyin_arr as $k32 =>$t32){
  413. if(!empty($t32) && !in_array($t32,$yy_arr)){
  414. $yuanyin_socre = 1+$yuanyin_socre;
  415. $yuanyin_content[] = [
  416. 'cx_id'=>$t32,
  417. 'cx_type'=>'错写',
  418. 'cx_name'=>Fault::where(['fault_id'=>$t32])->value('name'),
  419. ];
  420. $yuanyin_socre = 1+$yuanyin_socre;
  421. $yuanyin_content[] = [
  422. 'cx_id'=>$t32,
  423. 'cx_type'=>'多写',
  424. 'cx_name'=>Fault::where(['fault_id'=>$t32])->value('name'),
  425. ];
  426. }
  427. }
  428. //可能原因 end
  429. }
  430. $weixiu_score = $xianxian_score+$yuanyin_socre+$buwei_score+$fangfa_score;
  431. if($weixiu_score>15){
  432. $weixiu_score = 15;
  433. }
  434. //是否超时
  435. $overtime_fen = intval((time()-$info['endtime']) / 60);
  436. if($overtime_fen>=10){
  437. $overtime_score = 10;
  438. }else if($overtime_fen>0 && $overtime_fen<10){
  439. $overtime_score = $overtime_fen ;
  440. }else{
  441. $overtime_score =0;
  442. }
  443. $fault_score = $score-$fault_one_score-$fault_two_score-$fault_three_score-$weixiu_score-$overtime_score;
  444. //更新考试结果表
  445. $params['exam_id'] = $ids;
  446. $params['total'] = $fault_score;//得分;
  447. $params['fault_one_score'] = $fault_one_score;//得分;
  448. $params['fault_two_score'] = $fault_two_score;//得分;
  449. $params['fault_three_score'] = $fault_three_score;//得分;
  450. $params['xianxian_score'] = $xianxian_score;//得分;
  451. $params['xianxian_content'] = json_encode($xianxian_content);//错题;
  452. // $params['yuanyin_socre'] = $yuanyin_socre;//得分;
  453. // $params['yuanyin_content'] = !empty($yuanyin_arr) ? json_encode($yuanyin_arr) : '';//错题;
  454. $params['buwei_score'] = $buwei_score;//得分;
  455. $params['buwei_content'] = json_encode($buwei_content);//错题;
  456. // $params['fangfa_score'] = $fangfa_score;//得分;
  457. // $params['fangfa_content'] = !empty($fangfa_arr) ? json_encode($fangfa_arr):'';//错题;
  458. // $params['jielun_score'] = $jielun_score;//得分;
  459. $params['overtime_score'] = $overtime_score;//得分;
  460. Db::name('real_exam_score')->insert($params);
  461. $this->exam_model->where(['exam_id'=>$ids])->update(['total_score'=>$fault_score]);
  462. Db::commit();
  463. } catch (ValidateException|PDOException|Exception $e) {
  464. Db::rollback();
  465. $this->error($e->getMessage());
  466. }
  467. if ($result === false) {
  468. $this->error(__('No rows were inserted'));
  469. }
  470. $this->success('交卷成功,待老师确认成绩','/ZQOtIMLKud.php/student/exam/index');
  471. }
  472. if(empty($row->starttime)){
  473. $row->start_time = date('Y-m-d H:i:s');
  474. $row->starttime = time();
  475. $row->exam_status = 4;
  476. $row->save();
  477. }
  478. $isloading =1;
  479. if(empty($row->other_replace)){
  480. $isloading = 0;
  481. $row->other_replace = '[{"fault_id":"","request_status":"0"}]';
  482. }
  483. $row->other_report_text = !empty($row->other_report) ? json_decode($row->other_report,true) : [];
  484. $other_report_count = !empty($row->other_report) ? count(json_decode($row->other_report,true)) :0;
  485. //还未开始考试
  486. $row->limit_duration = $this->model->where(['exam_collection_id'=>$row['exam_collection_id']])->value('limit_duration');
  487. if(empty($row->starttime)){
  488. $timer = 60*$row->limit_duration;
  489. }else{
  490. $timer = $row->limit_duration*60 - abs(time() - $row->starttime);
  491. }
  492. $row->replace_list =Db::name('real_exam_comp_request')->where(['exam_id'=>$ids])->select();
  493. $this->assignConfig('ids',$ids);
  494. $this->assignConfig('timer',$timer);
  495. $this->assignConfig('isloading',$isloading);
  496. $this->assignConfig('other_report_count',$other_report_count);
  497. $this->view->assign('row', $row);
  498. $departmentdata = [];
  499. $departmentdata = Fault::where(['replace_part'=>1,'sim_type'=>$row->sim_type])->order('fault_id asc')->select();
  500. //更换件数据
  501. $this->view->assign('departmentdata', $departmentdata);
  502. //故障现象
  503. $xianxiang = Fault::where(['fault_type'=>1,'sim_type'=>$row->sim_type])->select();
  504. $this->view->assign('xianxiang', $xianxiang);
  505. //可能原因
  506. $yuanyin = Fault::where(['fault_type'=>2,'sim_type'=>$row->sim_type])->select();
  507. $this->view->assign('yuanyin', $yuanyin);
  508. //故障部位
  509. $buwei = Fault::where(['fault_type'=>3,'sim_type'=>$row->sim_type])->select();
  510. $this->view->assign('buwei', $buwei);
  511. //排除方法
  512. $paichu = Fault::where(['fault_type'=>4,'sim_type'=>$row->sim_type])->select();
  513. $this->view->assign('paichu', $paichu);
  514. return $this->view->fetch();
  515. }
  516. public function replace($ids = null)
  517. {
  518. if ($this->request->isPost()) {
  519. $params = $this->request->post('other_replace','');
  520. $other_report = $this->request->post('other_report','');
  521. $param = json_decode($params,true);
  522. if(!empty($param)){
  523. $faultid_arr = [];
  524. foreach ($param as $key=>$item){
  525. if(!empty($item['fault_id'])){
  526. $isreplace = Db::name('real_exam_comp_request')->where(['exam_id'=>$ids,'fault_id'=>$item['fault_id']])->find();
  527. if(empty($isreplace)){
  528. $add = [
  529. 'exam_id'=>$ids,
  530. 'fault_id'=>$item['fault_id'],
  531. 'request_status'=>1,
  532. 'fault_name'=>Db::name('fault')->where('fault_id',$item['fault_id'])->value('replace_name'),
  533. 'create_by_user_id'=>$this->auth->id,
  534. 'create_by'=>$this->auth->nickname,
  535. 'createtime'=>time(),
  536. 'updatetime'=>time(),
  537. 'create_time'=>date('Y-m-d H:i:s'),
  538. 'update_time'=>date('Y-m-d H:i:s'),
  539. ];
  540. Db::name('real_exam_comp_request')->insert($add);
  541. $status = 1;
  542. }else{
  543. $status = $isreplace['request_status'];
  544. }
  545. $faultid_arr[] = [
  546. 'fault_id'=>$item['fault_id'],
  547. 'request_status'=>$status,
  548. ];
  549. }
  550. }
  551. unset($item);
  552. $row = $this->exam_model->get($ids);
  553. $row-> other_replace = $faultid_arr ? json_encode($faultid_arr):'';
  554. $row-> other_report = $other_report;
  555. $result = $row->save();
  556. }
  557. $this->success('申请成功,待老师审批');
  558. }
  559. }
  560. /**
  561. * @Notes:添加维修报告
  562. * @Author: jxb
  563. * @Date: 2025/1/21
  564. * @Time: 10:29
  565. */
  566. public function addreport($ids = null){
  567. $row = $this->exam_model->get($ids);
  568. if(!$row){
  569. $this->error('未找到记录');
  570. }
  571. if ($this->request->isPost()) {
  572. $unwin = $this->request->post('unwin/a');
  573. $arr = [];
  574. if(!empty($unwin)){
  575. $xx_name = Fault::where('fault_id',$unwin['xx_id'])->value('name');
  576. $yy_name = Fault::where('fault_id','in',$unwin['yy_id'])->column('name');
  577. $bw_name = Fault::where('fault_id','in',$unwin['bw_id'])->column('name');
  578. $pc_name = Fault::where('fault_id','in',$unwin['pc_id'])->column('name');
  579. $arr = [
  580. 'xh_id' => $unwin['xh_id'],
  581. 'xx_id' => $unwin['xx_id'],
  582. 'xx_name'=>$xx_name,
  583. 'yy_id' => implode(',',$unwin['yy_id']),
  584. 'yy_name' => implode(',',$yy_name),
  585. 'bw_id' => implode(',',$unwin['bw_id']),
  586. 'bw_name' => implode(',',$bw_name),
  587. 'pc_id' => implode(',',$unwin['pc_id']),
  588. 'pc_name' => implode(',',$pc_name),
  589. ];
  590. }
  591. $other_report = !empty($row->other_report) ? json_decode($row->other_report,true) : [];
  592. array_push($other_report,$arr);
  593. $row->other_report = json_encode($other_report);
  594. $row->save();
  595. $this->success();
  596. }
  597. //故障现象
  598. $xianxiang = Fault::where(['fault_type'=>1,'sim_type'=>$row->sim_type])->select();
  599. $this->view->assign('xianxiang', $xianxiang);
  600. //可能原因
  601. $yuanyin = Fault::where(['fault_type'=>2,'sim_type'=>$row->sim_type])->column('fault_id,name');
  602. $this->view->assign('yuanyin', $yuanyin);
  603. //故障部位
  604. $buwei = Fault::where(['fault_type'=>3,'sim_type'=>$row->sim_type])->column('fault_id,name');
  605. $this->view->assign('buwei', $buwei);
  606. //排除方法
  607. $paichu = Fault::where(['fault_type'=>4,'sim_type'=>$row->sim_type])->column('fault_id,name');
  608. $this->view->assign('paichu', $paichu);
  609. $row->other_report_count = 0;
  610. if(!empty($row->other_report)){
  611. $row->other_report_count = count(json_decode($row->other_report,true));
  612. }
  613. $this->view->assign('row', $row);
  614. return $this->view->fetch();
  615. }
  616. /**
  617. * @Notes:编辑报告
  618. * @Author: jxb
  619. * @Date: 2025/1/21
  620. * @Time: 15:04
  621. */
  622. public function editreport($ids = null,$xh_id = null){
  623. $row = $this->exam_model->get($ids);
  624. if(!$row){
  625. $this->error('未找到记录');
  626. }
  627. if ($this->request->isPost()) {
  628. $unwin = $this->request->post('unwin/a');
  629. if(!empty($unwin)){
  630. $xx_name = Fault::where('fault_id',$unwin['xx_id'])->value('name');
  631. $yy_name = Fault::where('fault_id','in',$unwin['yy_id'])->column('name');
  632. $bw_name = Fault::where('fault_id','in',$unwin['bw_id'])->column('name');
  633. $pc_name = Fault::where('fault_id','in',$unwin['pc_id'])->column('name');
  634. $other_report = !empty($row->other_report) ? json_decode($row->other_report,true) : [];
  635. foreach ($other_report as $k =>$item){
  636. if($k==$xh_id){
  637. $other_report[$k]['xx_id'] =$unwin['xx_id'];
  638. $other_report[$k]['xx_name'] =$xx_name;
  639. $other_report[$k]['yy_id'] = implode(',',$unwin['yy_id']);
  640. $other_report[$k]['yy_name'] =implode(',',$yy_name);
  641. $other_report[$k]['bw_id'] = implode(',',$unwin['bw_id']);
  642. $other_report[$k]['bw_name'] =implode(',',$bw_name);
  643. $other_report[$k]['pc_id'] =implode(',',$unwin['pc_id']);
  644. $other_report[$k]['pc_name'] =implode(',',$pc_name);
  645. }
  646. }
  647. $row->other_report = json_encode($other_report);
  648. $row->save();
  649. }
  650. $this->success();
  651. }
  652. //故障现象
  653. $xianxiang = Fault::where(['fault_type'=>1,'sim_type'=>$row->sim_type])->select();
  654. $this->view->assign('xianxiang', $xianxiang);
  655. //可能原因
  656. $yuanyin = Fault::where(['fault_type'=>2,'sim_type'=>$row->sim_type])->column('fault_id,name');
  657. $this->view->assign('yuanyin', $yuanyin);
  658. //故障部位
  659. $buwei = Fault::where(['fault_type'=>3,'sim_type'=>$row->sim_type])->column('fault_id,name');
  660. $this->view->assign('buwei', $buwei);
  661. //排除方法
  662. $paichu = Fault::where(['fault_type'=>4,'sim_type'=>$row->sim_type])->column('fault_id,name');
  663. $this->view->assign('paichu', $paichu);
  664. $row->other_report_text = [];
  665. if(!empty($row->other_report)){
  666. $other_report = json_decode($row->other_report,true);
  667. foreach ($other_report as $k =>$item){
  668. if($k==$xh_id){
  669. $row->other_report_text = [
  670. 'xx_id'=>$item['xx_id'],
  671. 'yy_id'=>explode(',',$item['yy_id']),
  672. 'bw_id'=>explode(',',$item['bw_id']),
  673. 'pc_id'=>explode(',',$item['pc_id']),
  674. 'xh_id'=>$item['xh_id']
  675. ];
  676. }
  677. }
  678. }
  679. $this->view->assign('row', $row);
  680. return $this->view->fetch();
  681. }
  682. /**
  683. * @Notes:移除 维修报告
  684. * @Author: jxb
  685. * @Date: 2025/1/21
  686. * @Time: 14:45
  687. */
  688. public function delreport($ids = null){
  689. $row = $this->exam_model->get($ids);
  690. if(!$row){
  691. $this->error('未找到记录');
  692. }
  693. if ($this->request->isPost()) {
  694. $xh_id = $this->request->post('xh_id');
  695. if(!empty($row->other_report)){
  696. $other_report = json_decode($row->other_report,true);
  697. unset($other_report[$xh_id]);
  698. $row->other_report = json_encode($other_report);
  699. $row->save();
  700. }
  701. $this->success();
  702. }
  703. }
  704. public function analysis($ids = null)
  705. {
  706. $row = $this->exam_model->get($ids);
  707. if(!$row){
  708. $this->error('未找到记录');
  709. }
  710. if ($this->request->isPost()) {
  711. $params = $this->request->post('row/a');
  712. //计算总分到学员考试表
  713. $this->success('操作成功','/ZQOtIMLKud.php/student/collection/index');
  714. }
  715. return $this->view->fetch();
  716. }
  717. }