Practice.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. namespace app\admin\controller\student;
  3. use app\admin\model\Report;
  4. use app\common\controller\Backend;
  5. use app\common\model\Config as ConfigModel;
  6. /**
  7. * sim-练习集合管理
  8. *
  9. * @icon fa fa-circle-o
  10. */
  11. class Practice extends Backend
  12. {
  13. /**
  14. * Collection模型对象
  15. * @var \app\admin\model\teacher\Collection
  16. */
  17. protected $model = null;
  18. protected $exam_model = null;
  19. protected $whereExtend = null;
  20. public function _initialize()
  21. {
  22. parent::_initialize();
  23. $this->model = new \app\admin\model\teacher\Collection;
  24. $this->exam_model = new \app\admin\model\teacher\Exams;
  25. $this->assignConfig('sim_sim_type', ConfigModel::getSimTypeList());
  26. $this->assignConfig('sim_question_setting_method', ConfigModel::getSimQuestionList());
  27. $this->whereExtend['exam_collection_type'] = 1;//练习
  28. $this->whereExtend['exam_collection_state'] = 2;
  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. //如果发送的来源是 Selectpage,则转发到 Selectpage
  43. if ($this->request->request('keyField')) {
  44. return $this->selectpage();
  45. }
  46. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  47. $list = $this->model
  48. ->where($where)->where($this->whereExtend)
  49. ->order($sort, $order)
  50. ->paginate($limit);
  51. foreach ($list as $k => $v){
  52. $exam_isset = $this->exam_model->where(['user_id'=>$this->auth->id,'exam_collection_id'=>$v['exam_collection_id'],'exam_collection_type'=>1])->find();
  53. if(isset($exam_isset)){
  54. $v->is_user_examed = 1;
  55. }else{
  56. $v->is_user_examed = 0;
  57. }
  58. }
  59. unset($v);
  60. $result = ['total' => $list->total(), 'rows' => $list->items()];
  61. return json($result);
  62. }
  63. //进入考试
  64. public function into($ids = null)
  65. {
  66. $row = $this->model->get($ids);
  67. if(!$row){
  68. $this->error('未找到记录');
  69. }
  70. $info = $this->exam_model->where(['user_id'=>$this->auth->id,'exam_collection_id'=>$ids])->find();
  71. if(empty($info)){
  72. $arr = [
  73. 'exam_collection_id' => $ids,
  74. 'user_id' => $this->auth->id,
  75. 'user_username' => $this->auth->username,
  76. 'user_nickname' => $this->auth->nickname,
  77. 'user_depart_id' => $this->auth->depart_id,
  78. 'exam_collection_name' => $row->exam_collection_name,
  79. 'exam_collection_type' =>1,
  80. 'sim_type' => $row->sim_type,
  81. 'seat_id' => 1,
  82. 'sim_id' => 12,
  83. ];
  84. $this->exam_model->save($arr);
  85. }
  86. if ($this->request->isPost()) {
  87. $exam_collection_id = $this->request->post('exam_collection_id');
  88. if(empty($info->starttime)){
  89. $info->start_time = date('Y-m-d H:i:s');
  90. $info->starttime = time();
  91. }
  92. $info->exam_status = 4;
  93. $info->save();
  94. $this->success('开始成功','/ZQOtIMLKud.php/student/practice/examing/ids/'.$info['exam_id']);
  95. }
  96. $this->view->assign('row', $row);
  97. return $this->view->fetch();
  98. }
  99. public function examing($ids = null)
  100. {
  101. $row = $this->exam_model->get($ids);
  102. if(!$row){
  103. $this->error('未找到记录');
  104. }
  105. $this->assignConfig('timer', 60*$this->model->where(['exam_collection_id'=>$row['exam_collection_id']])->value('limit_duration'));
  106. $this->view->assign('row', $row);
  107. $departmentdata = [];
  108. $departmentdata = Report::where(['level'=>4,'is_replace'=>1])->select();
  109. if ($this->request->isPost()) {
  110. $params = $this->request->post('row/a');
  111. $row->end_time = date('Y-m-d H:i:s');
  112. $row->endtime = time();
  113. $row->exam_status = 5;
  114. $row->save();
  115. $this->success('交卷成功','/ZQOtIMLKud.php/student/practice/analysis/ids/'.$row['exam_id']);
  116. }
  117. $this->view->assign('departmentdata', $departmentdata);
  118. return $this->view->fetch();
  119. }
  120. public function analysis($ids = null)
  121. {
  122. $row = $this->exam_model->get($ids);
  123. if(!$row){
  124. $this->error('未找到记录');
  125. }
  126. if ($this->request->isPost()) {
  127. $params = $this->request->post('row/a');
  128. //计算总分到学员考试表
  129. $this->success('操作成功','/ZQOtIMLKud.php/student/practice/index');
  130. }
  131. return $this->view->fetch();
  132. }
  133. }