Exams.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. use app\admin\model\teacher\ExamsScore;
  8. /**
  9. * sim-考试表/成绩总分
  10. *
  11. * @icon fa fa-circle-o
  12. */
  13. class Exams extends Backend
  14. {
  15. /**
  16. * Exams模型对象
  17. * @var \app\admin\model\teacher\Exams
  18. */
  19. protected $model = null;
  20. protected $whereExtend = null;
  21. public function _initialize()
  22. {
  23. parent::_initialize();
  24. $this->model = new \app\admin\model\teacher\Exams;
  25. $this->whereExtend['exam_collection_type'] = 3;
  26. $this->whereExtend['starttime'] = ['>',0];
  27. }
  28. /**
  29. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  30. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  31. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  32. */
  33. public function edit($ids = null)
  34. {
  35. $row = Db::name('real_exam_score')->where('exam_id', $ids)->find();
  36. if (!$row) {
  37. $this->error(__('No Results were found'));
  38. }
  39. $rows = $this->model->get($ids);
  40. $row['seat_id'] = $rows->seat_id;
  41. $row['user_nickname'] = $rows->user_nickname;
  42. $row['user_username'] = $rows->user_username;
  43. $row['is_sure'] = $rows->is_sure;
  44. if (false === $this->request->isPost()) {
  45. $this->view->assign('row', $row);
  46. return $this->view->fetch();
  47. }
  48. $params = $this->request->post('row/a');
  49. if (empty($params)) {
  50. $this->error(__('Parameter %s can not be empty', ''));
  51. }
  52. $params = $this->preExcludeFields($params);
  53. $result = false;
  54. Db::startTrans();
  55. try {
  56. //是否采用模型验证
  57. $params['total'] = 100-$params['fault_one_score']-$params['fault_two_score']-$params['fault_three_score']-$params['xianxian_score']-$params['yuanyin_socre']-$params['buwei_score']-$params['fangfa_score']-$params['overtime_score']-$params['jielun_score'];
  58. $result = Db::name('real_exam_score')->where('id', $row['id'])->update($params);
  59. $rows->total_score = $params['total'];
  60. $rows->is_sure = 1;
  61. $rows->save();
  62. Db::commit();
  63. } catch (ValidateException|PDOException|Exception $e) {
  64. Db::rollback();
  65. $this->error($e->getMessage());
  66. }
  67. if (false === $result) {
  68. $this->error(__('No rows were updated'));
  69. }
  70. $this->success();
  71. }
  72. public function view($ids = null)
  73. {
  74. $row = Db::name('real_exam_score')->where('exam_id', $ids)->find();
  75. if (!$row) {
  76. $this->error(__('No Results were found'));
  77. }
  78. $rows = $this->model->get($ids);
  79. $row['seat_id'] = $rows->seat_id;
  80. $row['user_nickname'] = $rows->user_nickname;
  81. $row['user_username'] = $rows->user_username;
  82. $row['user_depart_id'] = $rows->user_depart_id;
  83. $row['start_time'] = $rows->start_time;
  84. $row['end_time'] = $rows->end_time;
  85. $this->view->assign('row', $row);
  86. return $this->view->fetch();
  87. }
  88. //正在考试
  89. public function persent()
  90. {
  91. //设置过滤方法
  92. $this->request->filter(['strip_tags', 'trim']);
  93. if (false === $this->request->isAjax()) {
  94. $examlist = $this->model->select();
  95. foreach ($examlist as $k => $v){
  96. $examlist[$k]['score'] = Db::name('real_exam_score')->where('exam_id',$v['exam_id'])->find();
  97. }
  98. $this->view->assign('examlist', $examlist);
  99. return $this->view->fetch();
  100. }
  101. //如果发送的来源是 Selectpage,则转发到 Selectpage
  102. if ($this->request->request('keyField')) {
  103. return $this->selectpage();
  104. }
  105. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  106. $list = Db::name('real_exam_comp_request')->where('exam_collection_type',3)
  107. ->where($where)
  108. ->order($sort, $order)
  109. ->paginate($limit);
  110. unset($v);
  111. $result = ['total' => $list->total(), 'rows' => $list->items()];
  112. return json($result);
  113. }
  114. public function examing()
  115. {
  116. //设置过滤方法
  117. $this->request->filter(['strip_tags', 'trim']);
  118. if (false === $this->request->isAjax()) {
  119. return $this->view->fetch();
  120. }
  121. //如果发送的来源是 Selectpage,则转发到 Selectpage
  122. if ($this->request->request('keyField')) {
  123. return $this->selectpage();
  124. }
  125. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  126. $list = $this->model
  127. ->where($where)->where($this->whereExtend)
  128. ->order($sort, $order)
  129. ->paginate($limit);
  130. $result = ['total' => $list->total(), 'rows' => $list->items()];
  131. return json($result);
  132. }
  133. public function score()
  134. {
  135. //设置过滤方法
  136. $this->request->filter(['strip_tags', 'trim']);
  137. if (false === $this->request->isAjax()) {
  138. return $this->view->fetch();
  139. }
  140. //如果发送的来源是 Selectpage,则转发到 Selectpage
  141. if ($this->request->request('keyField')) {
  142. return $this->selectpage();
  143. }
  144. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  145. $list = ExamsScore::where($where)
  146. ->order($sort, $order)
  147. ->paginate($limit);
  148. foreach ($list as $k => $v){
  149. $exam = $this->model->where(['exam_id'=>$v['exam_id']])->find();
  150. if($exam){
  151. $v->seat_id = $exam['seat_id'];
  152. $v->user_username = $exam['user_username'];
  153. $v->user_nickname = $exam['user_nickname'];
  154. }
  155. }
  156. unset($v);
  157. $result = ['total' => $list->total(), 'rows' => $list->items()];
  158. return json($result);
  159. }
  160. public function handle($type = null,$ids = null)
  161. {
  162. $row = Db::name('real_exam_comp_request')->where('rel_id',$ids)->find($ids);
  163. if(!$row){
  164. $this->error('未找到记录');
  165. }
  166. if($type ==1){
  167. $request_status = 2;
  168. }
  169. if($type==2)
  170. {
  171. $request_status= 3;
  172. }
  173. Db::name('real_exam_comp_request')->where('rel_id',$ids)->update(['request_status'=>$request_status]);
  174. //同步更新考试表json串
  175. $exam_info = $this->model->get($row['exam_id']);
  176. if(!empty($exam_info)){
  177. $other_replace = json_decode($exam_info['other_replace'],true)??[];
  178. foreach ($other_replace as $k=>$v){
  179. if($v['fault_id'] == $row['fault_id']){
  180. $other_replace[$k]['request_status'] = $request_status;
  181. }
  182. }
  183. $exam_info->other_replace = json_encode($other_replace);
  184. $exam_info->save();
  185. unset($v);
  186. }
  187. $this->success();
  188. }
  189. //啦
  190. public function editscore($ids = "")
  191. {
  192. $row = Db::name('real_exam_score')->where('exam_id', $ids)->find();
  193. if (!$row) {
  194. $this->error(__('No Results were found'));
  195. }
  196. $rows = $this->model->get($ids);
  197. $params = $this->request->post('row/a');
  198. if (empty($params)) {
  199. $this->error(__('Parameter %s can not be empty', ''));
  200. }
  201. $params = $this->preExcludeFields($params);
  202. $result = false;
  203. Db::startTrans();
  204. try {
  205. //是否采用模型验证
  206. $result = Db::name('real_exam_score')->where('id', $row['id'])->update($params);
  207. $info = Db::name('real_exam_score')->where('exam_id', $ids)->find();
  208. $total =100-$info['fault_one_score']-$info['fault_two_score']-$info['fault_three_score']-$info['xianxian_score']-$info['yuanyin_socre']-$info['buwei_score']-$info['fangfa_score']-$info['overtime_score']-$info['jielun_score'];;
  209. $rows->total_score = $total;
  210. $rows->is_sure = 1;
  211. $rows->save();
  212. $result = Db::name('real_exam_score')->where('id', $row['id'])->update(['total'=>$total]);
  213. Db::commit();
  214. } catch (ValidateException|PDOException|Exception $e) {
  215. Db::rollback();
  216. $this->error($e->getMessage());
  217. }
  218. if (false === $result) {
  219. $this->error(__('No rows were updated'));
  220. }
  221. $this->success();
  222. }
  223. }