title = '分类列表'; $sel_where = []; $sel_where[] = ['is_deleted','=',0]; $sel_where[] = ['pid','=',0]; if($title = $this->request->get('title')) $sel_where[] = ['title','like','%'.$title.'%']; $query = $this->_query($this->table)->where($sel_where); $query->dateBetween('create_at')->order('status desc ,sort desc , id desc')->page(); } /** * 数据列表处理 * @auth true * @menu true * @param array $data * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ protected function _index_page_filter(&$data) { foreach ($data as $k=>&$v){ $v['children'] = NTC::where(['pid'=>$v['id'],'is_deleted'=>0]) ->order('status desc ,sort desc , id desc') ->select(); } } /** * 添加分类 * @auth true * @menu true * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function add() { $this->title = '添加分类'; $this->all_cate = NTC::field('id,title')->where('is_deleted',0)->select(); $this->_form($this->table, 'form'); } /** * 编辑分类 * @auth true * @menu true * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function edit() { $this->title = '编辑分类'; $this->_form($this->table, 'form'); } /** * 禁用分类 * @auth true * @menu true * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function forbidden() { $this->_save($this->table, ['status' => '0']); } /** * 启用分类 * @auth true * @menu true * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function enable() { $this->_save($this->table, ['status' => 1]); } /** * 删除分类 * @auth true * @menu true * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function del() { $this->_save($this->table, ['is_deleted' => 1]); } /** * 表单数据处理 * @auth true * @menu true * @param array $data */ protected function _form_filter(&$data) { if($this->request->get()){ $this->pid = input('pid',0); $this->pname = NTC::where(['id'=>$this->pid])->value('title'); $this->is_desc = 1; if($this->request->action() == 'add'){ $this->is_desc = $this->pid ?1:0; }else{ $this->is_desc = $data['pid'] > 0 ? 1:0; } } } }