|
|
|
@ -161,26 +161,16 @@ class Agent extends Commission |
|
|
|
|
//好友总数 |
|
|
|
|
$son_total = 0; |
|
|
|
|
$user_id = $user->id; |
|
|
|
|
|
|
|
|
|
$son_total = UserModel::where('parent_user_id', $user_id)->count('id'); |
|
|
|
|
|
|
|
|
|
$team_total = UserModel::with(['parentUser' => function($query) use ($user_id) { |
|
|
|
|
// $query->where(''); |
|
|
|
|
}])->where('parent_user_id', $user_id)->count('id'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$list = UserModel::with('agent.levelInfo')->where('id', $user_id)->select(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$list = UserModel::with('agent.levelInfo')->where('parent_user_id', $user_id)->select(); |
|
|
|
|
|
|
|
|
|
$result = [ |
|
|
|
|
'team_total' => $team_total, |
|
|
|
|
'son_total' => $son_total ?? 0, |
|
|
|
|
'team_total' => $this->runNextUserCount($this->getParent($user_id)), |
|
|
|
|
'son_total' => $son_total, |
|
|
|
|
'list' => $list |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
foreach ($list as &$item) { |
|
|
|
|
$item['nextUserCount'] = 0; |
|
|
|
|
$item['nextUserCount'] = $this->runNextUserCount($this->getParent($item['id'])); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$this->success('success', $result); |
|
|
|
@ -188,7 +178,8 @@ class Agent extends Commission |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function test() { |
|
|
|
|
$result = $this->runNextUser( $this->getTestData(1)); |
|
|
|
|
$son = $this->getTestData(1); |
|
|
|
|
$result = $this->runNextUser($son); |
|
|
|
|
$this->success('success', $result); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -203,10 +194,10 @@ class Agent extends Commission |
|
|
|
|
['id' => 2, 'pid' => 1], |
|
|
|
|
['id' => 3, 'pid' => 1], |
|
|
|
|
['id' => 4, 'pid' => 2], |
|
|
|
|
['id' => 5, 'pid' => 4], |
|
|
|
|
['id' => 6, 'pid' => 5], |
|
|
|
|
['id' => 5, 'pid' => 3], |
|
|
|
|
['id' => 6, 'pid' => 1], |
|
|
|
|
['id' => 7, 'pid' => 6], |
|
|
|
|
['id' => 8, 'pid' => 2], |
|
|
|
|
['id' => 8, 'pid' => 1], |
|
|
|
|
['id' => 9, 'pid' => 2], |
|
|
|
|
['id' => 10, 'pid' => 7], |
|
|
|
|
['id' => 11, 'pid' => 3], |
|
|
|
@ -224,25 +215,67 @@ class Agent extends Commission |
|
|
|
|
/** |
|
|
|
|
* 递归处理用户的下级人数 |
|
|
|
|
* @param $list |
|
|
|
|
* @param $pid |
|
|
|
|
* @param int $pid |
|
|
|
|
* @return mixed |
|
|
|
|
*/ |
|
|
|
|
public function runNextUser($user) { |
|
|
|
|
static $data = []; |
|
|
|
|
$nextUser = $user; |
|
|
|
|
// return $nextUser; |
|
|
|
|
// $nextUserCount = count($this->getTestData($user_id)); |
|
|
|
|
public function runNextUserCount($user) { |
|
|
|
|
$count = 0; |
|
|
|
|
if (count($user) > 0) { |
|
|
|
|
$count += count($user); |
|
|
|
|
} |
|
|
|
|
foreach ($user as $item) { |
|
|
|
|
$nexUserData = $this->getParent($item['id']); |
|
|
|
|
if (is_array($nexUserData)) { |
|
|
|
|
$this->runNextUser($nexUserData); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return $count; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
foreach ($nextUser as $k => $v) { |
|
|
|
|
// if($v['pid'] == $user_id) { |
|
|
|
|
// $data[] = $v; |
|
|
|
|
$v['son'] = $this->runNextUser($v['id']); |
|
|
|
|
!empty($son)&& $v['son'] = $this->runNextUser($v['id']); |
|
|
|
|
$data[] = $v; |
|
|
|
|
unset($nextUser[$k]); |
|
|
|
|
// } |
|
|
|
|
/** |
|
|
|
|
* @param $user |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
public function runNextUser($user) { |
|
|
|
|
$count = 0; |
|
|
|
|
$data = []; |
|
|
|
|
if (count($user) > 0) { |
|
|
|
|
$count += count($user); |
|
|
|
|
} |
|
|
|
|
foreach ($user as $item) { |
|
|
|
|
$nexUserData = $this->getParent($item['id']); |
|
|
|
|
if (is_array($nexUserData)) { |
|
|
|
|
$item['son'] = $this->runNextUser($nexUserData); |
|
|
|
|
} |
|
|
|
|
$data[] = $item; |
|
|
|
|
} |
|
|
|
|
return ['list'=> $data, 'count'=> $count]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function getTree($data, $pId) |
|
|
|
|
{ |
|
|
|
|
$tree = []; |
|
|
|
|
foreach($data as $v) |
|
|
|
|
{ |
|
|
|
|
if(strcmp($v['condition'], $pId) == 0) |
|
|
|
|
{ |
|
|
|
|
$v['children'] = $this->getTree($data, $v['task_id']); |
|
|
|
|
$tree[] = $v; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return $tree; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function format($tree,$parent = [],$data = []) |
|
|
|
|
{ |
|
|
|
|
foreach ($tree as $v) { |
|
|
|
|
$tmp = $parent; |
|
|
|
|
$tmp[] = $v['task_id']; |
|
|
|
|
if (empty($v['children'])) { |
|
|
|
|
$data[] = $tmp; |
|
|
|
|
} else { |
|
|
|
|
$data = $this->format($v['children'],$tmp,$data); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return $data; |
|
|
|
|
} |
|
|
|
|