|
|
@@ -232,6 +232,7 @@ class StoreOrderSuccessServices extends BaseServices
|
|
|
// 追溯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,
|
|
|
@@ -239,6 +240,7 @@ class StoreOrderSuccessServices extends BaseServices
|
|
|
]);
|
|
|
if ($chainMember) {
|
|
|
$currentGroupPid = $chainMember['group_pid'];
|
|
|
+ @file_put_contents('quanju4.txt', $chainMember['group_pid'] . "-下一节点group_pid\r\n", 8);
|
|
|
} else {
|
|
|
break;
|
|
|
}
|
|
|
@@ -259,36 +261,79 @@ class StoreOrderSuccessServices extends BaseServices
|
|
|
@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) {
|
|
|
- // 小组满人,从后往前查找未满的直推下级小组
|
|
|
- $foundGroup = false;
|
|
|
-
|
|
|
- // 倒序遍历小组成员,查找未满的直推下级小组
|
|
|
- for ($i = count($allSubordinates) - 1; $i >= 0; $i--) {
|
|
|
- $member = $allSubordinates[$i];
|
|
|
-
|
|
|
- // 查找该成员作为小组长的小组成员(group_pid等于该成员uid的所有人)
|
|
|
- $subGroupMembers = $giftGroupService->getList([
|
|
|
- 'product_id' => $product_id,
|
|
|
- 'group_pid' => $member['uid']
|
|
|
- ], '*', 0, 0, 'create_time ASC');
|
|
|
-
|
|
|
- // 如果该成员的小组未满(包括自己作为组长的0或多人),可以加入
|
|
|
- if (count($subGroupMembers) < $groupMaxNum) {
|
|
|
- $data['group_pid'] = $member['uid'];
|
|
|
- $data['fake_pid'] = $spread_uid;
|
|
|
- $foundGroup = true;
|
|
|
- break;
|
|
|
+ // 小组满人,需要滑落到小组最后一人的直推下级小组
|
|
|
+ // 小组最后一人是group_pid链条中的最后一个uid
|
|
|
+ $lastGroupMemberUid = end($groupChain);
|
|
|
+
|
|
|
+ @file_put_contents('quanju4.txt', $lastGroupMemberUid . "-小组最后一人的uid\r\n", 8);
|
|
|
+
|
|
|
+ // 查找小组最后一人的直推下级(pid等于最后一人的uid)
|
|
|
+ $lastDirectSubordinates = $giftGroupService->getList([
|
|
|
+ 'product_id' => $product_id,
|
|
|
+ 'pid' => $lastGroupMemberUid
|
|
|
+ ], '*', 0, 0, 'create_time ASC');
|
|
|
+
|
|
|
+ @file_put_contents('quanju4.txt', count($lastDirectSubordinates) . "-最后一人的直推下级人数\r\n", 8);
|
|
|
+
|
|
|
+ if (count($lastDirectSubordinates) < $groupMaxNum) {
|
|
|
+ // 最后一人的直推下级未满,新成员应该加入这个小组
|
|
|
+ // 查找这些直推下级的小组关系,判断是否有小组(group_pid指向的)
|
|
|
+ if (count($lastDirectSubordinates) > 0) {
|
|
|
+ // 最后一人的直推下级有成员,查找这些成员的group_pid
|
|
|
+ $firstDirectSubordinate = $lastDirectSubordinates[0];
|
|
|
+ // 如果第一个直推下级的group_pid不为0,说明有小组,查找该小组的最后一人
|
|
|
+ if ($firstDirectSubordinate['group_pid'] > 0) {
|
|
|
+ // 查找该小组的所有成员
|
|
|
+ $subGroupMembers = $giftGroupService->getList([
|
|
|
+ 'product_id' => $product_id,
|
|
|
+ 'group_pid' => $firstDirectSubordinate['group_pid']
|
|
|
+ ], '*', 0, 0, 'create_time ASC');
|
|
|
+ // 新成员的group_pid是该小组的最后一人
|
|
|
+ $lastSubGroupMember = end($subGroupMembers);
|
|
|
+ $data['group_pid'] = $lastSubGroupMember['uid'];
|
|
|
+ // 新成员的fake_pid是该小组的最后一人
|
|
|
+ $data['fake_pid'] = $lastSubGroupMember['uid'];
|
|
|
+ @file_put_contents('quanju4.txt', $lastSubGroupMember['uid'] . "-小组的最后一人(新成员fake_pid)\r\n", 8);
|
|
|
+ } else {
|
|
|
+ // 第一直推下级的group_pid为0,说明没有小组,新成员成为第一人
|
|
|
+ $data['group_pid'] = 0;
|
|
|
+ $data['fake_pid'] = $lastGroupMemberUid;
|
|
|
+ @file_put_contents('quanju4.txt', '最后一人的直推下级没有小组,新成员成为第一人\r\n', 8);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 最后一人的直推下级没有成员,新成员成为第一人
|
|
|
+ $data['group_pid'] = 0;
|
|
|
+ $data['fake_pid'] = $lastGroupMemberUid;
|
|
|
+ @file_put_contents('quanju4.txt', '最后一人的直推下级没有成员,新成员成为第一人\r\n', 8);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 最后一人的直推下级也满了,新成员应该滑落到这个小组的最后一人
|
|
|
+ if (count($lastDirectSubordinates) > 0) {
|
|
|
+ // 查找最后一个人的小组
|
|
|
+ $lastDirectSubordinate = end($lastDirectSubordinates);
|
|
|
+ if ($lastDirectSubordinate['group_pid'] > 0) {
|
|
|
+ $subGroupMembers = $giftGroupService->getList([
|
|
|
+ 'product_id' => $product_id,
|
|
|
+ 'group_pid' => $lastDirectSubordinate['group_pid']
|
|
|
+ ], '*', 0, 0, 'create_time ASC');
|
|
|
+ $lastSubGroupMember = end($subGroupMembers);
|
|
|
+ $data['group_pid'] = 0;
|
|
|
+ $data['fake_pid'] = $lastSubGroupMember['uid'];
|
|
|
+ @file_put_contents('quanju4.txt', $lastSubGroupMember['uid'] . "-直推下级已满,新成员的fake_pid\r\n", 8);
|
|
|
+ } else {
|
|
|
+ $data['group_pid'] = 0;
|
|
|
+ $data['fake_pid'] = $lastDirectSubordinate['uid'];
|
|
|
+ @file_put_contents('quanju4.txt', $lastDirectSubordinate['uid'] . "-直推下级已满,无小组,新成员的fake_pid\r\n", 8);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 理论上不会走到这里
|
|
|
+ $data['group_pid'] = 0;
|
|
|
+ $data['fake_pid'] = $lastGroupMemberUid;
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- // 如果所有成员的直推下级小组都满了,建立新小组
|
|
|
- if (!$foundGroup) {
|
|
|
- $lastMember = $allSubordinates[count($allSubordinates) - 1];
|
|
|
- $data['group_pid'] = 0;
|
|
|
- $data['fake_pid'] = $lastMember['uid'];
|
|
|
}
|
|
|
} else {
|
|
|
// 小组未满,新成员应该加入当前小组
|
|
|
@@ -331,8 +376,6 @@ class StoreOrderSuccessServices extends BaseServices
|
|
|
@file_put_contents('quanju4.txt', 'cart_info不存在或为空' . "\r\n", 8);
|
|
|
return false;
|
|
|
}
|
|
|
- @file_put_contents('quanju4.txt', 'cart_info存在: ' . json_encode($order['cart_info'][0]) . "\r\n", 8);
|
|
|
-
|
|
|
// 获取商品ID和商品价格作为佣金计算基数
|
|
|
$product_id = $order['cart_info'][0]['product_id'] ?? 0;
|
|
|
$brokerage_price = $order['cart_info'][0]['truePrice'] ?? 0;
|