查找下级所有数据

admin2年前Laravel1050

public function bottom($mid = 3)
{
   $members = DB::select('select id,parent_id,`level` from member where status= 1  and parent_id >= 0');
   $Teams = array();//最终结果
   $mids = array($mid);//第一次执行时候的用户id
   do {
       $othermids = array();
       $state = false;
       foreach ($mids as $valueone) {
           foreach ($members as $key => $valuetwo) {
               if ($valuetwo->parent_id == $valueone) {
                   $Teams[] = $valuetwo->id;//找到我的下级立即添加到最终结果中
                   $othermids[] = $valuetwo->id;//将我的下级id保存起来用来下轮循环他的下级
                   $state = true;
               }
           }
       }
       $mids = $othermids;//foreach中找到的我的下级集合,用来下次循环
   } while ($state == true);
   array_push($Teams, $mid);
   return $Teams;
}

相关文章

生成二维码

public function qrcode($uid){    require_once base_path() . '/public/phpqrcode/phpqrco...

验证手机号

public function phone($phone){    $pat = '/'        . '^13...

设置项目编号

$max = Db::table('member')->max('id') ?? 0; if ($max < 100000) { $cd = $this->create...

两个经纬度之间的距离

    public function haversineGreatCircleDistance($latitude1, $longitude1, $latitude2, $lon...

阿里云发送短信

public function sms(){    $moile = request()->input('mobile');    if...

关注公众号并登录

/* * 服务端生成带唯一标识二维码并将唯一标识返回给前端 */ public function wx_code() { $scene_str = $this->get_...