无限极分类查询

孤人 提交于 2020-08-06 06:24:43
public function allClassify()
{
    $model = new ClassifyLogic();
    $list = $model -> getList('', '', '');

    foreach ($list as $k=>$v)
    {
        $cat_class[$k]['id']   = $v['id'];
        $cat_class[$k]['cate_name']   = $v['cate_name'];
        $cat_class[$k]['pid']   = $v['pid'];

        $getSon = $this->get_child_tree($v['id'],1);
        if ($getSon)
        {
            $cat_class[$k]['child'] = $this->get_child_tree($v['id']);
        }
    }

    foreach ($cat_class as $v)
    {
        if ($v['pid'] != 0)
        {
            unset($v);
        }

        $new_list[] = $v;
    }
    $list= array_filter($new_list);

    
    return json_encode([
        'code' => 0,
        'response' => $list,
        'errMsg' => '请求成功'
    ]);
}

//获取当前分类下的子分类(不包括自己)
function get_child_tree($tree_id,$get=0)
{
    $two_arr = [];
    $model = new ClassifyLogic();
    $list = $model -> getList(['pid' => $tree_id], '', '');

    if($get && empty($list)){
        return false;
    }
    foreach ($list AS $k=>$v)
    {
        $two_arr[$k]['id']   = $v['id'];
        $two_arr[$k]['cate_name'] = $v['cate_name'];
        $two_arr[$k]['pid']   = $v['pid'];

        $getSon = $this->get_child_tree($v['id'],1);
        if ($getSon){
            $two_arr[$k]['child'] = $this->get_child_tree($v['id']);
        }
    }
    return $two_arr;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!