| // +------------------------------------------------+ namespace app\system\controller; use app\common\model\Category as CategoryModel; use app\common\service\Category as CategoryService; use think\Request; class Category extends _Init { /** * 分类列表 * @param string $pid 上级分类id * @return [type] [description] */ public function index($pid = '') { if (is_numeric($pid)) { $map['pid'] = $pid; } else { $map['pid'] = 0; } $map['status'] = ['egt', 0]; $this->list = CategoryModel::where($map)->order('sort desc,update_time desc')->paginate(); $this->info = CategoryModel::get($pid); $this->menu = CategoryService::tree(); return $this->fetch(); } /** * 添加分类 * @param Request $Request [description] * @param integer $pid 上级id */ public function add(Request $Request, $pid = 0) { if (IS_POST) { $data = $Request->post(); $result = CategoryService::add($data); return $this->back($result); } else { $info['pid'] = $pid; $this->info = $info; $this->up_cates = CategoryService::treeList(); return $this->fetch(); } } /** * 编辑分类 * @param [type] $id 分类id */ public function edit(Request $Request, $id) { if (IS_POST) { $data = $Request->post(); $result = CategoryService::edit($data); return $this->back($result); } else { $this->up_cates = CategoryService::treeList($id); $this->info = CategoryModel::get($id); return $this->fetch('add'); } } /** * 删除分类 * @param [type] $id 分类id * @return [type] 返回删除的结果 */ public function del($id) { $result = CategoryService::del($id); $this->back($result); } /** * 设置分类状态 * @param [type] $id 分类id * @param [type] $status 状态 * @param [type] $type 要设置的字段 status * @return [type] 返回结果 */ public function status($id, $status, $type) { $result = CategoryService::status($id, $status, $type); return $this->back($result); } }