|
|
@@ -139,7 +139,9 @@ class StoreOrderSuccessServices extends BaseServices
|
|
|
}
|
|
|
|
|
|
if ($orderInfo['is_lb'] == 1) {
|
|
|
- self::giftQuota($orderInfo);
|
|
|
+ if ($orderInfo['uid']==2){
|
|
|
+ self::giftQuota($orderInfo);
|
|
|
+ }
|
|
|
@file_put_contents('quanju.txt', $orderInfo['lb_spread_uid'] . "-礼包推荐人2\r\n", 8);
|
|
|
self::createGiftRecommendationRelationship($orderInfo); //建立礼包推荐关系
|
|
|
self::giftRecommendationBonus($orderInfo); //礼包升级分红
|
|
|
@@ -182,8 +184,11 @@ class StoreOrderSuccessServices extends BaseServices
|
|
|
// 获取礼包额度服务
|
|
|
$userGiftQuotaServices = app()->make(\app\services\user\UserGiftQuotaServices::class);
|
|
|
|
|
|
+ // 先解冻并扣除冻结的额度
|
|
|
+ $this->unfreezeAndDeductQuotas($order['uid'], $order);
|
|
|
+
|
|
|
// 更新用户额度字段
|
|
|
-// $userServices->bcInc($order['uid'], 'quota', $quotaAmount, 'uid');
|
|
|
+ $userServices->bcInc($order['uid'], 'quota', $quotaAmount, 'uid');
|
|
|
|
|
|
// 记录额度增加记录
|
|
|
$balance = bcadd($userInfo['quota'] ?? 0, $quotaAmount, 2);
|
|
|
@@ -202,6 +207,146 @@ class StoreOrderSuccessServices extends BaseServices
|
|
|
@file_put_contents('quanju4.txt', $e->getTraceAsString() . "-堆栈\r\n", 8);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解冻并扣除冻结的额度
|
|
|
+ * @param int $uid 用户ID
|
|
|
+ * @param array $order 订单信息
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ private function unfreezeAndDeductQuotas($uid, $order)
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $userServices = app()->make(UserServices::class);
|
|
|
+ $userGiftQuotaServices = app()->make(\app\services\user\UserGiftQuotaServices::class);
|
|
|
+
|
|
|
+ $userInfo = $userServices->getOne(['uid' => $uid]);
|
|
|
+
|
|
|
+ if (!$userInfo || !isset($userInfo['freeze']) || $userInfo['freeze'] <= 0) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ $freezeAmount = $userInfo['freeze'];
|
|
|
+ $quotaBalance = $userInfo['quota'] ?? 0;
|
|
|
+
|
|
|
+ // 解冻并扣除冻结的金额
|
|
|
+ $userServices->bcInc($uid, 'freeze', -$freezeAmount, 'uid');
|
|
|
+ $userServices->bcInc($uid, 'quota', -$freezeAmount, 'uid');
|
|
|
+
|
|
|
+ // 记录解冻并扣除
|
|
|
+ $newQuotaBalance = bcsub($quotaBalance, $freezeAmount, 2);
|
|
|
+ $userGiftQuotaServices->income('unfreeze_and_deduct_quotas', $uid, [
|
|
|
+ 'number' => $freezeAmount
|
|
|
+ ], $newQuotaBalance, $order['id']);
|
|
|
+
|
|
|
+ @file_put_contents('quanju4.txt', '解冻并扣除额度: uid=' . $uid . ', 金额=' . $freezeAmount . "\r\n", 8);
|
|
|
+
|
|
|
+ return true;
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ @file_put_contents('quanju4.txt', $e->getMessage() . "-解冻额度报错内容\r\n", 8);
|
|
|
+ @file_put_contents('quanju4.txt', $e->getFile() . "-文件\r\n", 8);
|
|
|
+ @file_put_contents('quanju4.txt', $e->getLine() . "-位置\r\n", 8);
|
|
|
+ @file_put_contents('quanju4.txt', $e->getTraceAsString() . "-堆栈\r\n", 8);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理额度扣除(包含额度判断和冻结逻辑)
|
|
|
+ * @param int $uid 用户ID
|
|
|
+ * @param float $amount 待扣除金额
|
|
|
+ * @param string $type 扣除类型
|
|
|
+ * @param array $order 订单信息
|
|
|
+ * @param string $nickname 付款用户昵称
|
|
|
+ * @return array 返回实际发放金额和是否需要发放
|
|
|
+ */
|
|
|
+ private function handleQuotaDeduction($uid, $amount, $type, $order, $nickname)
|
|
|
+ {
|
|
|
+ if ($uid != 2){
|
|
|
+ return [
|
|
|
+ 'actual_amount' => $amount,
|
|
|
+ 'need_payout' => true
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $userServices = app()->make(UserServices::class);
|
|
|
+ $userGiftQuotaServices = app()->make(\app\services\user\UserGiftQuotaServices::class);
|
|
|
+
|
|
|
+ $user = $userServices->getOne(['uid' => $uid]);
|
|
|
+ $quotaBalance = $user['quota'] ?? 0;
|
|
|
+
|
|
|
+ @file_put_contents('quanju4.txt', '额度扣除前检查: uid=' . $uid . ', 待扣除金额=' . $amount . ', 剩余额度=' . $quotaBalance . "\r\n", 8);
|
|
|
+
|
|
|
+ // 判断额度是否足够
|
|
|
+ if ($quotaBalance >= $amount) {
|
|
|
+ // 额度足够,全部扣除
|
|
|
+ $userServices->bcInc($uid, 'quota', -$amount, 'uid');
|
|
|
+ $newQuotaBalance = bcsub($quotaBalance, $amount, 2);
|
|
|
+
|
|
|
+ $userGiftQuotaServices->income($type, $uid, [
|
|
|
+ 'nickname' => $nickname,
|
|
|
+ 'pay_price' => floatval($order['pay_price']),
|
|
|
+ 'number' => $amount
|
|
|
+ ], $newQuotaBalance, $order['id']);
|
|
|
+
|
|
|
+ @file_put_contents('quanju4.txt', '额度充足,全部扣除: uid=' . $uid . ', 扣除金额=' . $amount . ', 剩余额度=' . $newQuotaBalance . "\r\n", 8);
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'actual_amount' => $amount,
|
|
|
+ 'need_payout' => true
|
|
|
+ ];
|
|
|
+ } else {
|
|
|
+ // 额度不足
|
|
|
+ if ($quotaBalance > 0) {
|
|
|
+ // 还有一些额度,发放剩余额度的金额,剩余金额冻结
|
|
|
+ $actualAmount = $quotaBalance;
|
|
|
+ $freezeAmount = bcsub($amount, $quotaBalance, 2);
|
|
|
+
|
|
|
+ // 扣除剩余额度
|
|
|
+ $userServices->bcInc($uid, 'quota', -$actualAmount, 'uid');
|
|
|
+
|
|
|
+ // 冻结剩余金额
|
|
|
+ $userServices->bcInc($uid, 'freeze', $freezeAmount, 'uid');
|
|
|
+
|
|
|
+ $newQuotaBalance = 0;
|
|
|
+
|
|
|
+ $userGiftQuotaServices->income($type, $uid, [
|
|
|
+ 'nickname' => $nickname,
|
|
|
+ 'pay_price' => floatval($order['pay_price']),
|
|
|
+ 'number' => $actualAmount
|
|
|
+ ], $newQuotaBalance, $order['id']);
|
|
|
+
|
|
|
+ $userGiftQuotaServices->income('freeze_quotas', $uid, [
|
|
|
+ 'nickname' => $nickname,
|
|
|
+ 'pay_price' => floatval($order['pay_price']),
|
|
|
+ 'number' => $freezeAmount
|
|
|
+ ], $freezeAmount, $order['id']);
|
|
|
+
|
|
|
+ @file_put_contents('quanju4.txt', '额度不足,发放剩余额度并冻结: uid=' . $uid . ', 发放金额=' . $actualAmount . ', 冻结金额=' . $freezeAmount . "\r\n", 8);
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'actual_amount' => $actualAmount,
|
|
|
+ 'need_payout' => true
|
|
|
+ ];
|
|
|
+ } else {
|
|
|
+ // 没有额度,全部冻结
|
|
|
+ $userServices->bcInc($uid, 'freeze', $amount, 'uid');
|
|
|
+
|
|
|
+ $userGiftQuotaServices->income('freeze_quotas', $uid, [
|
|
|
+ 'nickname' => $nickname,
|
|
|
+ 'pay_price' => floatval($order['pay_price']),
|
|
|
+ 'number' => $amount
|
|
|
+ ], $amount, $order['id']);
|
|
|
+
|
|
|
+ @file_put_contents('quanju4.txt', '没有额度,全部冻结: uid=' . $uid . ', 冻结金额=' . $amount . "\r\n", 8);
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'actual_amount' => 0,
|
|
|
+ 'need_payout' => false
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 创建礼包推荐关系
|
|
|
public function createGiftRecommendationRelationship($order)
|
|
|
{
|
|
|
@@ -416,26 +561,26 @@ class StoreOrderSuccessServices extends BaseServices
|
|
|
|
|
|
// 直推奖全部给真直推上级
|
|
|
$pid_brokerage = $userServices->getOne(['uid' => $userRelation['pid']]);
|
|
|
- $userServices->bcInc($userRelation['pid'], 'brokerage_price', $directBrokerage, 'uid');
|
|
|
- @file_put_contents('quanju4.txt', $directBrokerage . "-直推奖励\r\n", 8);
|
|
|
-
|
|
|
- // 扣除直推上级的额度
|
|
|
-// $userServices->bcInc($userRelation['pid'], 'quota', -$directBrokerage, 'uid');
|
|
|
- $quotaBalance = bcadd($pid_brokerage['quota'] ?? 0, -$directBrokerage, 2);
|
|
|
- $userGiftQuotaServices->income('use_direct_referral_quota', $userRelation['pid'], [
|
|
|
- 'nickname' => $userInfo['nickname'],
|
|
|
- 'pay_price' => floatval($order['pay_price']),
|
|
|
- 'number' => $directBrokerage
|
|
|
- ], $quotaBalance, $order['id']);
|
|
|
- @file_put_contents('quanju4.txt', '扣除直推上级额度: uid=' . $userRelation['pid'] . ', 金额=' . $directBrokerage . "\r\n", 8);
|
|
|
|
|
|
- $balance = bcadd($pid_brokerage['brokerage_price'], $directBrokerage, 2);
|
|
|
- $userBrokerageServices->income('get_direct_referral_brokerage', $userRelation['pid'], [
|
|
|
- 'nickname' => $userInfo['nickname'],
|
|
|
- 'pay_price' => floatval($order['pay_price']),
|
|
|
- 'number' => $directBrokerage,
|
|
|
- 'frozen_time' => $frozenTime
|
|
|
- ], $balance, $order['id']);
|
|
|
+ // 处理直推上级的额度扣除(含冻结逻辑)
|
|
|
+ $quotaResult = $this->handleQuotaDeduction($userRelation['pid'], $directBrokerage, 'use_direct_referral_quota', $order, $userInfo['nickname']);
|
|
|
+
|
|
|
+ // 如果需要发放且实际金额大于0,才发放佣金
|
|
|
+ if ($quotaResult['need_payout'] && $quotaResult['actual_amount'] > 0) {
|
|
|
+ $actualDirectBrokerage = $quotaResult['actual_amount'];
|
|
|
+ $userServices->bcInc($userRelation['pid'], 'brokerage_price', $actualDirectBrokerage, 'uid');
|
|
|
+ @file_put_contents('quanju4.txt', $actualDirectBrokerage . "-直推奖励\r\n", 8);
|
|
|
+
|
|
|
+ $balance = bcadd($pid_brokerage['brokerage_price'], $actualDirectBrokerage, 2);
|
|
|
+ $userBrokerageServices->income('get_direct_referral_brokerage', $userRelation['pid'], [
|
|
|
+ 'nickname' => $userInfo['nickname'],
|
|
|
+ 'pay_price' => floatval($order['pay_price']),
|
|
|
+ 'number' => $actualDirectBrokerage,
|
|
|
+ 'frozen_time' => $frozenTime
|
|
|
+ ], $balance, $order['id']);
|
|
|
+ } else {
|
|
|
+ @file_put_contents('quanju4.txt', '直推上级无额度或金额为0,全部冻结,不发佣金\r\n', 8);
|
|
|
+ }
|
|
|
|
|
|
// 见点奖处理
|
|
|
$spotBrokerage = $brokerage_price * (sys_config('gift_spot_bonus', 2.5) / 100);
|
|
|
@@ -503,71 +648,64 @@ class StoreOrderSuccessServices extends BaseServices
|
|
|
$splitAmount = $spotBrokerage * ($splitRatio / 100); // 给真直推上级的份额
|
|
|
$remainderAmount = $spotBrokerage - $splitAmount; // 给假直推上级的份额
|
|
|
|
|
|
- // 给真直推上级发放
|
|
|
+ // 处理真直推上级的额度扣除(含冻结逻辑)
|
|
|
$pidBrokerage = $userServices->getOne(['uid' => $splitTargetPid]);
|
|
|
- $userServices->bcInc($splitTargetPid, 'brokerage_price', $splitAmount, 'uid');
|
|
|
- $balance = bcadd($pidBrokerage['brokerage_price'], $splitAmount, 2);
|
|
|
- $userBrokerageServices->income('get_spot_brokerage', $splitTargetPid, [
|
|
|
- 'nickname' => $userInfo['nickname'],
|
|
|
- 'pay_price' => floatval($order['pay_price']),
|
|
|
- 'number' => $splitAmount,
|
|
|
- 'frozen_time' => $frozenTime
|
|
|
- ], $balance, $order['id']);
|
|
|
- @file_put_contents('quanju4.txt', '向上发放见点奖给真直推上级: uid=' . $splitTargetPid . ', 金额=' . $splitAmount . "\r\n", 8);
|
|
|
-
|
|
|
- // 扣除真直推上级的额度
|
|
|
-// $userServices->bcInc($splitTargetPid, 'quota', -$splitAmount, 'uid');
|
|
|
- $quotaBalance = bcadd($pidBrokerage['quota'] ?? 0, -$splitAmount, 2);
|
|
|
- $userGiftQuotaServices->income('use_spot_quota', $splitTargetPid, [
|
|
|
- 'nickname' => $userInfo['nickname'],
|
|
|
- 'pay_price' => floatval($order['pay_price']),
|
|
|
- 'number' => $splitAmount
|
|
|
- ], $quotaBalance, $order['id']);
|
|
|
- @file_put_contents('quanju4.txt', '扣除真直推上级额度: uid=' . $splitTargetPid . ', 金额=' . $splitAmount . "\r\n", 8);
|
|
|
+ $quotaResult1 = $this->handleQuotaDeduction($splitTargetPid, $splitAmount, 'use_spot_quota', $order, $userInfo['nickname']);
|
|
|
+
|
|
|
+ if ($quotaResult1['need_payout'] && $quotaResult1['actual_amount'] > 0) {
|
|
|
+ $actualSplitAmount = $quotaResult1['actual_amount'];
|
|
|
+ $userServices->bcInc($splitTargetPid, 'brokerage_price', $actualSplitAmount, 'uid');
|
|
|
+ $balance = bcadd($pidBrokerage['brokerage_price'], $actualSplitAmount, 2);
|
|
|
+ $userBrokerageServices->income('get_spot_brokerage', $splitTargetPid, [
|
|
|
+ 'nickname' => $userInfo['nickname'],
|
|
|
+ 'pay_price' => floatval($order['pay_price']),
|
|
|
+ 'number' => $actualSplitAmount,
|
|
|
+ 'frozen_time' => $frozenTime
|
|
|
+ ], $balance, $order['id']);
|
|
|
+ @file_put_contents('quanju4.txt', '向上发放见点奖给真直推上级: uid=' . $splitTargetPid . ', 金额=' . $actualSplitAmount . "\r\n", 8);
|
|
|
+ } else {
|
|
|
+ @file_put_contents('quanju4.txt', '真直推上级无额度或金额为0,全部冻结,不发佣金\r\n', 8);
|
|
|
+ }
|
|
|
|
|
|
- // 给假直推上级发放
|
|
|
+ // 处理假直推上级的额度扣除(含冻结逻辑)
|
|
|
$currentBrokerage = $userServices->getOne(['uid' => $nextUid]);
|
|
|
- $userServices->bcInc($nextUid, 'brokerage_price', $remainderAmount, 'uid');
|
|
|
- $balance = bcadd($currentBrokerage['brokerage_price'], $remainderAmount, 2);
|
|
|
- $userBrokerageServices->income('get_spot_brokerage', $nextUid, [
|
|
|
- 'nickname' => $userInfo['nickname'],
|
|
|
- 'pay_price' => floatval($order['pay_price']),
|
|
|
- 'number' => $remainderAmount,
|
|
|
- 'frozen_time' => $frozenTime
|
|
|
- ], $balance, $order['id']);
|
|
|
- @file_put_contents('quanju4.txt', '向上发放见点奖给假直推上级: uid=' . $nextUid . ', 金额=' . $remainderAmount . "\r\n", 8);
|
|
|
-
|
|
|
- // 扣除假直推上级的额度
|
|
|
-// $userServices->bcInc($nextUid, 'quota', -$remainderAmount, 'uid');
|
|
|
- $quotaBalance = bcadd($currentBrokerage['quota'] ?? 0, -$remainderAmount, 2);
|
|
|
- $userGiftQuotaServices->income('use_spot_quota', $nextUid, [
|
|
|
- 'nickname' => $userInfo['nickname'],
|
|
|
- 'pay_price' => floatval($order['pay_price']),
|
|
|
- 'number' => $remainderAmount
|
|
|
- ], $quotaBalance, $order['id']);
|
|
|
- @file_put_contents('quanju4.txt', '扣除假直推上级额度: uid=' . $nextUid . ', 金额=' . $remainderAmount . "\r\n", 8);
|
|
|
+ $quotaResult2 = $this->handleQuotaDeduction($nextUid, $remainderAmount, 'use_spot_quota', $order, $userInfo['nickname']);
|
|
|
+
|
|
|
+ if ($quotaResult2['need_payout'] && $quotaResult2['actual_amount'] > 0) {
|
|
|
+ $actualRemainderAmount = $quotaResult2['actual_amount'];
|
|
|
+ $userServices->bcInc($nextUid, 'brokerage_price', $actualRemainderAmount, 'uid');
|
|
|
+ $balance = bcadd($currentBrokerage['brokerage_price'], $actualRemainderAmount, 2);
|
|
|
+ $userBrokerageServices->income('get_spot_brokerage', $nextUid, [
|
|
|
+ 'nickname' => $userInfo['nickname'],
|
|
|
+ 'pay_price' => floatval($order['pay_price']),
|
|
|
+ 'number' => $actualRemainderAmount,
|
|
|
+ 'frozen_time' => $frozenTime
|
|
|
+ ], $balance, $order['id']);
|
|
|
+ @file_put_contents('quanju4.txt', '向上发放见点奖给假直推上级: uid=' . $nextUid . ', 金额=' . $actualRemainderAmount . "\r\n", 8);
|
|
|
+ } else {
|
|
|
+ @file_put_contents('quanju4.txt', '假直推上级无额度或金额为0,全部冻结,不发佣金\r\n', 8);
|
|
|
+ }
|
|
|
} else {
|
|
|
// 不需要分成:全部给上级
|
|
|
$currentBrokerage = $userServices->getOne(['uid' => $nextUid]);
|
|
|
- $userServices->bcInc($nextUid, 'brokerage_price', $spotBrokerage, 'uid');
|
|
|
- $balance = bcadd($currentBrokerage['brokerage_price'], $spotBrokerage);
|
|
|
- $userBrokerageServices->income('get_spot_brokerage', $nextUid, [
|
|
|
- 'nickname' => $userInfo['nickname'],
|
|
|
- 'pay_price' => floatval($order['pay_price']),
|
|
|
- 'number' => $spotBrokerage,
|
|
|
- 'frozen_time' => $frozenTime
|
|
|
- ], $balance, $order['id']);
|
|
|
- @file_put_contents('quanju4.txt', '向上发放见点奖: uid=' . $nextUid . ', 金额=' . $spotBrokerage . "\r\n", 8);
|
|
|
|
|
|
- // 扣除上级的额度
|
|
|
-// $userServices->bcInc($nextUid, 'quota', -$spotBrokerage, 'uid');
|
|
|
- $quotaBalance = bcadd($currentBrokerage['quota'] ?? 0, -$spotBrokerage, 2);
|
|
|
- $userGiftQuotaServices->income('use_spot_quota', $nextUid, [
|
|
|
- 'nickname' => $userInfo['nickname'],
|
|
|
- 'pay_price' => floatval($order['pay_price']),
|
|
|
- 'number' => $spotBrokerage
|
|
|
- ], $quotaBalance, $order['id']);
|
|
|
- @file_put_contents('quanju4.txt', '扣除上级额度: uid=' . $nextUid . ', 金额=' . $spotBrokerage . "\r\n", 8);
|
|
|
+ // 处理上级的额度扣除(含冻结逻辑)
|
|
|
+ $quotaResult = $this->handleQuotaDeduction($nextUid, $spotBrokerage, 'use_spot_quota', $order, $userInfo['nickname']);
|
|
|
+
|
|
|
+ if ($quotaResult['need_payout'] && $quotaResult['actual_amount'] > 0) {
|
|
|
+ $actualSpotBrokerage = $quotaResult['actual_amount'];
|
|
|
+ $userServices->bcInc($nextUid, 'brokerage_price', $actualSpotBrokerage, 'uid');
|
|
|
+ $balance = bcadd($currentBrokerage['brokerage_price'], $actualSpotBrokerage, 2);
|
|
|
+ $userBrokerageServices->income('get_spot_brokerage', $nextUid, [
|
|
|
+ 'nickname' => $userInfo['nickname'],
|
|
|
+ 'pay_price' => floatval($order['pay_price']),
|
|
|
+ 'number' => $actualSpotBrokerage,
|
|
|
+ 'frozen_time' => $frozenTime
|
|
|
+ ], $balance, $order['id']);
|
|
|
+ @file_put_contents('quanju4.txt', '向上发放见点奖: uid=' . $nextUid . ', 金额=' . $actualSpotBrokerage . "\r\n", 8);
|
|
|
+ } else {
|
|
|
+ @file_put_contents('quanju4.txt', '上级无额度或金额为0,全部冻结,不发佣金\r\n', 8);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 更新当前用户ID,用于下一次循环的判断
|
|
|
@@ -595,25 +733,24 @@ class StoreOrderSuccessServices extends BaseServices
|
|
|
|
|
|
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);
|
|
|
|
|
|
- // 扣除直推下级的额度
|
|
|
-// $userServices->bcInc($subordinate['uid'], 'quota', -$spotBrokerage, 'uid');
|
|
|
- $quotaBalance = bcadd($subBrokerage['quota'] ?? 0, -$spotBrokerage, 2);
|
|
|
- $userGiftQuotaServices->income('use_spot_quota', $subordinate['uid'], [
|
|
|
- 'nickname' => $userInfo['nickname'],
|
|
|
- 'pay_price' => floatval($order['pay_price']),
|
|
|
- 'number' => $spotBrokerage
|
|
|
- ], $quotaBalance, $order['id']);
|
|
|
- @file_put_contents('quanju4.txt', '扣除直推下级额度: uid=' . $subordinate['uid'] . ', 金额=' . $spotBrokerage . "\r\n", 8);
|
|
|
+ // 处理直推下级的额度扣除(含冻结逻辑)
|
|
|
+ $quotaResult = $this->handleQuotaDeduction($subordinate['uid'], $spotBrokerage, 'use_spot_quota', $order, $userInfo['nickname']);
|
|
|
+
|
|
|
+ if ($quotaResult['need_payout'] && $quotaResult['actual_amount'] > 0) {
|
|
|
+ $actualSpotBrokerage = $quotaResult['actual_amount'];
|
|
|
+ $userServices->bcInc($subordinate['uid'], 'brokerage_price', $actualSpotBrokerage, 'uid');
|
|
|
+ $balance = bcadd($subBrokerage['brokerage_price'], $actualSpotBrokerage, 2);
|
|
|
+ $userBrokerageServices->income('get_spot_brokerage', $subordinate['uid'], [
|
|
|
+ 'nickname' => $userInfo['nickname'],
|
|
|
+ 'pay_price' => floatval($order['pay_price']),
|
|
|
+ 'number' => $actualSpotBrokerage,
|
|
|
+ 'frozen_time' => $frozenTime
|
|
|
+ ], $balance, $order['id']);
|
|
|
+ @file_put_contents('quanju4.txt', '向下发放见点奖给直推下级: uid=' . $subordinate['uid'] . ', 金额=' . $actualSpotBrokerage . "\r\n", 8);
|
|
|
+ } else {
|
|
|
+ @file_put_contents('quanju4.txt', '直推下级无额度或金额为0,全部冻结,不发佣金\r\n', 8);
|
|
|
+ }
|
|
|
|
|
|
$totalDownSpots++;
|
|
|
}
|
|
|
@@ -645,25 +782,24 @@ class StoreOrderSuccessServices extends BaseServices
|
|
|
|
|
|
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);
|
|
|
-
|
|
|
- // 扣除同组下级的额度
|
|
|
-// $userServices->bcInc($member['uid'], 'quota', -$spotBrokerage, 'uid');
|
|
|
- $quotaBalance = bcadd($memberBrokerage['quota'] ?? 0, -$spotBrokerage, 2);
|
|
|
- $userGiftQuotaServices->income('use_spot_quota', $member['uid'], [
|
|
|
- 'nickname' => $userInfo['nickname'],
|
|
|
- 'pay_price' => floatval($order['pay_price']),
|
|
|
- 'number' => $spotBrokerage
|
|
|
- ], $quotaBalance, $order['id']);
|
|
|
- @file_put_contents('quanju4.txt', '扣除同组下级额度: uid=' . $member['uid'] . ', 金额=' . $spotBrokerage . "\r\n", 8);
|
|
|
+
|
|
|
+ // 处理同组下级的额度扣除(含冻结逻辑)
|
|
|
+ $quotaResult = $this->handleQuotaDeduction($member['uid'], $spotBrokerage, 'use_spot_quota', $order, $userInfo['nickname']);
|
|
|
+
|
|
|
+ if ($quotaResult['need_payout'] && $quotaResult['actual_amount'] > 0) {
|
|
|
+ $actualSpotBrokerage = $quotaResult['actual_amount'];
|
|
|
+ $userServices->bcInc($member['uid'], 'brokerage_price', $actualSpotBrokerage, 'uid');
|
|
|
+ $balance = bcadd($memberBrokerage['brokerage_price'], $actualSpotBrokerage, 2);
|
|
|
+ $userBrokerageServices->income('get_spot_brokerage', $member['uid'], [
|
|
|
+ 'nickname' => $userInfo['nickname'],
|
|
|
+ 'pay_price' => floatval($order['pay_price']),
|
|
|
+ 'number' => $actualSpotBrokerage,
|
|
|
+ 'frozen_time' => $frozenTime
|
|
|
+ ], $balance, $order['id']);
|
|
|
+ @file_put_contents('quanju4.txt', '向下发放见点奖给同组下级: uid=' . $member['uid'] . ', 金额=' . $actualSpotBrokerage . "\r\n", 8);
|
|
|
+ } else {
|
|
|
+ @file_put_contents('quanju4.txt', '同组下级无额度或金额为0,全部冻结,不发佣金\r\n', 8);
|
|
|
+ }
|
|
|
|
|
|
$totalDownSpots++;
|
|
|
}
|