rabin vor 3 Jahren
Ursprung
Commit
d5b3477a01
2 geänderte Dateien mit 70 neuen und 213 gelöschten Zeilen
  1. 20 6
      service/agent/lib/Import.php
  2. 50 207
      service/agent/src/Children.php

+ 20 - 6
service/agent/lib/Import.php

@@ -332,6 +332,14 @@ class Import
         if ($data) {
             foreach ($data as $k => $v) {
                 $update = array();
+
+                # 获取直推代理人数
+                $num = Dever::load('invite/api')->getChildNum($v['id'], 1);
+                if ($num != $v['old_agentdownnum']) {
+                    # 记录日志
+                    $this->log($v['id'], 2, $v['old_agentdownnum'], $num);
+                }
+
                 # 获取直推业绩
                 $sell = Dever::db('bill/sell')->getNumByTimeOne(array('mid' => $v['id'], 'type' => 1, 'stype' => 3));
                 if ($sell && $sell['num']) {
@@ -345,13 +353,19 @@ class Import
                         # 记录日志
                         $this->log($v['id'], 3, $v['old_group_sell'], $update['group_sell']);
                     }
+
+                    if ($v['level_id'] > 0) {
+                        $cur_level = Dever::db('setting/level')->find($v['level_id']);
+                    } else {
+                        $cur_level = array('id' => -1, 'name' => '普通', 'level' => 0, 'num' => 1, 'value' => '0');
+                    }
+                    $level = Dever::db('setting/level')->getOne(array('target' => ($update['group_sell']/10000)));
+                    if ($level && $level['level'] > $cur_level['level']) {
+                        $update['level_id'] = $level['id'];
+                        Dever::load('agent/lib/level_log')->up($v['id'], -1, $cur_level['id'], $level['id'], $update['group_sell'], $update['group_sell'], $num);
+                    }
                 }
-                # 获取直推代理人数
-                $num = Dever::load('invite/api')->getChildNum($v['id'], 1);
-                if ($num != $v['old_agentdownnum']) {
-                    # 记录日志
-                    $this->log($v['id'], 2, $v['old_agentdownnum'], $num);
-                }
+
                 if ($update) {
                     $update['where_id'] = $v['id'];
                     Dever::db('agent/member')->update($update);

+ 50 - 207
service/agent/src/Children.php

@@ -6,70 +6,70 @@ use Dever;
 
 class Children
 {
-	public function text(){
+	public function home()
+	{
 		$cur = Dever::input('mid');
-		// $result = $this->index($cur);
-		$invite = Dever::load('invite/api')->getChild($cur);
-		// print_R($invite);die;
+		$parent = Dever::load('invite/api')->getParentAll($cur, 5);
 		$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(){
-		$cur = Dever::input('mid');
-		$invite = Dever::load('invite/api')->getParentAll($cur, 5);
-		// print_R($invite);die;
-		$result = array();
-		$data = array();
-		if($invite){
+		if($parent){
 			$index = array();
-			$count = count($invite) - 1;
-			foreach($invite as $k => $v) {
-				// print_R($v['uid']);die;
+			$count = count($parent) - 1;
+			foreach($parent as $k => $v) {
 				$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);
-
-				}
+				$this->handle($result, $index, $k, $uid, $parent, $cur);
 			}
-			
 		}
+		$this->handle($result, $index, $k+1, $cur, $parent, false);
 		exit(Dever::json_encode($result));
 	}
-	public function child($parent, $cur = false) {
+
+	public function handle(&$result, &$index, $k, $uid, $parent, $cur)
+	{
+		if (isset($parent[$k+1]['uid']) && $parent[$k+1]['uid']) {
+			$cur = $parent[$k+1]['uid'];
+			$color = 2;
+		} else {
+			$color = 1;
+		}
+		list($data, $index[$k]) = $this->child($uid, $cur, $color);
+
+		# 这里后续优化吧
+		if ($k == 0) {
+			$result['children'] = $data;
+		} elseif ($k == 1) {
+			$result['children'][$index[$k-1]]['children'] = $data;
+		} elseif ($k == 2) {
+			$result['children'][$index[$k-2]]['children'][$index[$k-1]]['children'] = $data;
+		} elseif ($k == 3) {
+			$result['children'][$index[$k-3]]['children'][$index[$k-2]]['children'][$index[$k-1]]['children'] = $data;
+		} elseif ($k == 4) {
+			$result['children'][$index[$k-4]]['children'][$index[$k-3]]['children'][$index[$k-2]]['children'][$index[$k-1]]['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;
+		} 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;
+		} 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;
+		} 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;
+		} 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;
+		}
+	}
+
+	public function child($parent, $cur = false, $color = 2)
+	{
 		$result = array();
 		$index = 0;
 		$child = Dever::load('invite/api')->getChild($parent, 1, false);
-		// print_R($child);die;
-		$num = count($child) / 2;
+		$num = intval(count($child) / 2);
 		foreach ($child as $k => $v) {
-			$result[] = $this->button($v['to_uid'], $cur);
+			$result[] = $this->button($v['to_uid'], $cur, $color);
 			if ($v['to_uid'] == $cur) {
 				$index = $k;
 			}
@@ -83,166 +83,10 @@ class Children
 		
  		return array($result, $index);
 	}
-	#查询所有下级
-	public function index($mid){
-		$uid = Dever::input('mid',$mid);
-		
-		#自己的所有直属下级
-		$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'];
-
-				// }else{
-				// 	$info['name'] = $member['value'];
-				// }
-				
-				$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'];
-				}
-				
-				$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'];
-										}
-								
-								// $i7 = $this->invite($v6['to_uid']);
-								// if($i7){
-								// 	foreach($i7 as $k7 => $v7){
-								// 		$m8 = $this->button($v7['to_uid']);
-								// 		if($v7['to_uid'] == $uid){
-								// 			$info['children'][$k]['children'][$k1]['children'][$k2]['children'][$k3]['children'][$k4]['children'][$k5]['children'][$k6]['children'][$k7]['name'] = $m8['value'];
-								// 			$info['children'][$k]['children'][$k1]['children'][$k2]['children'][$k3]['children'][$k4]['children'][$k5]['children'][$k6]['children'][$k7]['itemStyle']['color'] = 'blue';
-								// 		}else{
-								// 			$info['children'][$k]['children'][$k1]['children'][$k2]['children'][$k3]['children'][$k4]['children'][$k5]['children'][$k6]['children'][$k7]['name'] = $m8['value'];
-								// 		}
-								
-								// $i8 = $this->invite($v7['to_uid']);
-								// if($i8){
-								// 	foreach($i8 as $k8 => $v8){
-								// 		$m9 = $this->button($v8['to_uid']);
-								// 		if($v8['to_uid'] == $uid){
-								// 			$info['children'][$k]['children'][$k1]['children'][$k2]['children'][$k3]['children'][$k4]['children'][$k5]['children'][$k6]['children'][$k7]['children'][$k8]['name'] = $m9['value'];
-								// 			$info['children'][$k]['children'][$k1]['children'][$k2]['children'][$k3]['children'][$k4]['children'][$k5]['children'][$k6]['children'][$k7]['children'][$k8]['name']['itemStyle']['color'] = 'blue';
-								// 		}else{
-								// 			$info['children'][$k]['children'][$k1]['children'][$k2]['children'][$k3]['children'][$k4]['children'][$k5]['children'][$k6]['children'][$k7]['children'][$k8]['name'] = $m9['value'];
-								// 		}
-								
-								// $i9 = $this->invite($v8['to_uid']);
-								// if($i9){
-								// 	foreach($i9 as $k9 => $v9){
-								// 		$m10 = $this->button($v9['to_uid']);
-								// 		if($v9['to_uid'] == $uid){
-								// 			$info['children'][$k]['children'][$k1]['children'][$k2]['children'][$k3]['children'][$k4]['children'][$k5]['children'][$k6]['children'][$k7]['children'][$k8]['children'][$k9]['name'] = $m10['value'];
-								// 			$info['children'][$k]['children'][$k1]['children'][$k2]['children'][$k3]['children'][$k4]['children'][$k5]['children'][$k6]['children'][$k7]['children'][$k8]['children'][$k9]['itemStyle']['color'] = 'blue';
-								// 		}else{
-								// 			$info['children'][$k]['children'][$k1]['children'][$k2]['children'][$k3]['children'][$k4]['children'][$k5]['children'][$k6]['children'][$k7]['children'][$k8]['children'][$k9]['name'] = $m10['value'];
-								// 		}
-								
-								// 													}
-								// 												}else{}
-								// 											}
-								// 										}
-								// 									}
-								// 								}else{}
-															}
-														}
-													}
-												}else{}
-											}
-										}
-									}
-								}else{}
-							}
-						}
-					}
-				}else{}
-			}
-		}else{}
-		// 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, false);
-		// print_R($invite);die;
-		return $invite;
-	}
-	#非顶级
-	public function button($mid, $cur = false, $color = 2){
+	# 获取当前信息
+	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();
@@ -266,7 +110,6 @@ class Children
 			} else {
 				$result['itemStyle']['color'] = 'blue';
 			}
-			
 		}
 		
 		return $result;