Exercise.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. namespace app\admin\controller\student;
  3. use app\admin\model\Fault;
  4. use app\admin\model\Report;
  5. use app\common\controller\Backend;
  6. use app\common\model\Config as ConfigModel;
  7. use think\Db;
  8. use think\exception\PDOException;
  9. /**
  10. * sim-自主练习集合管理
  11. *
  12. * @icon fa fa-circle-o
  13. */
  14. class Exercise extends Backend
  15. {
  16. /**
  17. * Collection模型对象
  18. * @var \app\admin\model\teacher\Collection
  19. */
  20. protected $model = null;
  21. protected $exam_model = null;
  22. protected $whereExtend = null;
  23. public function _initialize()
  24. {
  25. parent::_initialize();
  26. $this->model = new \app\admin\model\teacher\Collection;
  27. $this->exam_model = new \app\admin\model\teacher\Exams;
  28. $this->assign('sim_sim_type', ConfigModel::getSimTypeList());
  29. }
  30. /**
  31. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  32. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  33. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  34. */
  35. public function index()
  36. {
  37. //设置过滤方法
  38. $this->request->filter(['strip_tags', 'trim']);
  39. if (false === $this->request->isAjax()) {
  40. return $this->view->fetch();
  41. }
  42. if ($this->request->isPost()) {
  43. $params = $this->request->post('row/a');
  44. $count = 0;
  45. Db::startTrans();
  46. try {
  47. $params['exam_collection_type'] = 2;
  48. $params['exam_collection_state'] = 2;
  49. $params['question_setting_method'] = 1;
  50. $params['exam_collection_name'] = $this->auth->nickname.'自主练习';
  51. $params['limit_duration'] = 30;
  52. $params['start_time'] = date('Y-m-d');
  53. $params['end_time'] = date('Y-m-d');
  54. $exam_id = $this->model->insertGetId($params);
  55. $data = [
  56. 'exam_collection_id' => $exam_id,
  57. 'user_id' => $this->auth->id,
  58. 'user_username' => $this->auth->username,
  59. 'user_nickname' => $this->auth->nickname,
  60. 'user_depart_id' => $this->auth->depart_id,
  61. 'exam_collection_name' => $params['exam_collection_name'],
  62. 'exam_collection_type' =>$params['exam_collection_type'],
  63. 'sim_type' => $params['sim_type'],
  64. 'seat_id' =>1,
  65. 'seat_id' =>12,
  66. 'exam_status'=>4,
  67. 'start_time'=>date('Y-m-d H:i:s'),
  68. 'starttime'=>time(),
  69. 'create_time'=>date('Y-m-d H:i:s'),
  70. 'createtime'=>time(),
  71. 'update_time'=>date('Y-m-d H:i:s'),
  72. 'updatetime'=>time(),
  73. ];
  74. $examid = $this->exam_model->insertGetId($data);
  75. $count = $examid;
  76. Db::commit();
  77. } catch (PDOException|Exception $e) {
  78. Db::rollback();
  79. $this->error($e->getMessage());
  80. }
  81. if ($count) {
  82. $this->success('开始成功','/ZQOtIMLKud.php/student/exercise/examing/ids/'.$count);
  83. }
  84. $this->error(__('No rows were updated'));
  85. }
  86. }
  87. public function examing($ids = null)
  88. {
  89. $row = $this->exam_model->get($ids);
  90. if(!$row){
  91. $this->error('未找到记录');
  92. }
  93. if ($this->request->isPost()) {
  94. $params = $this->request->post('row/a');
  95. $row->end_time = date('Y-m-d H:i:s');
  96. $row->endtime = time();
  97. $row->exam_status = 5;
  98. $row->save();
  99. $this->success('交卷成功','/ZQOtIMLKud.php/student/exercise/analysis/ids/'.$row['exam_id']);
  100. }
  101. // if(empty($row->starttime)){
  102. // $row->start_time = date('Y-m-d H:i:s');
  103. // $row->starttime = time();
  104. // $row->exam_status = 4;
  105. // $row->save();
  106. // }
  107. $isloading =1;
  108. if(empty($row->other_replace)){
  109. $isloading = 0;
  110. $row->other_replace = '[{"fault_id":"","request_status":"0"}]';
  111. }
  112. if(empty($row->other_report)){
  113. $row->other_report = '[{"xx_id":"","yy_id":"","bw_id":"","pc_id":""}]';
  114. }
  115. $row->limit_duration = $this->model->where(['exam_collection_id'=>$row['exam_collection_id']])->value('limit_duration');
  116. if(empty($row->starttime)){
  117. $timer = 60*$row->limit_duration;
  118. }else{
  119. $timer = $row->limit_duration*60 - abs(time() - $row->starttime);
  120. }
  121. $departmentdata = [];
  122. $departmentdata = Fault::where(['replace_part'=>1,'sim_type'=>$row->sim_type])->order('fault_id asc')->select();
  123. $this->view->assign('departmentdata', $departmentdata);
  124. //故障现象
  125. $xianxiang = Fault::where(['fault_type'=>1,'sim_type'=>$row->sim_type])->select();
  126. $this->view->assign('xianxiang', $xianxiang);
  127. $row->replace_list =Db::name('real_exam_comp_request')->where(['exam_id'=>$ids])->select();
  128. $this->assignConfig('ids',$ids);
  129. $this->assignConfig('timer',$timer);
  130. $this->assignConfig('isloading',$isloading);
  131. $this->view->assign('row', $row);
  132. return $this->view->fetch();
  133. }
  134. public function analysis($ids = null)
  135. {
  136. $row = $this->exam_model->get($ids);
  137. if(!$row){
  138. $this->error('未找到记录');
  139. }
  140. if ($this->request->isPost()) {
  141. $params = $this->request->post('row/a');
  142. //计算总分到学员考试表
  143. $this->success('操作成功','/ZQOtIMLKud.php/student/exercise/index');
  144. }
  145. return $this->view->fetch();
  146. }
  147. }