项目中常用到无限级,所以把之前写的循环拿出来整理下,以后遇到省的调试
//无限级查询上级
public function getParent($uid = 0){
if (!$this->find($uid)) {
return [];
}
$pid = $this->where('id',$uid)->value('pid');
if ($pid) {
$this->res[] = $pid;
$this->getParent($pid);
}else return [];
return $this->res;
}
//无限级向上查找最近等级的会员信息
public function getLevelParent($uid = 0,$level = 0){
if (!$this->find($uid)) {
return [];
}
$parent = $this->where('id',$uid)->find();
if ($parent['level'] >= $level) {
return $parent;
}else{