huangsijun
2025-09-22 a78c011de350b188afb03beb2f26a73f35f71986
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
<?php
 
namespace app\api\controller\plus\goodcoupon;
 
use app\api\model\plus\goodcoupon\Category as CategoryModel;
use app\api\model\plus\goodcoupon\Coupon as goodCouponModel;
use app\api\controller\Controller;
;
/**
 * 分类控制器
 */
class Category extends Controller
{
    /**
     * 分类页面
     */
    public function index()
    {
        // 商品分类列表
        $all_list = array_values(CategoryModel::getCacheTree());
        $all_list =$this->hideCate($all_list);
        //获取券商品的所有分类id
        $category_ids = goodCouponModel::getCategoryIds();
        $category_list = [];
        if(!empty($all_list) && !empty($category_ids)){
            foreach ($all_list as $val){
                //筛选出券商品的分类
                if(in_array($val["category_id"],$category_ids)){
                    $category_list[] = $val;
                }
            }
        }
 
        return $this->renderSuccess('', compact('category_list'));
    }
 
    public function hideCate($all){
        if(empty($all)){
            return $all;
        }
        foreach ($all as $i=>$first) {
            if (intval($all[$i]["status"]) === 0){
                unset($all[$i]);
            }
            if(!empty($all[$i]['child'])){
                foreach ($all[$i]['child'] as $j=>$two) {
                    if (intval($all[$i]['child'][$j]["status"]) === 0){
                        unset($all[$i]['child'][$j]);
                    }
 
                    if(!empty($all[$i]['child'][$j]['child'])){
                        foreach ($all[$i]['child'][$j]['child'] as $k=>$three){
                            if (intval($all[$i]['child'][$j]["child"][$k]["status"]) === 0){
                                unset($all[$i]['child'][$j]["child"][$k]);
                            }
                        }
                    }
                }
            }
        }
        return array_values($all);
    }
 
}