获取无限极分类底级分类之后查询(递归)

function get_categories_tree()
{
$cat_class = array();

/*
适用与无限极分类展示
*/

/* 获取当前分类及其子分类 (包括自己)*/
$res = Db::name('DomelampNode')->where('pid',null)->order('id desc')->limit(10)->select();

if(!empty($res)){

foreach ($res AS $k=>$v)
{
$cat_class[$k]['id'] = $v['id'];
$cat_class[$k]['name'] = $v['name'];
$cat_class[$k]['pid'] = $v['pid'];
$getSon = $this->get_child_tree($v['id'],1);
if ($getSon)
{
$cat_class[$k]['three_class'] = $this->get_child_tree($v['id']);
}
}
}
if(isset($cat_class))
{
return $cat_class;

}
}

//获取当前分类下的子分类(不包括自己)
function get_child_tree($tree_id,$get=0)
{

$two_arr = array();
$res = Db::name('DomelampNode')->where('pid',$tree_id)->order('id desc')->limit(10)->select();

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

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

}
return $two_arr;
}
//查询直推业绩300以上的人
SELECT id,username FROM fa_user AS u WHERE (SELECT SUM(kjsl) FROM fa_kjorder AS k LEFT JOIN fa_user AS yy ON k.username=yy.username WHERE k.addtime >= 1543075200 AND k.addtime <= 1546012799 AND yy.pid=u.username) >= 300

转载于:https://www.cnblogs.com/nonoleng/p/9581059.html

你可能感兴趣的:(数据库,python,c#)