|
|
@@ -365,95 +365,67 @@ class StoreOrderSuccessServices extends BaseServices
|
|
|
|
|
|
// 见点奖处理
|
|
|
$spotBrokerage = $brokerage_price * (sys_config('gift_spot_bonus', 2.5) / 100);
|
|
|
- $totalSpots = 0;
|
|
|
-
|
|
|
- // 1. 真直推链上找5人
|
|
|
- $currentUid = $userRelation['pid'];
|
|
|
- for ($i = 0; $i < sys_config('gift_spot_bonus_up', 5); $i++) {
|
|
|
- // 先给当前uid发奖
|
|
|
- $currentBrokerage = $userServices->getOne(['uid' => $currentUid]);
|
|
|
- $userServices->bcInc($currentUid, 'brokerage_price', $spotBrokerage, 'uid');
|
|
|
+
|
|
|
+ // 1. 向上查找:先找小组上级,没有就找直推上级
|
|
|
+ $spotUpLimit = sys_config('gift_spot_bonus_up', 15);
|
|
|
+ $currentUid = $order['uid']; // 从当前用户开始
|
|
|
+ $currentRelation = $userRelation; // 当前用户的推荐关系
|
|
|
+
|
|
|
+ for ($i = 0; $i < $spotUpLimit; $i++) {
|
|
|
+ $nextUid = null;
|
|
|
+
|
|
|
+ // 优先查找小组上级
|
|
|
+ if (!empty($currentRelation['group_pid'])) {
|
|
|
+ $nextUid = $currentRelation['group_pid'];
|
|
|
+ } else if (!empty($currentRelation['pid'])) {
|
|
|
+ // 没有小组上级,查找直推上级
|
|
|
+ $nextUid = $currentRelation['pid'];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 找不到上级,退出循环
|
|
|
+ if (!$nextUid) break;
|
|
|
+
|
|
|
+ // 给上级发放见点奖
|
|
|
+ $currentBrokerage = $userServices->getOne(['uid' => $nextUid]);
|
|
|
+ $userServices->bcInc($nextUid, 'brokerage_price', $spotBrokerage, 'uid');
|
|
|
$balance = bcadd($currentBrokerage['brokerage_price'], $spotBrokerage);
|
|
|
- $userBrokerageServices->income('get_spot_brokerage', $currentUid, [
|
|
|
+ $userBrokerageServices->income('get_spot_brokerage', $nextUid, [
|
|
|
'nickname' => $userInfo['nickname'],
|
|
|
'pay_price' => floatval($order['pay_price']),
|
|
|
'number' => $spotBrokerage,
|
|
|
'frozen_time' => $frozenTime
|
|
|
], $balance, $order['id']);
|
|
|
- $totalSpots++;
|
|
|
|
|
|
- // 再查找当前uid的上级关系
|
|
|
- $parentRelation = $giftGroupService->getOne([
|
|
|
+ @file_put_contents('quanju4.txt', '向上发放见点奖: uid=' . $nextUid . ', 金额=' . $spotBrokerage . "\r\n", 8);
|
|
|
+
|
|
|
+ // 查找下一个上级的推荐关系
|
|
|
+ $currentRelation = $giftGroupService->getOne([
|
|
|
'product_id' => $product_id,
|
|
|
- 'uid' => $currentUid
|
|
|
+ 'uid' => $nextUid
|
|
|
]);
|
|
|
- if (!$parentRelation) break; // 找不到上级关系,退出循环
|
|
|
|
|
|
- $currentUid = $parentRelation['pid']; // 继续向上
|
|
|
+ // 如果找不到推荐关系,退出循环
|
|
|
+ if (!$currentRelation) break;
|
|
|
}
|
|
|
|
|
|
- // 2. 同组下找M人(先找同小组的下级)
|
|
|
+ // 2. 向下查找:只找购买人的直推下级
|
|
|
$spotDownLimit = sys_config('gift_spot_bonus_down', 15);
|
|
|
-
|
|
|
- // 获取所有pid与当前用户pid相同的同级用户
|
|
|
- $samePidMembers = $giftGroupService->getList([
|
|
|
+ $directSubordinates = $giftGroupService->getList([
|
|
|
'product_id' => $product_id,
|
|
|
- 'pid' => $userRelation['pid']
|
|
|
- ], '*', 0, 0, 'create_time asc');
|
|
|
-
|
|
|
- // 找到当前用户在同级用户中的位置
|
|
|
- $currentIndex = null;
|
|
|
- foreach ($samePidMembers as $index => $member) {
|
|
|
- if ($member['uid'] == $order['uid']) {
|
|
|
- $currentIndex = $index;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 从当前用户之后的同级用户开始,检查它们是否是同组下级
|
|
|
- if ($currentIndex !== null) {
|
|
|
- for ($i = $currentIndex + 1; $i < count($samePidMembers) && $totalSpots < $spotDownLimit; $i++) {
|
|
|
- $member = $samePidMembers[$i];
|
|
|
-
|
|
|
- // 检查这个同级用户的group_pid层级是否在当前用户或其下级中
|
|
|
- // 即:group_pid == order['uid'] 或 group_pid 是当前用户的下级
|
|
|
- $isGroupSubordinate = $this->isGroupSubordinate($order['uid'], $member['group_pid'], $product_id, $giftGroupService);
|
|
|
-
|
|
|
- if ($isGroupSubordinate) {
|
|
|
- $memberBrokerage = $userServices->getOne(['uid' => $member['uid']]);
|
|
|
- $userServices->bcInc($member['uid'], 'brokerage_price', $spotBrokerage, 'uid');
|
|
|
- $balance = bcadd($memberBrokerage['brokerage_price'], $spotBrokerage);
|
|
|
- $userBrokerageServices->income('get_spot_brokerage', $member['uid'], [
|
|
|
- 'nickname' => $userInfo['nickname'],
|
|
|
- 'pay_price' => floatval($order['pay_price']),
|
|
|
- 'number' => $spotBrokerage,
|
|
|
- 'frozen_time' => $frozenTime
|
|
|
- ], $balance, $order['id']);
|
|
|
- @file_put_contents('quanju4.txt', '发放见点奖给同组下级: uid=' . $member['uid'] . ', 金额=' . $spotBrokerage . "\r\n", 8);
|
|
|
- $totalSpots++;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 3. 如果同组下级不足M人,找自己的直推下级
|
|
|
- if ($totalSpots < $spotDownLimit) {
|
|
|
- $directSubordinates = $giftGroupService->getList([
|
|
|
- 'product_id' => $product_id,
|
|
|
- 'pid' => $order['uid']
|
|
|
- ], '*', 0, $spotDownLimit - $totalSpots, 'create_time asc');
|
|
|
-
|
|
|
- foreach ($directSubordinates as $subordinate) {
|
|
|
- $subBrokerage = $userServices->getOne(['uid' => $subordinate['uid']]);
|
|
|
- $userServices->bcInc($subordinate['uid'], 'brokerage_price', $spotBrokerage, 'uid');
|
|
|
- $balance = bcadd($subBrokerage['brokerage_price'], $spotBrokerage);
|
|
|
- $userBrokerageServices->income('get_spot_brokerage', $subordinate['uid'], [
|
|
|
- 'nickname' => $userInfo['nickname'],
|
|
|
- 'pay_price' => floatval($order['pay_price']),
|
|
|
- 'number' => $spotBrokerage,
|
|
|
- 'frozen_time' => $frozenTime
|
|
|
- ], $balance, $order['id']);
|
|
|
- $totalSpots++;
|
|
|
- }
|
|
|
+ 'pid' => $order['uid']
|
|
|
+ ], '*', 0, $spotDownLimit, 'create_time asc');
|
|
|
+
|
|
|
+ foreach ($directSubordinates as $subordinate) {
|
|
|
+ $subBrokerage = $userServices->getOne(['uid' => $subordinate['uid']]);
|
|
|
+ $userServices->bcInc($subordinate['uid'], 'brokerage_price', $spotBrokerage, 'uid');
|
|
|
+ $balance = bcadd($subBrokerage['brokerage_price'], $spotBrokerage);
|
|
|
+ $userBrokerageServices->income('get_spot_brokerage', $subordinate['uid'], [
|
|
|
+ 'nickname' => $userInfo['nickname'],
|
|
|
+ 'pay_price' => floatval($order['pay_price']),
|
|
|
+ 'number' => $spotBrokerage,
|
|
|
+ 'frozen_time' => $frozenTime
|
|
|
+ ], $balance, $order['id']);
|
|
|
+ @file_put_contents('quanju4.txt', '向下发放见点奖给直推下级: uid=' . $subordinate['uid'] . ', 金额=' . $spotBrokerage . "\r\n", 8);
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
@@ -466,47 +438,6 @@ class StoreOrderSuccessServices extends BaseServices
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 检查某个用户是否是另一个用户的小组下级(通过group_pid层级关系)
|
|
|
- * @param int $baseUid 基准用户uid
|
|
|
- * @param int $groupPid 要检查的group_pid
|
|
|
- * @param int $productId 商品ID
|
|
|
- * @param StoreProductGiftGroupService $giftGroupService 礼包服务
|
|
|
- * @param array $checked 已检查的用户(防止循环)
|
|
|
- * @return bool 如果是小组下级返回true,否则返回false
|
|
|
- */
|
|
|
- protected function isGroupSubordinate($baseUid, $groupPid, $productId, $giftGroupService, $checked = [])
|
|
|
- {
|
|
|
- // 如果已经检查过这个groupPid,跳过(防止循环)
|
|
|
- if (isset($checked[$groupPid])) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- $checked[$groupPid] = true;
|
|
|
-
|
|
|
- // 如果groupPid是0,说明没有小组关系
|
|
|
- if (empty($groupPid)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- // 如果groupPid等于基准用户,说明是直接下级
|
|
|
- if ($groupPid == $baseUid) {
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- // 递归检查group_pid是否是基准用户的下级
|
|
|
- $member = $giftGroupService->getOne([
|
|
|
- 'product_id' => $productId,
|
|
|
- 'uid' => $groupPid
|
|
|
- ]);
|
|
|
-
|
|
|
- if ($member) {
|
|
|
- // 继续检查这个用户的group_pid
|
|
|
- return $this->isGroupSubordinate($baseUid, $member['group_pid'], $productId, $giftGroupService, $checked);
|
|
|
- }
|
|
|
-
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 检查某个用户是否是另一个用户的下级团队成员
|
|
|
* @param int $uid 当前用户
|