Exams.php 8.7 KB

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