Category.php
3.9 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
namespace app\api\controller;
use app\common\controller\Api;
/**
* 分类接口
*/
class Category extends Api
{
protected $categoryModel;
protected $categoryGroupModel;
public function _initialize()
{
parent::_initialize();
$this->categoryModel = new \app\api\model\Category;
$this->categoryGroupModel = new \app\api\model\CategoryGroup;
}
/**
* @ApiTitle (首页分类)
* @ApiSummary (首页分类)
* @ApiMethod (POST)
* @ApiRoute (/api/category/getCategoryIndex)
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1553839125",
"data": {
"id": "id",//幻灯片id
"goods_id": "shop_id",//商品id(可跳转商品详情)
"title": "title",//标题
"image": "image",//图片
},
})
*/
public function getCategoryIndex(){
$data['category1'] = $this->categoryGroupModel->selectData(['sitelist'=>['like','%' . 1 . '%']],4,$this->lang);
$data['category2'] = $this->categoryGroupModel->selectData(['sitelist'=>['like','%' . 2 . '%']],3,$this->lang);
$data['category3'] = $this->categoryModel->selectData(['pid'=>0],null,$this->lang);
$this->success('SUCCESS',$data);
}
/**
* @ApiTitle (分类页列表)
* @ApiSummary (分类页列表)
* @ApiMethod (POST)
* @ApiRoute (/api/category/getCategory)
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587524078",
"data": {
"category1": [ 顶部分组列表
{
"id": 2, 分组id
"ch_name": "素食", 中文名称
"en_name": "vegetarian", 英文名称
"ch_index_name": "素食", 中文首页名称
"en_index_name": "vegetarian", 英文首页名称
"index_image": "http://q7s0a1rb4.bkt.clouddn.com/assets/img/qrcode.png", 首页图片
"image": "" 图片
}
],
"category2": [ 左侧一级分类列表
{
"id": 8, 分类id
"ch_name": "乳品蛋类", 中文名称
"en_name": "Eggs in the dairy", 英文名称
"image": "" 图片
},
{
"id": 1,
"ch_name": "生鲜产品",
"en_name": "fresh product",
"image": "http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png"
}
],
"category3": [ 右侧二级分类列表
{
"ch_name": "乳品蛋类", 一级分类中文名称
"en_name": "Eggs in the dairy", 一级分类英文名称
"list": [ 二级分类列表
{
"id": 11, 分类id
"ch_name": "酸奶/甜点", 二级分类中文名称
"en_name": "Yogurt/dessert", 二级分类英文名称
"image": ""
},
{
"id": 10,
"ch_name": "鸡蛋",
"en_name": "henapple",
"image": ""
},
{
"id": 9,
"ch_name": "牛奶",
"en_name": "milk",
"image": ""
}
]
},
{
"ch_name": "生鲜产品",
"en_name": "fresh product",
"list": [
{
"id": 5,
"ch_name": "水产海鲜",
"en_name": "aquaculture seafood",
"image": "http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png"
},
{
"id": 2,
"ch_name": "肉类",
"en_name": "meat",
"image": ""
}
]
}
]
}
})
*/
public function getCategory(){
$data['category1'] = $this->categoryGroupModel->selectData(['sitelist'=>['like','%' . 3 . '%']],4,$this->lang);
$data['category2'] = $this->categoryModel->selectData(['pid'=>0],null,$this->lang);
$data['category3'] = [];
foreach ($data['category2'] as $k=>$v){
$data['category3'][$k]['name'] = $v['name'];
$data['category3'][$k]['list'] = $this->categoryModel->selectData(['pid'=>$v['id']],null,$this->lang);
if (!$data['category3'][$k]['list']){
unset($data['category2'][$k]);
unset($data['category3'][$k]);
}
}
$this->success('SUCCESS',$data);
}
}