<?php
namespace app\store\controller\apps\sharing;
use app\store\controller\Controller;
use app\store\model\sharing\Category as CategoryModel;
class Category extends Controller
{
public function index()
{
$model = new CategoryModel;
$list = $model->getCacheTree();
return $this->fetch('index', compact('list'));
}
public function add()
{
$model = new CategoryModel;
if (!$this->request->isAjax()) {
$list = $model->getCacheTree();
return $this->fetch('add', compact('list'));
}
if ($model->add($this->postData('category'))) {
return $this->renderSuccess('添加成功', url('apps.sharing.category/index'));
}
return $this->renderError($model->getError() ?: '添加失败');
}
public function edit($category_id)
{
$model = CategoryModel::detail($category_id);
if (!$this->request->isAjax()) {
$list = $model->getCacheTree();
return $this->fetch('edit', compact('model', 'list'));
}
if ($model->edit($this->postData('category'))) {
return $this->renderSuccess('更新成功', url('apps.sharing.category/index'));
}
return $this->renderError($model->getError() ?: '更新失败');
}
public function delete($category_id)
{
$model = CategoryModel::detail($category_id);
if (!$model->remove($category_id)) {
return $this->renderError($model->getError() ?: '删除失败');
}
return $this->renderSuccess('删除成功');
}
}