查找下级所有数据

admin1年前Laravel579

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 wxlogin(){       $code = request()->input('code'); &n...

发送公众号信息

* 发送消息 */public function tosend($openid, $title, $content, $time, $aid){    $tokens = $thi...

设置项目编号

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

微信退款v3

/** * 微信 退款 操作 */ public function refund($out_trade_no, $refund_money) { $time = time();...

用户注册账号

public function register(){    $mobile = request()->input('mobile');   &nb...

解密微信绑定的手机号

public function mobile() { $code = request()->input('code'); if (!$code) { return $this-&...