Exams.php 8.7 KB

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