title = '分类管理'; $query = $this->_query($this->table)->where('pid', 0)->like('title'); if (isset($_GET['status']) && $_GET['status']!=''){ $query->where('status',$_GET['status']); } if (isset($_GET['label_id']) && $_GET['label_id']!=''){ $query->where('label_id',$_GET['label_id']); } $query->where('is_deleted', 0) ->order('pid asc,id desc') ->page(); } /** * 列表数据处理 * @param array $data */ protected function _index_page_filter(&$data) { foreach ($data as &$vo) { $vo['children'] = Db::name($this->table) ->where('is_deleted', 0) ->where('pid', $vo['id']) ->select(); foreach ($vo['children'] as &$v) { $v['children'] = Db::name($this->table) ->where('is_deleted', 0) ->where('pid', $v['id']) ->select(); } } $data = Data::arr2table($data); // dump($data);die; } /** * 添加分类 * @auth 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->_form($this->table, 'form'); } /** * 编辑分类 * @auth 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->_form($this->table, 'form'); } /** * 表单数据处理 * @param array $vo * @throws \ReflectionException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ protected function _form_filter(&$vo) { if ($this->request->isGet()) { // 选择自己的上级分类 if (empty($vo['pid']) && $this->request->get('pid', '0')) $vo['pid'] = $this->request->get('pid', '0'); // 列出可选上级分类 $menus = Db::name($this->table)->where(['status' => '1'])->where('is_deleted', 0)->order('id asc')->column('id,pid,title'); $this->menus = Data::arr2table(array_merge($menus, [['id' => '0', 'pid' => '-1', 'title' => '一级分类']])); if (isset($vo['id'])) foreach ($this->menus as $key => $menu) if ($menu['id'] === $vo['id']) $vo = $menu; foreach ($this->menus as $key => &$menu) { if ($menu['spt'] >= 3) unset($this->menus[$key]); } //dump($this->menus);die; }elseif ($this->request->isPost()){ $pid = request()->post('pid'); $id = request()->post('id'); if ($pid == $id) $this->error('上级分类不能是自身'); } } /** * 禁用分类 * @auth true * @throws \think\Exception * @throws \think\exception\PDOException */ public function forbid() { $this->applyCsrfToken(); $this->_save($this->table, ['status' => '0']); } /** * 启用分类 * @auth true * @throws \think\Exception * @throws \think\exception\PDOException */ public function resume() { $this->applyCsrfToken(); $this->_save($this->table, ['status' => '1']); } /** * 删除分类 * @auth true * @throws \think\Exception * @throws \think\exception\PDOException */ public function remove() { $this->_delete($this->table); } }