今天做一个多级分销代理,我这里要获取代理下的所有会员ID,下面是我所用的方法

通过代理ID来获取,这里的代理agentID可以是数组

//获取指定代理ID中的所有会员ID
function getAllUserId($categoryID)
{
    do
    {
        $ids = '';
        $where['vid'] = array('in',$categoryID);
        $user = M('userinfo')->where($where)->select();

        foreach ($user as $k=>$v){
            $array[] = $v['uid'];
            $ids .= ',' . $v['uid'];
        }
        $ids = substr($ids, 1, strlen($ids));
        $categoryID = $ids;
    }
    while (!empty($user));
    $ids = implode(',', $array);
    return $array;    //返回数组
    //return $ids   //  返回字符串
}

 

//可以用以下方法来获取子分类,父分类,下一级等,也可以用下面的方法来获取到代理下面的所有子代理,灵活应用

//获取指定分类所有父ID号
    function getAllFcateIds($categoryID)
    {
        //初始化ID数组
        $array[] = $categoryID;
         
        do
        {
            $ids = '';
            $where['id'] = array('in',$categoryID);
            $cate = M('cate')->where($where)->select();
            echo M('cate')->_sql();
            foreach ($cate as $v)
            {
                $array[] = $v['pid'];
                $ids .= ',' . $v['pid'];
            }
            $ids = substr($ids, 1, strlen($ids));
            $categoryID = $ids;
        }
        while (!empty($cate));
 
        $ids = implode(',', $array);
         return $ids;   //  返回字符串
        //return $array //返回数组
    }

 

//获取指定分类的所有子分类 键为ID,值为分类名
    function getCateKv($categoryID)
    {
        //初始化ID数组,赋值当前分类
        $array[] = M('cate')->where("id={$categoryID}")->getField("cateName");
        do
        {
            $ids = '';
            $where['pid'] = array('in',$categoryID);
            $cate = M('cate')->where($where)->select();
            echo M('cate')->_sql();
            foreach ($cate as $k=>$v)
            {
                $array[$v['id']] = $v['cateName'];
                $ids .= ',' . $v['id'];
            }
            $ids = substr($ids, 1, strlen($ids));
            $categoryID = $ids;
        }
        while (!empty($cate));
        $ids = implode(',', $array);
 
         //return $ids; //  返回字符串
        return $array //返回数组
    }

 获取某个文章分类的 儿子 孙子  重子重孙 的 id

/**
 * 获取某个文章分类的 儿子 孙子  重子重孙 的 id
 * @param type $cat_id
 */
function getArticleCatGrandson ($cat_id){
    $GLOBALS['ArticleCatGrandson'] = array();
    $GLOBALS['cat_id_arr'] = array();
    // 先把自己的id 保存起来
    $GLOBALS['ArticleCatGrandson'][] = $cat_id;
    // 把整张表找出来
    $GLOBALS['cat_id_arr'] = M('ArticleCat')->getField('cat_id,parent_id');
    // 先把所有儿子找出来
    $son_id_arr = M('ArticleCat')->where("parent_id = $cat_id")->getField('cat_id',true);
    foreach($son_id_arr as $k => $v)
    {
        getArticleCatGrandson2($v);
    }
    return $GLOBALS['ArticleCatGrandson'];
}

 查询分类的所有上级ID

//根据PID查询上级所有分类ID
function get_cate_id($pid,$menus){
    $arr=array();
    foreach ($menus as $key => $v) {
        if($v['id']==$pid){  //pid为0的是顶级分类
            $arr[]=$v['id'];
            if ($v['pid'] > 0) {
                $arr = array_merge($arr,get_cate_id($v['pid'],$menus));
            }
        }
    }
    return $arr;
}

 

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6