Exams.php 8.5 KB

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