|
@@ -9,26 +9,39 @@ class Children
|
|
|
public function home()
|
|
|
{
|
|
|
$cur = Dever::input('mid');
|
|
|
+ $result = $index = array();
|
|
|
+ $k = -1;
|
|
|
+
|
|
|
$parent = Dever::load('invite/api')->getParentAll($cur, 5);
|
|
|
- $result = array();
|
|
|
- $data = array();
|
|
|
- if($parent){
|
|
|
- $index = array();
|
|
|
- $count = count($parent) - 1;
|
|
|
+ if ($parent) {
|
|
|
foreach($parent as $k => $v) {
|
|
|
$uid = $v['uid'];
|
|
|
$v = $this->button($v['uid'], $v['uid']);
|
|
|
if ($k == 0) {
|
|
|
$result = $v;
|
|
|
- }
|
|
|
+ }
|
|
|
$this->handle($result, $index, $k, $uid, $parent, $cur);
|
|
|
}
|
|
|
}
|
|
|
- $this->handle($result, $index, $k+1, $cur, $parent, false);
|
|
|
+ $k = $k+1;
|
|
|
+ $child = $this->handle($result, $index, $k, $cur, array(), false);
|
|
|
+
|
|
|
+ if ($child) {
|
|
|
+ $k = $k+1;
|
|
|
+ foreach ($child as $i => $v) {
|
|
|
+ $c = $this->handle($result, $index, $k, $v['mid'], array(), false, $i);
|
|
|
+ if ($c) {
|
|
|
+ foreach ($c as $j => $v1) {
|
|
|
+ //$d = $this->handle($result, $index, $k+1, $v['mid'], array(), false, $j);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
exit(Dever::json_encode($result));
|
|
|
}
|
|
|
|
|
|
- public function handle(&$result, &$index, $k, $uid, $parent, $cur)
|
|
|
+ public function handle(&$result, &$index, $k, $uid, $parent, $cur, $i = -1)
|
|
|
{
|
|
|
if (isset($parent[$k+1]['uid']) && $parent[$k+1]['uid']) {
|
|
|
$cur = $parent[$k+1]['uid'];
|
|
@@ -38,28 +51,37 @@ class Children
|
|
|
}
|
|
|
list($data, $index[$k]) = $this->child($uid, $cur, $color);
|
|
|
|
|
|
+ if (!$data) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
# 这里后续优化吧
|
|
|
+ if ($i < 0 && $k > 0) {
|
|
|
+ $i = $index[$k-1];
|
|
|
+ }
|
|
|
if ($k == 0) {
|
|
|
$result['children'] = $data;
|
|
|
} elseif ($k == 1) {
|
|
|
- $result['children'][$index[$k-1]]['children'] = $data;
|
|
|
+ $result['children'][$i]['children'] = $data;
|
|
|
} elseif ($k == 2) {
|
|
|
- $result['children'][$index[$k-2]]['children'][$index[$k-1]]['children'] = $data;
|
|
|
+ $result['children'][$index[$k-2]]['children'][$i]['children'] = $data;
|
|
|
} elseif ($k == 3) {
|
|
|
- $result['children'][$index[$k-3]]['children'][$index[$k-2]]['children'][$index[$k-1]]['children'] = $data;
|
|
|
+ $result['children'][$index[$k-3]]['children'][$index[$k-2]]['children'][$i]['children'] = $data;
|
|
|
} elseif ($k == 4) {
|
|
|
- $result['children'][$index[$k-4]]['children'][$index[$k-3]]['children'][$index[$k-2]]['children'][$index[$k-1]]['children'] = $data;
|
|
|
+ $result['children'][$index[$k-4]]['children'][$index[$k-3]]['children'][$index[$k-2]]['children'][$i]['children'] = $data;
|
|
|
} elseif ($k == 5) {
|
|
|
- $result['children'][$index[$k-5]]['children'][$index[$k-4]]['children'][$index[$k-3]]['children'][$index[$k-2]]['children'][$index[$k-1]]['children'] = $data;
|
|
|
+ $result['children'][$index[$k-5]]['children'][$index[$k-4]]['children'][$index[$k-3]]['children'][$index[$k-2]]['children'][$i]['children'] = $data;
|
|
|
} elseif ($k == 6) {
|
|
|
- $result['children'][$index[$k-6]]['children'][$index[$k-5]]['children'][$index[$k-4]]['children'][$index[$k-3]]['children'][$index[$k-2]]['children'][$index[$k-1]]['children'] = $data;
|
|
|
+ $result['children'][$index[$k-6]]['children'][$index[$k-5]]['children'][$index[$k-4]]['children'][$index[$k-3]]['children'][$index[$k-2]]['children'][$i]['children'] = $data;
|
|
|
} elseif ($k == 7) {
|
|
|
- $result['children'][$index[$k-7]]['children'][$index[$k-6]]['children'][$index[$k-5]]['children'][$index[$k-4]]['children'][$index[$k-3]]['children'][$index[$k-2]]['children'][$index[$k-1]]['children'] = $data;
|
|
|
+ $result['children'][$index[$k-7]]['children'][$index[$k-6]]['children'][$index[$k-5]]['children'][$index[$k-4]]['children'][$index[$k-3]]['children'][$index[$k-2]]['children'][$i]['children'] = $data;
|
|
|
} elseif ($k == 8) {
|
|
|
- $result['children'][$index[$k-8]]['children'][$index[$k-7]]['children'][$index[$k-6]]['children'][$index[$k-5]]['children'][$index[$k-4]]['children'][$index[$k-3]]['children'][$index[$k-2]]['children'][$index[$k-1]]['children'] = $data;
|
|
|
+ $result['children'][$index[$k-8]]['children'][$index[$k-7]]['children'][$index[$k-6]]['children'][$index[$k-5]]['children'][$index[$k-4]]['children'][$index[$k-3]]['children'][$index[$k-2]]['children'][$i]['children'] = $data;
|
|
|
} elseif ($k == 9) {
|
|
|
- $result['children'][$index[$k-9]]['children'][$index[$k-8]]['children'][$index[$k-7]]['children'][$index[$k-6]]['children'][$index[$k-5]]['children'][$index[$k-4]]['children'][$index[$k-3]]['children'][$index[$k-3]]['children'][$index[$k-1]]['children'] = $data;
|
|
|
+ $result['children'][$index[$k-9]]['children'][$index[$k-8]]['children'][$index[$k-7]]['children'][$index[$k-6]]['children'][$index[$k-5]]['children'][$index[$k-4]]['children'][$index[$k-3]]['children'][$index[$k-3]]['children'][$i]['children'] = $data;
|
|
|
}
|
|
|
+
|
|
|
+ return $data;
|
|
|
}
|
|
|
|
|
|
public function child($parent, $cur = false, $color = 2)
|