Collection.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 think\exception\DbException;
  7. use think\response\Json;
  8. /**
  9. * sim-考试集合管理
  10. *
  11. * @icon fa fa-circle-o
  12. */
  13. class Collection extends Backend
  14. {
  15. /**
  16. * Collection模型对象
  17. * @var \app\admin\model\teacher\Collection
  18. */
  19. protected $model = null;
  20. protected $exam_model = null;
  21. protected $whereExtend = null;
  22. public function _initialize()
  23. {
  24. parent::_initialize();
  25. $this->model = new \app\admin\model\teacher\Collection;
  26. $this->exam_model = new \app\admin\model\teacher\Exams;
  27. $this->assignConfig('sim_sim_type', ConfigModel::getSimTypeList());
  28. $this->assignConfig('sim_question_setting_method', ConfigModel::getSimQuestionList());
  29. $this->whereExtend['exam_collection_type'] = 3;
  30. $this->whereExtend['exam_collection_state'] = 2;
  31. $this->assignConfig('sim_sim_type', ConfigModel::getSimTypeList());
  32. }
  33. /**
  34. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  35. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  36. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  37. */
  38. /**
  39. * 查看
  40. *
  41. * @return string|Json
  42. * @throws \think\Exception
  43. * @throws DbException
  44. */
  45. public function index()
  46. {
  47. //设置过滤方法
  48. $this->request->filter(['strip_tags', 'trim']);
  49. if (false === $this->request->isAjax()) {
  50. return $this->view->fetch();
  51. }
  52. //如果发送的来源是 Selectpage,则转发到 Selectpage
  53. if ($this->request->request('keyField')) {
  54. return $this->selectpage();
  55. }
  56. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  57. $list = $this->model
  58. ->where($where)->where($this->whereExtend)
  59. ->order($sort, $order)
  60. ->paginate($limit);
  61. foreach ($list as $k => $v){
  62. $exam_isset = $this->exam_model->where(['user_id'=>$this->auth->id,'exam_collection_id'=>$v['exam_collection_id'],'exam_collection_type'=>3])->find();
  63. if(isset($exam_isset)){
  64. $v->is_user_examed = 1;
  65. }else{
  66. $v->is_user_examed = 0;
  67. }
  68. }
  69. unset($v);
  70. $result = ['total' => $list->total(), 'rows' => $list->items()];
  71. return json($result);
  72. }
  73. //进入考试
  74. public function into($ids = null)
  75. {
  76. $row = $this->model->get($ids);
  77. if(!$row){
  78. $this->error('未找到记录');
  79. }
  80. $info = $this->exam_model->where(['user_id'=>$this->auth->id,'exam_collection_id'=>$ids])->find();
  81. if(empty($info)){
  82. $arr = [
  83. 'exam_collection_id' => $ids,
  84. 'user_id' => $this->auth->id,
  85. 'user_username' => $this->auth->username,
  86. 'user_nickname' => $this->auth->nickname,
  87. 'user_depart_id' => $this->auth->depart_id,
  88. 'exam_collection_name' => $row->exam_collection_name,
  89. 'exam_collection_type' => 3,
  90. 'sim_type' => $row->sim_type,
  91. 'seat_id' => 1,
  92. 'sim_id' => 12,
  93. ];
  94. $this->exam_model->save($arr);
  95. }
  96. if ($this->request->isPost()) {
  97. $exam_collection_id = $this->request->post('exam_collection_id');
  98. if(empty($info->starttime)){
  99. $info->start_time = date('Y-m-d H:i:s');
  100. $info->starttime = time();
  101. }
  102. $info->exam_status = 4;
  103. $info->save();
  104. $this->success('开始成功','/ZQOtIMLKud.php/student/collection/examing/ids/'.$info['exam_id']);
  105. }
  106. $this->view->assign('row', $row);
  107. return $this->view->fetch();
  108. }
  109. public function examing($ids = null)
  110. {
  111. $row = $this->exam_model->get($ids);
  112. if(!$row){
  113. $this->error('未找到记录');
  114. }
  115. $this->assignConfig('timer', 60*$this->model->where(['exam_collection_id'=>$row['exam_collection_id']])->value('limit_duration'));
  116. $this->view->assign('row', $row);
  117. $departmentdata = [];
  118. $departmentdata = Report::where(['level'=>4,'is_replace'=>1])->select();
  119. if ($this->request->isPost()) {
  120. $params = $this->request->post('row/a');
  121. $row->end_time = date('Y-m-d H:i:s');
  122. $row->endtime = time();
  123. $row->exam_status = 5;
  124. $row->save();
  125. $this->success('交卷成功','/ZQOtIMLKud.php/student/collection/analysis/ids/'.$row['exam_id']);
  126. }
  127. $this->view->assign('departmentdata', $departmentdata);
  128. return $this->view->fetch();
  129. }
  130. public function analysis($ids = null)
  131. {
  132. $row = $this->exam_model->get($ids);
  133. if(!$row){
  134. $this->error('未找到记录');
  135. }
  136. if ($this->request->isPost()) {
  137. $params = $this->request->post('row/a');
  138. //计算总分到学员考试表
  139. $this->success('操作成功','/ZQOtIMLKud.php/student/collection/index');
  140. }
  141. return $this->view->fetch();
  142. }
  143. }