Category.php
2.8 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
<?php
namespace app\api\controller;
use addons\shopro\model\Category as CategoryModel;
use addons\shopro\model\Goods;
/**
* 分类管理
*
* @icon fa fa-list
* @remark 用于统一管理网站的所有分类,分类可进行无限级分类,分类类型请在常规管理->系统配置->字典配置中添加
*/
class Category extends Base
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
/**
* @ApiWeigh (99)
* @ApiTitle (商城分类)
* @ApiSummary (商城分类)
* @ApiMethod (GET)
*
* @ApiReturn({
"code": 1,
"msg": "商城分类",
"time": "1607653266",
"data": {
"id": 1, //不用管
"name": "商品分类", //不用管
"type": "3", //不用管
"image": null, //不用管
"pid": 0, //不用管
"weigh": 0, //不用管
"description": "", //不用管
"children": [{
"id": 2, //一级分类ID
"name": "一级分类", 一级分类名称
"type": "",
"image": null, //一级分类图片
"pid": 1,
"weigh": 0,
"description": "",
"children": [{
"id": 3, //二级分类ID
"name": "二级分类", //二级分类名称
"type": "",
"image": null, //二级分类图片
"pid": 2,
"weigh": 0,
"description": "",
"children": [] //不用管
}]
}]
}
})
*/
public function index()
{
$id = $this->request->get('id',1);
$data = CategoryModel::getCategoryList($id);
$this->success('商城分类', $data);
}
/**
* @ApiInternal
* 商城分类商品
*/
public function goods() {
$params = $this->request->get();
$category_id = $params['category_id'];
$categories = CategoryModel::where('pid', $category_id)->where('status', 'normal')->select();
// 获取这个分类下面的所有商品
$goodsList = Goods::getGoodsList(array_merge($params, ['no_activity' => true]), false);
foreach($categories as $key => $category) {
$categoryIds = ',' . $category['id'] . ',';
$currentCategoryGoods = [];
foreach ($goodsList as $k => $goods) {
$goodsCategoryIds = ',' . $goods['category_ids'] . ',';
if (strpos($goodsCategoryIds, $categoryIds) !== false) {
$currentCategoryGoods[] = $goods;
}
}
$categories[$key]['goods'] = $currentCategoryGoods;
}
$this->success('商城分类商品', $categories);
}
}