Exercise.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. use think\Db;
  7. use think\exception\PDOException;
  8. /**
  9. * sim-自主练习集合管理
  10. *
  11. * @icon fa fa-circle-o
  12. */
  13. class Exercise 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->assign('sim_sim_type', ConfigModel::getSimTypeList());
  28. }
  29. /**
  30. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  31. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  32. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  33. */
  34. public function index()
  35. {
  36. //设置过滤方法
  37. $this->request->filter(['strip_tags', 'trim']);
  38. if (false === $this->request->isAjax()) {
  39. return $this->view->fetch();
  40. }
  41. if ($this->request->isPost()) {
  42. $params = $this->request->post('row/a');
  43. $count = 0;
  44. Db::startTrans();
  45. try {
  46. $params['exam_collection_type'] = 2;
  47. $params['exam_collection_state'] = 2;
  48. $params['question_setting_method'] = 1;
  49. $params['exam_collection_name'] = $this->auth->nickname.'自主练习';
  50. $params['limit_duration'] = 30;
  51. $params['start_time'] = date('Y-m-d');
  52. $params['end_time'] = date('Y-m-d');
  53. $exam_id = $this->model->insertGetId($params);
  54. $data = [
  55. 'exam_collection_id' => $exam_id,
  56. 'user_id' => $this->auth->id,
  57. 'user_username' => $this->auth->username,
  58. 'user_nickname' => $this->auth->nickname,
  59. 'user_depart_id' => $this->auth->depart_id,
  60. 'exam_collection_name' => $params['exam_collection_name'],
  61. 'exam_collection_type' =>$params['exam_collection_type'],
  62. 'sim_type' => $params['sim_type'],
  63. 'seat_id' =>1,
  64. 'seat_id' =>12,
  65. 'exam_status'=>4,
  66. 'start_time'=>date('Y-m-d H:i:s'),
  67. 'starttime'=>time(),
  68. 'create_time'=>date('Y-m-d H:i:s'),
  69. 'createtime'=>time(),
  70. 'update_time'=>date('Y-m-d H:i:s'),
  71. 'updatetime'=>time(),
  72. ];
  73. $examid = $this->exam_model->insertGetId($data);
  74. $count = $examid;
  75. Db::commit();
  76. } catch (PDOException|Exception $e) {
  77. Db::rollback();
  78. $this->error($e->getMessage());
  79. }
  80. if ($count) {
  81. $this->success('开始成功','/ZQOtIMLKud.php/student/exercise/examing/ids/'.$count);
  82. }
  83. $this->error(__('No rows were updated'));
  84. }
  85. }
  86. public function examing($ids = null)
  87. {
  88. $row = $this->exam_model->get($ids);
  89. if(!$row){
  90. $this->error('未找到记录');
  91. }
  92. $this->assignConfig('timer', 60*$this->model->where(['exam_collection_id'=>$row['exam_collection_id']])->value('limit_duration'));
  93. $this->view->assign('row', $row);
  94. $departmentdata = [];
  95. $departmentdata = Report::where(['level'=>4,'is_replace'=>1])->select();
  96. if ($this->request->isPost()) {
  97. $params = $this->request->post('row/a');
  98. $row->end_time = date('Y-m-d H:i:s');
  99. $row->endtime = time();
  100. $row->exam_status = 5;
  101. $row->save();
  102. $this->success('交卷成功','/ZQOtIMLKud.php/student/exercise/analysis/ids/'.$row['exam_id']);
  103. }
  104. $this->view->assign('departmentdata', $departmentdata);
  105. return $this->view->fetch();
  106. }
  107. public function analysis($ids = null)
  108. {
  109. $row = $this->exam_model->get($ids);
  110. if(!$row){
  111. $this->error('未找到记录');
  112. }
  113. if ($this->request->isPost()) {
  114. $params = $this->request->post('row/a');
  115. //计算总分到学员考试表
  116. $this->success('操作成功','/ZQOtIMLKud.php/student/exercise/index');
  117. }
  118. return $this->view->fetch();
  119. }
  120. }