1,递归找出指定用户的指定层级的下级用户
/**
* 找到指定用户的指定级别的下级用户
* @param $pidStr 指定用户id
* @param $num 指定第几个下级
* @return string 返回下级id组成的字符串
*/
function getSonsId($pidStr,$num){
$sql = "SELECT user_id FROM ".$GLOBALS['ecs']->table('users')." WHERE parent_id IN (".$pidStr.")";
$sonArr = $GLOBALS['db']->getAll($sql);
foreach($sonArr as $key => $val){
$sonArr[$key] = $val["user_id"];
}
$sonStr = implode(',',$sonArr);
if($num == 1){
return $sonStr;
}else{
$num--;
return getSonsId($sonStr,$num);
}
}
2,递归找当前产品最顶级分类
//找到该商品的分类
$sql = "SELECT cat_id FROM ecs_goods WHERE goods_id";
$scat_id = $db->getOne($sql);
$bigCatId = getBigCatByCatId($scat_id)
//根据商品分类找到其所属的最顶级分类
function getBigCatByCatId($cat_id){
$sql = "SELECT parent_id FROM ecs_category WHERE cat_id = ".$cat_id;
$fcat_id = $db->getOne($sql);
if($fcat_id == '0'){
return $cat_id;
}else{
return getBigCatByCatId($fcat_id);
}
}