Category.php
1.5 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
<?php
namespace addons\shopro\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 = ['*'];
public function index()
{
$id = $this->request->get('id');
$data = CategoryModel::getCategoryList($id);
$this->success('商城分类', $data);
}
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);
}
}