您的位置:首页 > 编程语言 > PHP开发

laravel 商品无限级分类

2017-05-12 11:33 302 查看
//商品类别查询
public function topParent()
{
$where['commodType_depth'] = 1;
$where['commodType_status'] = 1;
$where['commodType_parentId'] = null;
return $this->where($where)->get(['commodType_id', 'commodType_name']);
}

//商品分类子集递归查询
public function child($commodType_id)
{
$arr[] = Array();
$where['commodType_status'] = 1;
$where['commodType_parentId'] = $commodType_id;
if ($arr = $this->where($where)->get(['commodType_id', 'commodType_name'])) {
foreach ($arr as $k => $v) {
$arr[$k]['child'] = $this->child($v->commodType_id);
}
}
return $arr;
}

//商品分类列表  无限级
public function commod_type_list()
{
$arr = $this->topParent();
if ($arr) {
foreach ($arr as $k => $v) {
$arr[$k]['child'] = $this->child($v->commodType_id);
}
}
return $arr;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: