/* * 获取当前用户的下5级 * $parent 当前用户id 数组格式 例子[1]比如获取用户1的下5级 * $level 所属第几级用户 1表示当前用户的下1级用户 为0或者不传 默认所有5级用户信息 * $sub 数据集 变量参数 默认值即可 * $depth 深度 默认值即可 * 调用 $this->getSub([1],5);获取当前用户第5级的用户信息 * */ public function getAwardUser($parent = [],$level=0,$sub = [], $depth = 1) { if (empty($parent)) return []; $ids = []; $im=implode(',',$parent); $userModel = $this->getDatabase('User'); $tmp= $userModel->select("extend_id in ($im)",'id');//获取下一级成员 if ($tmp){ $tmp2=$tmp; while ($tmp2){ $pop = array_pop($tmp2); $sub[$depth][] = $pop; } $tmp_id = array_column($tmp,'id'); while ($tmp_id){ $pop = array_pop($tmp_id); array_push($ids,$pop); } } if ($level > 0 and $level < 6) { if ($depth > $level) return $sub[$level]; } if ($ids) return $this->getAwardUser($ids,$level,$sub,$depth + 1); else return $sub; }