|
|
@@ -214,97 +214,68 @@ class StoreOrderSuccessServices extends BaseServices
|
|
|
]);
|
|
|
|
|
|
if ($hasSubordinate) {
|
|
|
- // 直推上级已有下级,获取所有下级
|
|
|
- $allSubordinates = $giftGroupService->getList([
|
|
|
+ // 直推上级已有下级,需要判断是否需要滑落
|
|
|
+ // 小组定义:一个商品 + 一个 fake_id 形成一个小组
|
|
|
+ // 37的直推下级首先加入 fake_id=37 的小组
|
|
|
+
|
|
|
+ // 查找 fake_id=37 的小组(商品ID=6, fake_pid=spread_uid的所有人)
|
|
|
+ $spreadFakeIdGroup = $giftGroupService->getList([
|
|
|
'product_id' => $product_id,
|
|
|
- 'pid' => $spread_uid
|
|
|
+ 'fake_pid' => $spread_uid
|
|
|
], '*', 0, 0, 'create_time ASC');
|
|
|
|
|
|
- // 获取最后一个下级的group_pid来判断小组是否满人
|
|
|
- $lastMember = $allSubordinates[count($allSubordinates) - 1];
|
|
|
- $lastGroupPid = $lastMember['group_pid'];
|
|
|
-
|
|
|
- // 统计小组人数:从最后一个成员开始,沿group_pid向上追溯到根节点
|
|
|
- // 然后统计所有pid=spread_uid且group_pid在链条上的成员
|
|
|
- $groupChain = [];
|
|
|
- $currentGroupPid = $lastGroupPid;
|
|
|
-
|
|
|
- // 追溯group_pid链条
|
|
|
- while ($currentGroupPid > 0) {
|
|
|
- $groupChain[] = $currentGroupPid;
|
|
|
- @file_put_contents('quanju4.txt', $currentGroupPid . "-group_pid链条节点\r\n", 8);
|
|
|
- // 查找这个group_pid对应的成员
|
|
|
- $chainMember = $giftGroupService->getOne([
|
|
|
- 'product_id' => $product_id,
|
|
|
- 'uid' => $currentGroupPid
|
|
|
- ]);
|
|
|
- if ($chainMember) {
|
|
|
- $currentGroupPid = $chainMember['group_pid'];
|
|
|
- @file_put_contents('quanju4.txt', $chainMember['group_pid'] . "-下一节点group_pid\r\n", 8);
|
|
|
+ @file_put_contents('quanju4.txt', count($spreadFakeIdGroup) . "-fake_id=" . $spread_uid . "的小组人数\r\n", 8);
|
|
|
+
|
|
|
+ // 判断该小组是否满人
|
|
|
+ if (count($spreadFakeIdGroup) < $groupMaxNum) {
|
|
|
+ // 小组未满,新成员加入该小组
|
|
|
+ if (count($spreadFakeIdGroup) > 0) {
|
|
|
+ // 该小组已有成员,新成员的group_pid是该小组的最后一人
|
|
|
+ $lastMember = end($spreadFakeIdGroup);
|
|
|
+ $data['group_pid'] = $lastMember['uid'];
|
|
|
+ $data['fake_pid'] = $spread_uid;
|
|
|
+ @file_put_contents('quanju4.txt', $lastMember['uid'] . "-小组最后一人,新成员group_pid\r\n", 8);
|
|
|
} else {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 统计小组人数:pid=spread_uid 且 group_pid 在链条中或为0
|
|
|
- $groupCount = 0;
|
|
|
- foreach ($allSubordinates as $sub) {
|
|
|
- if (in_array($sub['group_pid'], $groupChain) || $sub['group_pid'] == 0) {
|
|
|
- $groupCount++;
|
|
|
+ // 该小组没有成员,新成员成为第一人
|
|
|
+ $data['group_pid'] = 0;
|
|
|
+ $data['fake_pid'] = $spread_uid;
|
|
|
+ @file_put_contents('quanju4.txt', 'fake_id小组没有成员,新成员成为第一人\r\n', 8);
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- $isGroupFull = $groupCount >= $groupMaxNum;
|
|
|
-
|
|
|
- @file_put_contents('quanju4.txt', $groupCount . "-小组人数\r\n", 8);
|
|
|
- @file_put_contents('quanju4.txt', $groupMaxNum . "-系统设置人数\r\n", 8);
|
|
|
- @file_put_contents('quanju4.txt', $lastGroupPid . "-最后一个人的group_pid\r\n", 8);
|
|
|
- @file_put_contents('quanju4.txt', json_encode($groupChain) . "-group_pid链条\r\n", 8);
|
|
|
- @file_put_contents('quanju4.txt', ($isGroupFull ? '小组已满' : '小组未满') . "-小组状态\r\n", 8);
|
|
|
- @file_put_contents('quanju4.txt', end($groupChain) . "-小组最后一人uid(end groupChain)\r\n", 8);
|
|
|
-
|
|
|
- // 判断小组是否满人
|
|
|
- if ($isGroupFull) {
|
|
|
- // 小组满人,需要滑落到小组最后一人的直推下级小组
|
|
|
- // 小组最后一人应该是按create_time排序的最后一人,而不是group_pid链条的最后一人
|
|
|
- $lastGroupMemberUid = end($allSubordinates)['uid'];
|
|
|
-
|
|
|
- @file_put_contents('quanju4.txt', $lastGroupMemberUid . "-小组最后一人的uid(按create_time排序)\r\n", 8);
|
|
|
+ } else {
|
|
|
+ // 小组已满,需要滑落到该小组最后一人的 fake_id 下
|
|
|
+ $lastMember = end($spreadFakeIdGroup);
|
|
|
+ @file_put_contents('quanju4.txt', $lastMember['uid'] . "-小组最后一人uid\r\n", 8);
|
|
|
+ @file_put_contents('quanju4.txt', $lastMember['fake_pid'] . "-最后一人的fake_id\r\n", 8);
|
|
|
|
|
|
- // 查找小组最后一人的直推下级小组(group_pid等于最后一人的uid)
|
|
|
- $lastGroupSubordinates = $giftGroupService->getList([
|
|
|
+ // 查找最后一人的 fake_id 对应的小组
|
|
|
+ $lastMemberFakeIdGroup = $giftGroupService->getList([
|
|
|
'product_id' => $product_id,
|
|
|
- 'group_pid' => $lastGroupMemberUid
|
|
|
+ 'fake_pid' => $lastMember['fake_pid']
|
|
|
], '*', 0, 0, 'create_time ASC');
|
|
|
|
|
|
- @file_put_contents('quanju4.txt', count($lastGroupSubordinates) . "-最后一人的直推下级小组人数\r\n", 8);
|
|
|
+ @file_put_contents('quanju4.txt', count($lastMemberFakeIdGroup) . "-最后一人的fake_id小组人数\r\n", 8);
|
|
|
|
|
|
- if (count($lastGroupSubordinates) < $groupMaxNum) {
|
|
|
- // 最后一人的直推下级小组未满,新成员加入该小组
|
|
|
- if (count($lastGroupSubordinates) > 0) {
|
|
|
+ if (count($lastMemberFakeIdGroup) < $groupMaxNum) {
|
|
|
+ // 该小组未满,新成员加入该小组
|
|
|
+ if (count($lastMemberFakeIdGroup) > 0) {
|
|
|
// 该小组已有成员,新成员的group_pid是该小组的最后一人
|
|
|
- $lastSubGroupMember = end($lastGroupSubordinates);
|
|
|
- $data['group_pid'] = $lastSubGroupMember['uid'];
|
|
|
- // 新成员的fake_pid保持为最后一人的uid
|
|
|
- $data['fake_pid'] = $lastGroupMemberUid;
|
|
|
- @file_put_contents('quanju4.txt', $lastSubGroupMember['uid'] . "-小组的最后一人(新成员group_pid)\r\n", 8);
|
|
|
+ $lastSubMember = end($lastMemberFakeIdGroup);
|
|
|
+ $data['group_pid'] = $lastSubMember['uid'];
|
|
|
+ $data['fake_pid'] = $lastMember['fake_pid'];
|
|
|
+ @file_put_contents('quanju4.txt', $lastSubMember['uid'] . "-fake_id小组最后一人,新成员group_pid\r\n", 8);
|
|
|
} else {
|
|
|
// 该小组没有成员,新成员成为第一人
|
|
|
$data['group_pid'] = 0;
|
|
|
- $data['fake_pid'] = $lastGroupMemberUid;
|
|
|
- @file_put_contents('quanju4.txt', '最后一人的直推下级小组没有成员,新成员成为第一人\r\n', 8);
|
|
|
+ $data['fake_pid'] = $lastMember['fake_pid'];
|
|
|
+ @file_put_contents('quanju4.txt', '最后一人的fake_id小组没有成员,新成员成为第一人\r\n', 8);
|
|
|
}
|
|
|
} else {
|
|
|
- // 最后一人的直推下级小组也满了,新成员需要新建小组
|
|
|
+ // 该小组也满了,继续滑落(最后一人的 fake_id 可能不等于自己的 fake_pid)
|
|
|
+ // 这种情况下,最后一人的 fake_pid 就是滑落后的上级
|
|
|
$data['group_pid'] = 0;
|
|
|
- $data['fake_pid'] = $lastGroupMemberUid;
|
|
|
- @file_put_contents('quanju4.txt', '最后一人的直推下级小组已满,新成员新建小组\r\n', 8);
|
|
|
+ $data['fake_pid'] = $lastMember['fake_pid'];
|
|
|
+ @file_put_contents('quanju4.txt', '最后一人的fake_id小组已满,新成员fake_pid=' . $lastMember['fake_pid'] . "\r\n", 8);
|
|
|
}
|
|
|
- } else {
|
|
|
- // 小组未满,新成员应该加入当前小组
|
|
|
- // 新成员的group_pid是最后一个下级的uid(成为小组长)
|
|
|
- $data['group_pid'] = $lastMember['uid'];
|
|
|
- $data['fake_pid'] = $spread_uid;
|
|
|
}
|
|
|
} else {
|
|
|
// 直推上级没有下级,这是该推广人的第一个下级,建立新小组
|