quanwei
7 days ago 30563323a53b0d0260c97d08a9e8bd4cc8227a95
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
 
namespace app\supplier\controller\product;
 
use app\supplier\controller\Controller;
use app\supplier\model\product\Category as CategoryModel;
 
/**
 * 商品分类
 */
class Category extends Controller
{
    /**
     * 商品分类列表
     */
    public function index()
    {
        $model = new CategoryModel;
        $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'));
    }
 
 
}