title = '商品分类列表'; $query = $this->_query($this->table) ->field('is_deleted', true) ->where('is_deleted', CommonConstant::IS_DELETED_0) ->order('sort desc,id asc'); $query->page(false); } /** * 列表数据处理 * @param array $data * @throws \Exception */ protected function _index_page_filter(&$data) { if ($data) { foreach ($data as &$vo) { $vo['ids'] = join(',', Data::getArrSubIds($data, $vo['id'])); } $data = Data::arr2table($data); } } /** * 添加 * @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->title = '添加'; $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->title = '编辑'; $this->_form($this->table, 'form'); } /** * 表单处理 * @param array $data * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ protected function _form_filter(&$data) { if ($this->request->isGet()) { $this->category_list = GoodsCategoryService::get_list([]); $this->category_list = array_merge([['id' => '0', 'pid' => '-1', 'name' => '顶级']], $this->category_list ? $this->category_list->toArray() : []); } if ($this->request->isPost()) { } } /** * 删除 * @auth true * @throws \think\Exception * @throws \think\exception\PDOException */ public function remove() { $this->applyCsrfToken(); list($data) = [$this->request->post()]; $is_goods = Goods::field('id') ->where('is_deleted', CommonConstant::IS_DELETED_0) ->when($data, function ($query) use ($data) { if ($data['pid'] == 0) { $query->where('goods_category_first', $data['id']); } else { $query->where('goods_category_id', $data['id']); } }) ->find(); if ($is_goods) { $this->error("该分类下有商品,不能删除!"); } $this->_delete($this->table); } /** * 删除结果处理 * @param boolean $result * @throws \think\Exception * @throws \think\exception\PDOException */ protected function _remove_delete_result($result) { if ($result) { list($data) = [$this->request->post()]; if ($data['pid'] == 0) { model::where('pid', $data['id'])->update(['is_deleted' => CommonConstant::IS_DELETED_1]); } $this->success("删除成功!", ''); } else { $this->error("删除失败,请稍候再试!"); } } }