select id,ruid,nickname,telphone from tf_user limit 30;
+----+------+------------+-------------+
| id | ruid | nickname | telphone |
+----+------+------------+-------------+
| 1 | 0 | 候淑娥 | 15852052228 |
| 2 | 1 | 候淑娥1 | 15852052228 |
| 3 | 2 | 候淑娥2 | 15852052228 |
| 4 | 2 | 候淑娥3 | 15852052228 |
| 5 | 2 | 候淑娥4 | 15852052228 |
| 6 | 2 | 候淑娥5 | 15852052228 |
| 7 | 2 | 候淑娥6 | 15852052228 |
| 8 | 2 | 候淑娥7 | 15852052228 |
| 9 | 2 | 候淑娥8 | 15852052228 |
| 10 | 3 | 陈茹 | 15252185133 |
| 11 | 10 | 陈茹1 | 15252185133 |
| 12 | 10 | 陈茹2 | 15252185133 |
| 13 | 10 | 陈茹3 | 15252185133 |
| 14 | 10 | 陈茹4 | 15252185133 |
| 15 | 10 | 陈茹5 | 15252185133 |
| 16 | 10 | 陈茹6 | 15252185133 |
| 17 | 10 | 陈茹7 | 15252185133 |
| 18 | 3 | 张明裕 | 15295469779 |
| 19 | 18 | 张明裕1 | 15295469779 |
| 20 | 18 | 张明裕2 | 15295469779 |
| 21 | 18 | 张明裕3 | 15295469779 |
| 22 | 18 | 张明裕4 | 15295469779 |
| 23 | 18 | 张明裕5 | 15295469779 |
| 24 | 18 | 张明裕6 | 15295469779 |
| 25 | 18 | 张明裕7 | 15295469779 |
| 26 | 3 | 仝建立 | 15952131238 |
| 27 | 26 | 仝建立1 | 15952131238 |
| 28 | 26 | 仝建立2 | 15952131238 |
| 29 | 26 | 仝建立3 | 15952131238 |
| 30 | 26 | 仝建立4 | 15952131238 |
+----+------+------------+-------------+
30 rows in set (0.00 sec)
private function _getson($uid,$level)
{
$sonlists = Db::name('user')
->where(['ruid' => $uid])
->order('id desc')
->field('id,ruid,top_uid,nickname,telphone')
->select();
if ($sonlists) {
foreach ($sonlists as $k => &$v) {
$v['level'] = $level;
$data = $this->_getson($v['id'],$level + 1);
$v['nickname'] = $v['id'] . '-' . $v['nickname'];
if ($data && $v['level'] < 3){ //&& $v['level'] < 10 去掉可以无限级抓取;为了不展示太多数据而限制的 ;
$v['children'] = $data;
}
}
}
return $sonlists;
}
public function family()
{
$info = Db::name('user')
->where(['id' => $_GET['top_uid']])
->order('id desc')
->field('id,ruid,top_uid,nickname,telphone')
->select();
$child = $this->_getson($_GET['top_uid'],'2');
$info[0]['children'] = $child;
$this->assign('info', $info);
dump($info);
exit;
$this->assign('model_name', '家族族谱');
return $this->fetch();
}
array(1) {
[0] => array(6) {
["id"] => int(1)
["ruid"] => int(0)
["top_uid"] => int(1)
["nickname"] => string(9) "候淑娥"
["telphone"] => string(11) "158520500008"
["children"] => array(1) {
[0] => array(7) {
["id"] => int(2)
["ruid"] => int(1)
["top_uid"] => int(1)
["nickname"] => string(12) "2-候淑娥1"
["telphone"] => string(11) "1585200000"
["level"] => string(1) "2"
["children"] => array(7) {
[0] => array(6) {
["id"] => int(9)
["ruid"] => int(2)
["top_uid"] => int(1)
["nickname"] => string(12) "9-候淑娥8"
["telphone"] => string(11) "15800002228"
["level"] => int(3)
}
[1] => array(6) {
["id"] => int(8)
["ruid"] => int(2)
["top_uid"] => int(1)
["nickname"] => string(12) "8-候淑娥7"
["telphone"] => string(11) "15800002228"
["level"] => int(3)
}
[2] => array(6) {
["id"] => int(7)
["ruid"] => int(2)
["top_uid"] => int(1)
["nickname"] => string(12) "7-候淑娥6"
["telphone"] => string(11) "158000028"
["level"] => int(3)
}
[3] => array(6) {
["id"] => int(6)
["ruid"] => int(2)
["top_uid"] => int(1)
["nickname"] => string(12) "6-候淑娥5"
["telphone"] => string(11) "158000052228"
["level"] => int(3)
}
[4] => array(6) {
["id"] => int(5)
["ruid"] => int(2)
["top_uid"] => int(1)
["nickname"] => string(12) "5-候淑娥4"
["telphone"] => string(11) "15800002228"
["level"] => int(3)
}
[5] => array(6) {
["id"] => int(4)
["ruid"] => int(2)
["top_uid"] => int(1)
["nickname"] => string(12) "4-候淑娥3"
["telphone"] => string(11) "158500002228"
["level"] => int(3)
}
[6] => array(6) {
["id"] => int(3)
["ruid"] => int(2)
["top_uid"] => int(1)
["nickname"] => string(12) "3-候淑娥2"
["telphone"] => string(11) "1585****28"
["level"] => int(3)
}
}
}
}
}
}