|
@@ -321,60 +321,70 @@ class MemberService extends BaseService
|
|
|
public function getPointParentId($userId)
|
|
public function getPointParentId($userId)
|
|
|
{
|
|
{
|
|
|
if($userId<=0){
|
|
if($userId<=0){
|
|
|
- return 0;
|
|
|
|
|
|
|
+ return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 上级
|
|
// 上级
|
|
|
- $parentId = $this->model->where(['id'=>$userId])->value('parent_id');
|
|
|
|
|
|
|
+ $userInfo = $this->model->where(['id'=>$userId])->select(['id','parent_id','point_sort','point_id'])->first();
|
|
|
|
|
+ $parentId = isset($userInfo['parent_id'])?$userInfo['parent_id']:0;
|
|
|
|
|
+ $pointSort = isset($userInfo['point_sort'])&&$userInfo['point_sort']?$userInfo['point_sort']:1;
|
|
|
|
|
+ $model = $this->model->where(['mark'=> 1]);
|
|
|
|
|
+
|
|
|
|
|
+ $model1= clone $model;
|
|
|
|
|
+ // 自己节点人数
|
|
|
|
|
+ $childrenCount = $model1->where(function($query) use($userId){
|
|
|
|
|
+ $query->where('point_id', $userId);
|
|
|
|
|
+ })->count('id');
|
|
|
|
|
|
|
|
// 自己团队和平级用户
|
|
// 自己团队和平级用户
|
|
|
- $userList = $this->model->where(['mark'=> 1])
|
|
|
|
|
- ->whereNotIn('id',[$userId])
|
|
|
|
|
|
|
+ $userList = $model->whereNotIn('id',[$userId])
|
|
|
->where(function($query) use($userId,$parentId){
|
|
->where(function($query) use($userId,$parentId){
|
|
|
$query->whereRaw('FIND_IN_SET(?,points)', $userId);
|
|
$query->whereRaw('FIND_IN_SET(?,points)', $userId);
|
|
|
|
|
|
|
|
// 节点平级用户
|
|
// 节点平级用户
|
|
|
if($parentId>0){
|
|
if($parentId>0){
|
|
|
- $query->orWhereRaw('point_id', $parentId);
|
|
|
|
|
|
|
+ $query->orWhere('point_id', $parentId);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
})
|
|
})
|
|
|
->select(['id','point_id','point_sort','points'])
|
|
->select(['id','point_id','point_sort','points'])
|
|
|
|
|
+ ->withCount(['points'])
|
|
|
->orderBy('point_sort','asc')
|
|
->orderBy('point_sort','asc')
|
|
|
->orderBy('id','asc')
|
|
->orderBy('id','asc')
|
|
|
->get();
|
|
->get();
|
|
|
$userList = $userList? $userList->toArray() : [];
|
|
$userList = $userList? $userList->toArray() : [];
|
|
|
- if(count($userList) < 2){
|
|
|
|
|
- return $userId;
|
|
|
|
|
|
|
+ if($childrenCount < 2){
|
|
|
|
|
+ return ['point_id'=>$userId,'point_sort'=>($pointSort*$pointSort+($childrenCount+1)),'index'=>$childrenCount+1];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $users = [];
|
|
|
|
|
- foreach($userList as $item){
|
|
|
|
|
- $points = isset($item['points']) && $item['points']? explode(',', $item['points']) : [];
|
|
|
|
|
- $points = array_filter($points);
|
|
|
|
|
- $users[$item['id']]['pointLen'] = count($points);
|
|
|
|
|
- $users[$item['id']]['children'] = isset($users[$item['id']]['children'])? $users[$item['id']]['children'] : 0;
|
|
|
|
|
- $users[$item['point_id']]['children'] = isset($users[$item['point_id']]['children'])? $users[$item['point_id']]['children'] + 1 : 1;
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
|
|
+// dump($childrenCount);
|
|
|
|
|
+// dump($userList);
|
|
|
$pointId = 0;
|
|
$pointId = 0;
|
|
|
$tempPointLen = 0;
|
|
$tempPointLen = 0;
|
|
|
$tempChildren = 0;
|
|
$tempChildren = 0;
|
|
|
|
|
+ $pointSort = 0;
|
|
|
foreach ($userList as $item) {
|
|
foreach ($userList as $item) {
|
|
|
$id = isset($item['id'])? $item['id'] : 0;
|
|
$id = isset($item['id'])? $item['id'] : 0;
|
|
|
- $children = isset($users[$id]['children'])? $users[$id]['children'] : 0;
|
|
|
|
|
- $pointLen = isset($users[$id]['pointLen'])? $users[$id]['pointLen'] : 0;
|
|
|
|
|
- //dump("ID:{$id}-{$pointId}-{$tempChildren}-{$children}-{$pointLen}");
|
|
|
|
|
|
|
+ $sort = isset($item['point_sort']) && $item['point_sort']? $item['point_sort'] : 1;
|
|
|
|
|
+ $children = isset($item['points_count']) && $item['points_count']? $item['points_count'] : 0;
|
|
|
|
|
+
|
|
|
|
|
+ $points = isset($item['points']) && $item['points']? explode(',', $item['points']) : [];
|
|
|
|
|
+ $points = array_filter($points);
|
|
|
|
|
+ $pointLen = count($points);
|
|
|
|
|
+
|
|
|
|
|
+ //dump("ID:{$id}-{$pointId}-{$tempChildren}-{$children}-{$pointLen}-{$sort}");
|
|
|
if($pointLen<=$tempPointLen || $pointId == 0){
|
|
if($pointLen<=$tempPointLen || $pointId == 0){
|
|
|
if($children < 2 && $pointId <= 0){
|
|
if($children < 2 && $pointId <= 0){
|
|
|
$pointId = $id;
|
|
$pointId = $id;
|
|
|
$tempPointLen = $pointLen;
|
|
$tempPointLen = $pointLen;
|
|
|
$tempChildren = $children+1;
|
|
$tempChildren = $children+1;
|
|
|
|
|
+ $pointSort = $sort*$sort + $tempChildren;
|
|
|
|
|
+ //dump("ID:{$id}-{$children}命中");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return ['point_id'=>$pointId,'point_sort'=>$tempChildren];
|
|
|
|
|
|
|
+ return ['point_id'=>$pointId,'point_sort'=>$pointSort,'index'=>$tempChildren];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|