Exams.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. namespace app\admin\controller\teacher;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. use think\exception\PDOException;
  6. use think\exception\ValidateException;
  7. /**
  8. * sim-考试表/成绩总分
  9. *
  10. * @icon fa fa-circle-o
  11. */
  12. class Exams extends Backend
  13. {
  14. /**
  15. * Exams模型对象
  16. * @var \app\admin\model\teacher\Exams
  17. */
  18. protected $model = null;
  19. protected $whereExtend = null;
  20. public function _initialize()
  21. {
  22. parent::_initialize();
  23. $this->model = new \app\admin\model\teacher\Exams;
  24. }
  25. /**
  26. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  27. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  28. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  29. */
  30. public function edit($ids = null)
  31. {
  32. $row = Db::name('real_exam_score')->where('exam_id', $ids)->find();
  33. if (!$row) {
  34. $this->error(__('No Results were found'));
  35. }
  36. $rows = $this->model->get($ids);
  37. $row['seat_id'] = $rows->seat_id;
  38. $row['user_nickname'] = $rows->user_nickname;
  39. $row['user_username'] = $rows->user_username;
  40. $row['is_sure'] = $rows->is_sure;
  41. if (false === $this->request->isPost()) {
  42. $this->view->assign('row', $row);
  43. return $this->view->fetch();
  44. }
  45. $params = $this->request->post('row/a');
  46. if (empty($params)) {
  47. $this->error(__('Parameter %s can not be empty', ''));
  48. }
  49. $params = $this->preExcludeFields($params);
  50. $result = false;
  51. Db::startTrans();
  52. try {
  53. //是否采用模型验证
  54. $params['total'] = 100-$params['fault_one_score']-$params['fault_two_score']-$params['fault_three_score']-$params['overtime_score']-$params['jielun_score'];
  55. $result = Db::name('real_exam_score')->where('id', $row['id'])->update($params);
  56. $rows->total_score = $params['total'];
  57. $rows->is_sure = 1;
  58. $rows->save();
  59. Db::commit();
  60. } catch (ValidateException|PDOException|Exception $e) {
  61. Db::rollback();
  62. $this->error($e->getMessage());
  63. }
  64. if (false === $result) {
  65. $this->error(__('No rows were updated'));
  66. }
  67. $this->success();
  68. }
  69. public function view($ids = null)
  70. {
  71. $row = $this->model->get($ids);
  72. if(!$row){
  73. $this->error('未找到记录');
  74. }
  75. $this->view->assign('row', $row);
  76. return $this->view->fetch();
  77. }
  78. //正在考试
  79. public function persent()
  80. {
  81. //设置过滤方法
  82. $this->request->filter(['strip_tags', 'trim']);
  83. if (false === $this->request->isAjax()) {
  84. $examlist = $this->model->select();
  85. foreach ($examlist as $k => $v){
  86. $examlist[$k]['score'] = Db::name('real_exam_score')->where('exam_id',$v['exam_id'])->find();
  87. }
  88. $this->view->assign('examlist', $examlist);
  89. return $this->view->fetch();
  90. }
  91. //如果发送的来源是 Selectpage,则转发到 Selectpage
  92. if ($this->request->request('keyField')) {
  93. return $this->selectpage();
  94. }
  95. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  96. $list = Db::name('real_exam_comp_request')
  97. ->where($where)->where($this->whereExtend)
  98. ->order($sort, $order)
  99. ->paginate($limit);
  100. unset($v);
  101. $result = ['total' => $list->total(), 'rows' => $list->items()];
  102. return json($result);
  103. }
  104. public function examing()
  105. {
  106. //设置过滤方法
  107. $this->request->filter(['strip_tags', 'trim']);
  108. if (false === $this->request->isAjax()) {
  109. return $this->view->fetch();
  110. }
  111. //如果发送的来源是 Selectpage,则转发到 Selectpage
  112. if ($this->request->request('keyField')) {
  113. return $this->selectpage();
  114. }
  115. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  116. $list = $this->model
  117. ->where($where)->where($this->whereExtend)
  118. ->order($sort, $order)
  119. ->paginate($limit);
  120. $result = ['total' => $list->total(), 'rows' => $list->items()];
  121. return json($result);
  122. }
  123. public function handle($type = null,$ids = null)
  124. {
  125. $row = Db::name('real_exam_comp_request')->where('rel_id',$ids)->find($ids);
  126. if(!$row){
  127. $this->error('未找到记录');
  128. }
  129. if($type ==1){
  130. $request_status = 2;
  131. }
  132. if($type==2)
  133. {
  134. $request_status= 3;
  135. }
  136. Db::name('real_exam_comp_request')->where('rel_id',$ids)->update(['request_status'=>$request_status]);
  137. $this->success();
  138. }
  139. }