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