model = model('Protector'); } /** * 查看 */ public function index($status = false) { //设置过滤方法 $this->request->filter(['strip_tags']); if ($this->request->isAjax()) { //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } list($where, $sort, $order, $offset, $limit) = $this->buildparams(); switch ($status){ case 'protect': //保护中 $total = $this->model ->where('status',0) ->where($where) ->order($sort, $order) ->count(); $list = $this->model ->where('status',0) ->where($where) ->order($sort, $order) ->limit($offset, $limit) ->select(); break; case 'overdue': //已过期 $total = $this->model ->where('status',1) ->where($where) ->order($sort, $order) ->count(); $list = $this->model ->where('status',1) ->where($where) ->order($sort, $order) ->limit($offset, $limit) ->select(); break; case 'contract': //已签单 $total = $this->model ->where('status',2) ->where($where) ->order($sort, $order) ->count(); $list = $this->model ->where('status',2) ->where($where) ->order($sort, $order) ->limit($offset, $limit) ->select(); break; } $list = collection($list)->toArray(); $result = array("total" => $total, "rows" => $list); return json($result); } return $this->view->fetch('index'); } /** * 添加 */ public function add() { if ($this->request->isPost()) { $params = $this->request->post("row/a"); if ($params) { if ($this->dataLimit && $this->dataLimitFieldAutoFill) { $params[$this->dataLimitField] = $this->auth->id; } try { //是否采用模型验证 if ($this->modelValidate) { $name = basename(str_replace('\\', '/', get_class($this->model))); $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : true) : $this->modelValidate; $this->model->validate($validate); } $params['usr_id'] = Session::get('admin')['id']; //usr id $params['usr_nickname'] = Session::get('admin')['nickname']; //nickname $params['usr_depart'] = AuthGroupAccess::getGroupName($params['usr_id']); //获取所属组名 $result = $this->model->allowField(true)->save($params); if ($result !== false) { $this->success(); } else { $this->error($this->model->getError()); } } catch (\think\exception\PDOException $e) { $this->error($e->getMessage()); } } $this->error(__('Parameter %s can not be empty', '')); } return $this->view->fetch(); } }