quanwei
2025-12-13 30563323a53b0d0260c97d08a9e8bd4cc8227a95
admin/app/supplier/controller/product/Category.php
@@ -3,7 +3,7 @@
namespace app\supplier\controller\product;
use app\supplier\controller\Controller;
use app\common\model\product\Category as CategoryModel;
use app\supplier\model\product\Category as CategoryModel;
/**
 * 商品分类
@@ -16,9 +16,64 @@
    public function index()
    {
        $model = new CategoryModel;
        $list = $model->getCacheTree();
        $shop_supplier_id = $this->getSupplierId();
        $list = $model->getSupplierCacheTree($shop_supplier_id);
        return $this->renderSuccess('', compact('list'));
    }
    /**
    * 删除商品分类
    */
    public function delete($category_id)
    {
        $model = (new CategoryModel())->find($category_id);
        if ($model->remove($category_id)) {
            return $this->renderSuccess('删除成功');
        }
        return $this->renderError($model->getError() ?:'删除失败');
    }
    /**
     * 添加商品分类
     */
    public function add()
    {
        $model = new CategoryModel;
        $data = $this->request->post();
        $data['shop_supplier_id'] = $this->getSupplierId();
        // 新增记录
        if ($model->add($data)) {
            return $this->renderSuccess('添加成功');
        }
        return $this->renderError($model->getError() ?:'添加失败');
    }
    /**
     * 编辑商品分类
     */
    public function edit($category_id)
    {
        // 模板详情
        $model = CategoryModel::detail($category_id);
        $data = $this->request->post();
        $data['shop_supplier_id'] = $this->getSupplierId();
        // 更新记录
        if ($model->edit($data)) {
            return $this->renderSuccess('更新成功');
        }
        return $this->renderError($model->getError() ?: '更新失败');
    }
    /**
     * 得到修改图片
     * @return array
     */
    public function image($category_id)
    {
        $model = new CategoryModel;
        $detail = $model->detailWithImage(['category_id' => $category_id]);
        return $this->renderSuccess('', compact('detail'));
    }
}