123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- <?php
- namespace app\admin\controller\teacher;
- use app\common\controller\Backend;
- use think\Db;
- use think\exception\PDOException;
- use think\exception\ValidateException;
- /**
- * sim-考试表/成绩总分
- *
- * @icon fa fa-circle-o
- */
- class Exams extends Backend
- {
- /**
- * Exams模型对象
- * @var \app\admin\model\teacher\Exams
- */
- protected $model = null;
- protected $whereExtend = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \app\admin\model\teacher\Exams;
- }
- /**
- * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
- * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
- * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
- */
- public function edit($ids = null)
- {
- $row = Db::name('real_exam_score')->where('exam_id', $ids)->find();
- if (!$row) {
- $this->error(__('No Results were found'));
- }
- $rows = $this->model->get($ids);
- $row['seat_id'] = $rows->seat_id;
- $row['user_nickname'] = $rows->user_nickname;
- $row['user_username'] = $rows->user_username;
- $row['is_sure'] = $rows->is_sure;
- if (false === $this->request->isPost()) {
- $this->view->assign('row', $row);
- return $this->view->fetch();
- }
- $params = $this->request->post('row/a');
- if (empty($params)) {
- $this->error(__('Parameter %s can not be empty', ''));
- }
- $params = $this->preExcludeFields($params);
- $result = false;
- Db::startTrans();
- try {
- //是否采用模型验证
- $params['total'] = 100-$params['fault_one_score']-$params['fault_two_score']-$params['fault_three_score']-$params['overtime_score']-$params['jielun_score'];
- $result = Db::name('real_exam_score')->where('id', $row['id'])->update($params);
- $rows->total_score = $params['total'];
- $rows->is_sure = 1;
- $rows->save();
- Db::commit();
- } catch (ValidateException|PDOException|Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- if (false === $result) {
- $this->error(__('No rows were updated'));
- }
- $this->success();
- }
- public function view($ids = null)
- {
- $row = $this->model->get($ids);
- if(!$row){
- $this->error('未找到记录');
- }
- $this->view->assign('row', $row);
- return $this->view->fetch();
- }
- //正在考试
- public function persent()
- {
- //设置过滤方法
- $this->request->filter(['strip_tags', 'trim']);
- if (false === $this->request->isAjax()) {
- $examlist = $this->model->select();
- foreach ($examlist as $k => $v){
- $examlist[$k]['score'] = Db::name('real_exam_score')->where('exam_id',$v['exam_id'])->find();
- }
- $this->view->assign('examlist', $examlist);
- return $this->view->fetch();
- }
- //如果发送的来源是 Selectpage,则转发到 Selectpage
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- [$where, $sort, $order, $offset, $limit] = $this->buildparams();
- $list = Db::name('real_exam_comp_request')
- ->where($where)->where($this->whereExtend)
- ->order($sort, $order)
- ->paginate($limit);
- unset($v);
- $result = ['total' => $list->total(), 'rows' => $list->items()];
- return json($result);
- }
- public function examing()
- {
- //设置过滤方法
- $this->request->filter(['strip_tags', 'trim']);
- if (false === $this->request->isAjax()) {
- return $this->view->fetch();
- }
- //如果发送的来源是 Selectpage,则转发到 Selectpage
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- [$where, $sort, $order, $offset, $limit] = $this->buildparams();
- $list = $this->model
- ->where($where)->where($this->whereExtend)
- ->order($sort, $order)
- ->paginate($limit);
- $result = ['total' => $list->total(), 'rows' => $list->items()];
- return json($result);
- }
- public function handle($type = null,$ids = null)
- {
- $row = Db::name('real_exam_comp_request')->where('rel_id',$ids)->find($ids);
- if(!$row){
- $this->error('未找到记录');
- }
- if($type ==1){
- $request_status = 2;
- }
- if($type==2)
- {
- $request_status= 3;
- }
- Db::name('real_exam_comp_request')->where('rel_id',$ids)->update(['request_status'=>$request_status]);
- $this->success();
- }
- }
|