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
<?php
 
namespace app\api\controller\product;
 
use app\api\model\product\Category as CategoryModel;
use app\api\controller\Controller;
use app\common\model\page\PageCategory as PageCategoryModel;
use app\api\model\product\Product as ProductModel;
use app\api\model\settings\Setting as SettingModel;
/**
 * 商品分类控制器
 */
class Category extends Controller
{
    /**
     * 分类页面
     */
    public function index()
    {
        $postData =$this->postData();
        $city_supplier_ids = empty($postData["city_supplier_ids"]) ? '' : $postData["city_supplier_ids"];
        // 分类模板
        $template = PageCategoryModel::detail();
        // 商品分类列表
        $list = array_values(CategoryModel::getCacheTree());
        $list =$this->hideCate($list);
        $category_id=0;
        if(count($list)>0){
            $category_id=$list[0]['category_id'];
        }
        $data=['page'=>1,'category_id'=>$category_id,'city_supplier_ids'=>$city_supplier_ids,'search'=>'','sortType'=>'','sortPrice'=>'','list_rows'=>10];
        $param = array_merge($data, [
            'product_status' => 10,
            'audit_status' => 10
        ]);
        
        // 获取列表数据
        $model = new ProductModel;
        $productList = $model->getList($param, $this->getUser(false));
 
        $store = SettingModel::getItem('store');
        
        return $this->renderSuccess('', compact('template','list','productList','store'));
    }
    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);
    }
}