取三级分销上下级用户id
Posted ruanqin
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了取三级分销上下级用户id相关的知识,希望对你有一定的参考价值。
//取上三级的用户id
public function _get_up_third_id($member_id){
$up_id=array();
$invite_id=dbselect(‘invite_id‘)->from(‘{dt_user}‘)->where([‘id‘=>$member_id])->get(0,‘invite_id‘);
if($invite_id>0){
//取上一级id
$up_first=dbselect(‘id,invite_id‘)->from(‘{dt_user}‘)->where([‘id‘=>$invite_id])->get(0);
if($up_first)
{
$up_id[‘up_first‘]=$up_first[‘id‘];
if($up_first[‘invite_id‘]>0)
{
//取上二级id
$up_two=dbselect(‘id,invite_id‘)->from(‘{dt_user}‘)->where([‘id‘=>$up_first[‘invite_id‘]])->get(0);
if($up_two)
{
$up_id[‘up_two‘]=$up_two[‘id‘];
if($up_two[‘invite_id‘]>0)
{
$up_id[‘up_third‘]=$up_two[‘invite_id‘];
}
}
}
}
}
return $up_id;
}
//取下三路id
public function _get_down_third_id($member_id){
$down_third_info=array();
//一级id
$down_first=$this->_get_son_id([$member_id]);
if($down_first)
{
$ids_first=[];
$ids_two=[];
//循环取出一级id中对应下级
$down_third_info[‘down_first‘]=$down_first;
//将数组中的id取出,然后根据拼装的数组取下一级的id
foreach ($down_first as $key)
{
array_push($ids_first,$key[‘id‘]);
}
//二级id
$down_two=$this->_get_son_id($ids_first);
if($down_two){
$down_third_info[‘down_two‘]=$down_two;
foreach($down_two as $row){
array_push($ids_two,$row[‘id‘]);
}
//三级id
$down_third=$this->_get_son_id($ids_two);
if($down_third){
$down_third_info[‘down_third‘]=$down_third;
}
}
}
return $down_third_info;
}
//根据父级id取子级id
private function _get_son_id($ids=[]){
$list=dbselect(‘id,invite_id‘)->from(‘{dt_user}‘)->where([‘invite_id IN‘=>$ids])->toArray();
if($list)
{
return $list;
}
else
{
return array();
}
}
以上是关于取三级分销上下级用户id的主要内容,如果未能解决你的问题,请参考以下文章