Your Name há 3 anos atrás
pai
commit
695699545c
2 ficheiros alterados com 97 adições e 40 exclusões
  1. 1 1
      service/agent/database/member.php
  2. 96 39
      service/agent/src/Children.php

+ 1 - 1
service/agent/database/member.php

@@ -147,7 +147,7 @@ return array
             'match'     => 'is_string',
             'update'    => 'text',
             'search'    => ($parent_mid) ? 'hidden' : 'fulltext',
-            'list'      => 'Dever::load("agent/lib/order.new_set", {id})',
+            'list'      => 'Dever::load("agent/lib/member.getOne", {id}, "agent/member", true)',
         ),
 
         'rdate'     => array

+ 96 - 39
service/agent/src/Children.php

@@ -7,38 +7,81 @@ use Dever;
 class Children
 {
 	public function text(){
-		echo "<font style='color: yellow'>12312323</font>";
+		$cur = Dever::input('mid');
+		// $result = $this->index($cur);
+		$invite = Dever::load('invite/api')->getChild($cur);
+		// print_R($invite);die;
+		$result = array();
+		$data = array();
+		$index = array();
+		$count = count($invite) - 1;
+		$i=0;
+		foreach($invite as $k => $v) {
+				
+			}
+		print_R($result);die;
+		
 	}
 	#uid 邀请人 to_uid=mid 被邀请人(要查的人) level 等级
 	#invite/relation
-	public function home($mid){
-		$invite = Dever::load('invite/api')->getParentAll($mid);
+	public function home(){
+		$cur = Dever::input('mid');
+		$invite = Dever::load('invite/api')->getParentAll($cur, 5);
+		// print_R($invite);die;
+		$result = array();
+		$data = array();
 		if($invite){
-			foreach($invite as $k => $v){
-				if($v['level'] == 5){
-					$info = $this->index($v['uid']); 
-				}else{
-					if($v['level'] == 4){
-						$info = $this->index($v['uid']);
-					}else{
-						if($v['level'] == 3){
-							$info = $this->index($v['uid']);
-						}else{
-							if($v['level'] == 2){
-								$info = $this->index($v['uid']);
-							}else{
-								if($v['level'] == 1){
-									$info = $this->index($v['uid']);
-								}
-							}
-						}
-					}
+			$index = array();
+			$count = count($invite) - 1;
+			foreach($invite as $k => $v) {
+				// print_R($v['uid']);die;
+				$uid = $v['uid'];
+				$v = $this->button($v['uid'], $v['uid']);
+				if ($count == $k) {
+					//$v['children'] = array($this->button($cur, $cur, 1)) + $this->child($uid, $cur);
+				}
+				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);
+
 				}
 			}
-		}else{
-			$info = $this->index($mid);
+			
 		}
-		exit(Dever::json_encode($info));
+		exit(Dever::json_encode($result));
+	}
+	public function child($parent, $cur = false) {
+		$result = array();
+		$index = 0;
+		$child = Dever::load('invite/api')->getChild($parent, 1, false);
+		// print_R($child);die;
+		$num = count($child) / 2;
+		foreach ($child as $k => $v) {
+			$result[] = $this->button($v['to_uid'], $cur);
+			if ($v['to_uid'] == $cur) {
+				$index = $k;
+			}
+		}
+		if ($cur) {
+			$old = $result;
+			$result[$index] = $result[$num];
+			$result[$num] = $old[$index];
+			$index = $num;
+		}
+		
+ 		return array($result, $index);
 	}
 	#查询所有下级
 	public function index($mid){
@@ -46,17 +89,18 @@ class Children
 		
 		#自己的所有直属下级
 		$invite = $this->invite($mid);
+		// print_R($invite);die;
 		if($invite){
 			foreach($invite as $k =>$v){
 				$member = $this->button($mid);
-				if($mid == $uid){
-					$info['name'] = $member['value'];
-					$info['itemStyle']['color'] = 'blue';
-					// $info['tooltip']['valueFormatter']= $member['value'];
+				// if($mid == $uid){
+				// 	$info['name'] = $member['value'];
+				// 	$info['itemStyle']['color'] = 'blue';
+				// 	// $info['tooltip']['valueFormatter']= $member['value'];
 
-				}else{
-					$info['name'] = $member['value'];
-				}
+				// }else{
+				// 	$info['name'] = $member['value'];
+				// }
 				
 				$m1 = $this->button($v['to_uid']);
 				if($v['to_uid']==$uid){
@@ -129,7 +173,7 @@ class Children
 											$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'];
+											$info['children'][$k]['children'][$k1]['children'][$k2]['children'][$k3]['children'][$k4]['children'][$k5]['children'][$k6]['name'] = $m7['value'];
 										}
 								
 								// $i7 = $this->invite($v6['to_uid']);
@@ -188,31 +232,44 @@ class Children
 		// print_R($info);die;
 		// return Dever::render('index', $info);
 		exit(Dever::json_encode($info));
+		// return $info;
 	}
 	
 	#获取所有直属下级
 	public function invite($mid){
-		$invite = Dever::load('invite/api')->getChild($mid,$level_id = 1);
+		$invite = Dever::load('invite/api')->getChild($mid,$level_id = 1, false);
 		// print_R($invite);die;
 		return $invite;
 	}
 	#非顶级
-	public function button($mid){
+	public function button($mid, $cur = false, $color = 2){
 		$child = Dever::db('agent/member')->find($mid);
 		$role = Dever::db('setting/role')->find($child['role']);
-		$child['value'] = $child['name']."\r\n".$child['mobile']."\r\n".$role['name'];
+		$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']);
-			$child['value'].= '('.$level['name'].')';
+			$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){
-                $child['value'] .= "\r\n".$source['name'];
+                $result['value'] .= "\r\n".$source['name'];
             }
 		}
+
+		if ($cur && $mid == $cur) {
+			if ($color == 1) {
+				$result['itemStyle']['color'] = 'green';
+			} else {
+				$result['itemStyle']['color'] = 'blue';
+			}
+			
+		}
 		
-		return $child;
+		return $result;
 	}
 	
 }