|
@@ -6,270 +6,103 @@ use Dever;
|
|
|
|
|
|
class Children
|
|
|
{
|
|
|
- public function text(){
|
|
|
- $cur = Dever::input('mid');
|
|
|
-
|
|
|
- $invite = Dever::load('invite/api')->getChild($cur);
|
|
|
-
|
|
|
- $result = array();
|
|
|
- $data = array();
|
|
|
- $index = array();
|
|
|
- $count = count($invite) - 1;
|
|
|
- $i=0;
|
|
|
- foreach($invite as $k => $v) {
|
|
|
-
|
|
|
- }
|
|
|
- print_R($result);die;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public function home(){
|
|
|
+
|
|
|
+ private $cur_color = 'blue';
|
|
|
+
|
|
|
+ private $parent_color = '#d71345';
|
|
|
+
|
|
|
+ private $child_color = 'green';
|
|
|
+
|
|
|
+ private $color = '#bababa';
|
|
|
+
|
|
|
+ public function home()
|
|
|
+ {
|
|
|
$cur = Dever::input('mid');
|
|
|
- $invite = Dever::load('invite/api')->getParentAll($cur, 5);
|
|
|
-
|
|
|
- $result = array();
|
|
|
+ $parent = Dever::load('invite/api')->getParentAll($cur, 5, 2);
|
|
|
+
|
|
|
$data = array();
|
|
|
- if($invite){
|
|
|
- $index = array();
|
|
|
- $count = count($invite) - 1;
|
|
|
- foreach($invite as $k => $v) {
|
|
|
-
|
|
|
- $uid = $v['uid'];
|
|
|
- $v = $this->button($v['uid'], $v['uid']);
|
|
|
- if ($count == $k) {
|
|
|
-
|
|
|
- }
|
|
|
- if ($k == 0) {
|
|
|
- $result = $v;
|
|
|
- list($result['children'], $index[$k]) = $this->child($uid, $invite[$k+1]['uid']);
|
|
|
- }
|
|
|
- if ($k == 1) {
|
|
|
- list($result['children'][$index[$k-1]]['children'], $index[$k]) = $this->child($uid, $invite[$k+1]['uid']);
|
|
|
- }
|
|
|
- if ($k == 2) {
|
|
|
- list($result['children'][$index[$k-2]]['children'][$index[$k-1]]['children'], $index[$k]) = $this->child($uid, $invite[$k+1]['uid']);
|
|
|
- }
|
|
|
- if ($k == 3) {
|
|
|
- list($result['children'][$index[$k-3]]['children'][$index[$k-2]]['children'][$index[$k-1]]['children'], $index[$k]) = $this->child($uid, $invite[$k+1]['uid']);
|
|
|
- }
|
|
|
- if ($k == 4) {
|
|
|
- list($result['children'][$index[$k-4]]['children'][$index[$k-3]]['children'][$index[$k-2]]['children'][$index[$k-1]]['children'], $index[$k]) = $this->child($uid, $cur);
|
|
|
+ $parents = array();
|
|
|
|
|
|
- }
|
|
|
+ if ($parent) {
|
|
|
+ foreach ($parent as $k => $v) {
|
|
|
+ $parents[] = $v['uid'];
|
|
|
}
|
|
|
-
|
|
|
- }
|
|
|
- exit(Dever::json_encode($result));
|
|
|
- }
|
|
|
- public function child($parent, $cur = false) {
|
|
|
- $result = array();
|
|
|
- $index = 0;
|
|
|
- $child = Dever::load('invite/api')->getChild($parent, 1, false);
|
|
|
-
|
|
|
- $num = count($child) / 2;
|
|
|
- foreach ($child as $k => $v) {
|
|
|
- $result[] = $this->button($v['to_uid'], $cur);
|
|
|
- if ($v['to_uid'] == $cur) {
|
|
|
- $index = $k;
|
|
|
+
|
|
|
+ $top = Dever::db('agent/member')->find($parent[0]['uid']);
|
|
|
+ if (!$top) {
|
|
|
+ Dever::alert('错误的上级用户信息');
|
|
|
}
|
|
|
- }
|
|
|
- if ($cur) {
|
|
|
- $old = $result;
|
|
|
- $result[$index] = $result[$num];
|
|
|
- $result[$num] = $old[$index];
|
|
|
- $index = $num;
|
|
|
+ $color = $this->parent_color;
|
|
|
+
|
|
|
+ $state = 1;
|
|
|
+ } else {
|
|
|
+ Dever::alert('根用户无法查询');
|
|
|
+ $top = Dever::db('agent/member')->find($cur);
|
|
|
+ $color = $this->cur_color;
|
|
|
+
|
|
|
+ $state = 2;
|
|
|
}
|
|
|
|
|
|
- return array($result, $index);
|
|
|
- }
|
|
|
-
|
|
|
- public function index($mid){
|
|
|
- $uid = Dever::input('mid',$mid);
|
|
|
+ $i = 0;
|
|
|
+ $data[$i]['id'] = $top['id'];
|
|
|
+ $data[$i]['name'] = $top['name'];
|
|
|
+ $data[$i]['parent_id'] = 0;
|
|
|
+ $data[$i]['itemStyle']['color'] = $color;
|
|
|
+
|
|
|
+ $this->getChild($data, $i, $top['id'], $parents, $cur, $state);
|
|
|
|
|
|
-
|
|
|
- $invite = $this->invite($mid);
|
|
|
-
|
|
|
- if($invite){
|
|
|
- foreach($invite as $k =>$v){
|
|
|
- $member = $this->button($mid);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ $result = Dever::walk($data, 0);
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- $m1 = $this->button($v['to_uid']);
|
|
|
- if($v['to_uid']==$uid){
|
|
|
- $info['children'][$k]['name'] = $m1['value'];
|
|
|
- $info['children'][$k]['itemStyle']['color'] = 'blue';
|
|
|
- }else{
|
|
|
- $info['children'][$k]['name'] = $m1['value'];
|
|
|
+ return $result[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getChild(&$data, &$i, $uid, $parents, $cur, $state, $next = true)
|
|
|
+ {
|
|
|
+ $child = Dever::db('agent/member')->select(array('parent_mid' => $uid));
|
|
|
+ if ($child) {
|
|
|
+ foreach ($child as $k => $v) {
|
|
|
+ $i++;
|
|
|
+ $data[$i]['id'] = $v['id'];
|
|
|
+ $data[$i]['name'] = $v['name'] . substr($v['mobile'], -4);
|
|
|
+ $data[$i]['parent_id'] = $v['parent_mid'];
|
|
|
+ $data[$i]['itemStyle']['color'] = $this->color;
|
|
|
+
|
|
|
+ $data[$i]['value'] = $v['name'] . '<br />' . $v['mobile'];
|
|
|
+ if ($v['role']) {
|
|
|
+ $role = Dever::db('setting/role')->find($v['role']);
|
|
|
+ if ($role) {
|
|
|
+ $data[$i]['value'] .= '<br />角色:' . $role['name'];
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- $i1 = $this->invite($v['to_uid']);
|
|
|
- if($i1){
|
|
|
- foreach($i1 as $k1 => $v1){
|
|
|
- $m2 = $this->button($v1['to_uid']);
|
|
|
- if($v1['to_uid'] == $uid){
|
|
|
- $info['children'][$k]['children'][$k1]['name'] = $m2['value'];
|
|
|
- $info['children'][$k]['children'][$k1]['itemStyle']['color'] = 'blue';
|
|
|
- }else{
|
|
|
- $info['children'][$k]['children'][$k1]['name'] = $m2['value'];
|
|
|
- }
|
|
|
-
|
|
|
- $i2 = $this->invite($v1['to_uid']);
|
|
|
- if($i2){
|
|
|
- foreach($i2 as $k2 => $v2){
|
|
|
- $m3 = $this->button($v2['to_uid']);
|
|
|
- if($v2['to_uid'] == $uid){
|
|
|
- $info['children'][$k]['children'][$k1]['children'][$k2]['name'] = $m3['value'];
|
|
|
- $info['children'][$k]['children'][$k1]['children'][$k2]['itemStyle']['color'] = 'blue';
|
|
|
- }else{
|
|
|
- $info['children'][$k]['children'][$k1]['children'][$k2]['name'] = $m3['value'];
|
|
|
- }
|
|
|
-
|
|
|
- $i3 = $this->invite($v2['to_uid']);
|
|
|
- if($i3){
|
|
|
- foreach($i3 as $k3 => $v3){
|
|
|
- $m4 = $this->button($v3['to_uid']);
|
|
|
- if($v3['to_uid'] == $uid){
|
|
|
- $info['children'][$k]['children'][$k1]['children'][$k2]['children'][$k3]['name'] = $m4['value'];
|
|
|
- $info['children'][$k]['children'][$k1]['children'][$k2]['children'][$k3]['itemStyle']['color'] = 'blue';
|
|
|
- }else{
|
|
|
- $info['children'][$k]['children'][$k1]['children'][$k2]['children'][$k3]['name'] = $m4['value'];
|
|
|
- }
|
|
|
-
|
|
|
- $i4 = $this->invite($v3['to_uid']);
|
|
|
- if($i4){
|
|
|
- foreach($i4 as $k4 => $v4){
|
|
|
- $m5 = $this->button($v4['to_uid']);
|
|
|
- if($v4['to_uid'] == $uid){
|
|
|
- $info['children'][$k]['children'][$k1]['children'][$k2]['children'][$k3]['children'][$k4]['name'] = $m5['value'];
|
|
|
- $info['children'][$k]['children'][$k1]['children'][$k2]['children'][$k3]['children'][$k4]['itemStyle']['color'] = 'blue';
|
|
|
- }else{
|
|
|
- $info['children'][$k]['children'][$k1]['children'][$k2]['children'][$k3]['children'][$k4]['name'] = $m5['value'];
|
|
|
- }
|
|
|
-
|
|
|
- $i5 = $this->invite($v4['to_uid']);
|
|
|
- if($i5){
|
|
|
- foreach($i5 as $k5 => $v5){
|
|
|
- $m6 = $this->button($v5['to_uid']);
|
|
|
- if($v5['to_uid']==$uid){
|
|
|
- $info['children'][$k]['children'][$k1]['children'][$k2]['children'][$k3]['children'][$k4]['children'][$k5]['name'] = $m6['value'];
|
|
|
- $info['children'][$k]['children'][$k1]['children'][$k2]['children'][$k3]['children'][$k4]['children'][$k5]['itemStyle']['color'] = 'blue';
|
|
|
- }else{
|
|
|
- $info['children'][$k]['children'][$k1]['children'][$k2]['children'][$k3]['children'][$k4]['children'][$k5]['name'] = $m6['value'];
|
|
|
- }
|
|
|
-
|
|
|
- $i6 = $this->invite($v5['to_uid']);
|
|
|
- if($i6){
|
|
|
- foreach($i6 as $k6 => $v6){
|
|
|
- $m7 = $this->button($v6['to_uid']);
|
|
|
- if($v6['to_uid'] == $uid){
|
|
|
- $info['children'][$k]['children'][$k1]['children'][$k2]['children'][$k3]['children'][$k4]['children'][$k5]['children'][$k6]['name'] = $m7['value'];
|
|
|
- $info['children'][$k]['children'][$k1]['children'][$k2]['children'][$k3]['children'][$k4]['children'][$k5]['children'][$k6]['itemStyle']['color'] = 'blue';
|
|
|
- }else{
|
|
|
- $info['children'][$k]['children'][$k1]['children'][$k2]['children'][$k3]['children'][$k4]['children'][$k5]['children'][$k6]['name'] = $m7['value'];
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }else{}
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }else{}
|
|
|
- }
|
|
|
- }
|
|
|
+ if ($v['level_id'] && $v['level_id'] > 0) {
|
|
|
+ $level = Dever::db('setting/level')->find($v['level_id']);
|
|
|
+ if ($level) {
|
|
|
+ $data[$i]['value'] .= '<br />等级:' . $level['name'];
|
|
|
}
|
|
|
- }else{}
|
|
|
- }
|
|
|
- }else{}
|
|
|
-
|
|
|
-
|
|
|
- exit(Dever::json_encode($info));
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public function invite($mid){
|
|
|
- $invite = Dever::load('invite/api')->getChild($mid,$level_id = 1, false);
|
|
|
-
|
|
|
- return $invite;
|
|
|
- }
|
|
|
-
|
|
|
- public function button($mid, $cur = false, $color = 2){
|
|
|
- $child = Dever::db('agent/member')->find($mid);
|
|
|
- $role = Dever::db('setting/role')->find($child['role']);
|
|
|
- $result = array();
|
|
|
- $result['mid'] = $mid;
|
|
|
- $result['name'] = $child['name'];
|
|
|
- $result['value'] = $child['name']."\r\n".$child['mobile']."\r\n".$role['name'];
|
|
|
- if (isset($child['level_id']) && $child['level_id'] && $child['level_id'] > 0) {
|
|
|
- $level = Dever::db('setting/level')->find($child['level_id']);
|
|
|
- $result['value'].= '('.$level['name'].')';
|
|
|
- }
|
|
|
- if(isset($child['source_id']) && $child['source_id'] && $child['source_id']>0){
|
|
|
- $source=Dever::db('setting/source')->one(array('id'=>$child['source_id'],'state'=>1));
|
|
|
- if($source){
|
|
|
- $result['value'] .= "\r\n".$source['name'];
|
|
|
- }
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
- if ($cur && $mid == $cur) {
|
|
|
- if ($color == 1) {
|
|
|
- $result['itemStyle']['color'] = 'green';
|
|
|
- } else {
|
|
|
- $result['itemStyle']['color'] = 'blue';
|
|
|
+ if ($cur == $uid) {
|
|
|
+ $data[$i]['itemStyle']['color'] = $this->child_color;
|
|
|
+ }
|
|
|
+ if ($cur == $v['id']) {
|
|
|
+ $data[$i]['itemStyle']['color'] = $this->cur_color;
|
|
|
+ $next = true;
|
|
|
+ $state = 2;
|
|
|
+ } elseif ($parents && in_array($v['id'], $parents)) {
|
|
|
+ $data[$i]['itemStyle']['color'] = $this->parent_color;
|
|
|
+ $next = false;
|
|
|
+ $this->getChild($data, $i, $v['id'], $parents, $cur, $state, $next);
|
|
|
+ } elseif ($state == 1) {
|
|
|
+ $next = false;
|
|
|
+ } else {
|
|
|
+ $next = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($next) {
|
|
|
+ $this->getChild($data, $i, $v['id'], $parents, $cur, $state, $next);
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
- return $result;
|
|
|
}
|
|
|
-
|
|
|
}
|