|
|
|
@ -2,6 +2,7 @@ |
|
|
|
|
|
|
|
|
|
namespace addons\shopro\controller\commission; |
|
|
|
|
|
|
|
|
|
use addons\shopro\controller\Pay; |
|
|
|
|
use think\Db; |
|
|
|
|
use app\admin\model\shopro\user\User as UserModel; |
|
|
|
|
use app\admin\model\shopro\commission\Agent as AgentModel; |
|
|
|
@ -148,4 +149,125 @@ class Agent extends Commission |
|
|
|
|
}); |
|
|
|
|
$this->success(''); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 我的团队 |
|
|
|
|
*/ |
|
|
|
|
public function myTeam() { |
|
|
|
|
$user = auth_user(); |
|
|
|
|
$list = []; |
|
|
|
|
//团队总数 |
|
|
|
|
$team_total = 0; |
|
|
|
|
//好友总数 |
|
|
|
|
$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(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$result = [ |
|
|
|
|
'team_total' => $team_total, |
|
|
|
|
'son_total' => $son_total ?? 0, |
|
|
|
|
'list' => $list |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
foreach ($list as &$item) { |
|
|
|
|
$item['nextUserCount'] = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$this->success('success', $result); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function test() { |
|
|
|
|
$result = $this->runNextUser( $this->getTestData(1)); |
|
|
|
|
$this->success('success', $result); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 测试数据 |
|
|
|
|
*/ |
|
|
|
|
public function getTestData($id) { |
|
|
|
|
$data = [ |
|
|
|
|
['id' => 1, 'pid' => 0], |
|
|
|
|
['id' => 2, 'pid' => 1], |
|
|
|
|
['id' => 3, 'pid' => 1], |
|
|
|
|
['id' => 4, 'pid' => 2], |
|
|
|
|
['id' => 5, 'pid' => 4], |
|
|
|
|
['id' => 6, 'pid' => 5], |
|
|
|
|
['id' => 7, 'pid' => 6], |
|
|
|
|
['id' => 8, 'pid' => 2], |
|
|
|
|
['id' => 9, 'pid' => 2], |
|
|
|
|
['id' => 10, 'pid' => 7], |
|
|
|
|
['id' => 11, 'pid' => 3], |
|
|
|
|
]; |
|
|
|
|
$data = array_column($data, null, 'id'); |
|
|
|
|
$new_data = []; |
|
|
|
|
foreach ($data as $key => $val) { |
|
|
|
|
if ($id == $val['pid']) { |
|
|
|
|
$new_data[] = $val; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return $new_data; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 递归处理用户的下级人数 |
|
|
|
|
* @param $list |
|
|
|
|
* @param $pid |
|
|
|
|
* @return mixed |
|
|
|
|
*/ |
|
|
|
|
public function runNextUser($user) { |
|
|
|
|
static $data = []; |
|
|
|
|
$nextUser = $user; |
|
|
|
|
// return $nextUser; |
|
|
|
|
// $nextUserCount = count($this->getTestData($user_id)); |
|
|
|
|
|
|
|
|
|
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]); |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
return $data; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function getParent($pid) { |
|
|
|
|
return UserModel::where('parent_user_id', $pid)->select(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 返回树形结构 |
|
|
|
|
* @param $list |
|
|
|
|
* @param $pid |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
public function getTreeData($list, $pid = 0) { |
|
|
|
|
static $data = []; |
|
|
|
|
foreach ($list as $key => $item) { |
|
|
|
|
if ($item['user_id'] == $pid) { |
|
|
|
|
$children = $this->getTreeData($item, $item['user_id']); |
|
|
|
|
!empty($children) && $item['children'] = $children; |
|
|
|
|
$data[] = $item; |
|
|
|
|
unset($list[$key]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return $data; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|