|
@@ -117,6 +117,20 @@ class UserBrokerageServices extends BaseServices
|
|
|
'status' => 1,
|
|
|
'pm' => 1
|
|
|
],
|
|
|
+ 'trade_in' => [
|
|
|
+ 'title' => '佣金转入',
|
|
|
+ 'type' => 'trade_in',
|
|
|
+ 'mark' => '{%mark%}{$number}元',
|
|
|
+ 'status' => 1,
|
|
|
+ 'pm' => 1
|
|
|
+ ],
|
|
|
+ 'trade_out' => [
|
|
|
+ 'title' => '佣金转出',
|
|
|
+ 'type' => 'trade_out',
|
|
|
+ 'mark' => '{%mark%}{$number}元',
|
|
|
+ 'status' => 1,
|
|
|
+ 'pm' => 0
|
|
|
+ ],
|
|
|
];
|
|
|
|
|
|
|
|
@@ -658,4 +672,56 @@ class UserBrokerageServices extends BaseServices
|
|
|
}
|
|
|
return ['list' => $list, 'time' => $times];
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ public function trade(int $uid, int $to_uid, $num)
|
|
|
+ {
|
|
|
+ $switch = sys_config('brokerage_trade_switch', 1);
|
|
|
+ if (!$switch) throw new ValidateException('暂不支持');
|
|
|
+
|
|
|
+ $userService = app()->make(UserServices::class);
|
|
|
+ $user = $userService->getUserInfo($uid);
|
|
|
+ $to_user = $userService->getUserInfo($to_uid);
|
|
|
+ if (!$user || !$to_user) {
|
|
|
+ throw new ValidateException('数据不存在');
|
|
|
+ }
|
|
|
+ if ($to_uid == $uid) throw new ValidateException('不能自己转给自己');
|
|
|
+ if ($user['is_auth'] != 2) throw new ValidateException('请先完成实名认证');
|
|
|
+
|
|
|
+ $broken_commission = $this->getUserFrozenPrice($uid);
|
|
|
+ if ($broken_commission < 0)
|
|
|
+ $broken_commission = 0;
|
|
|
+ $brokerage_price = $user['brokerage_price'];
|
|
|
+
|
|
|
+ $commissionCount = (float)bcsub((string)$brokerage_price, (string)$broken_commission, 2);
|
|
|
+ if ($num > $commissionCount) {
|
|
|
+ throw new ValidateException('可用佣金不足');
|
|
|
+ }
|
|
|
+
|
|
|
+ $extractPrice = $user['brokerage_price'];
|
|
|
+ if ($extractPrice < 0) {
|
|
|
+ throw new ValidateException('转账佣金不足' . $num);
|
|
|
+ }
|
|
|
+ if ($num > $extractPrice) {
|
|
|
+ throw new ValidateException('转账佣金不足' . $num);
|
|
|
+ }
|
|
|
+ if ($num <= 0) {
|
|
|
+ throw new ValidateException('转账佣金大于0');
|
|
|
+ }
|
|
|
+ return $this->transaction(function () use ($num, $user, $to_user, $userService) {
|
|
|
+
|
|
|
+ $balance = bcsub((string)$user['brokerage_price'], (string)$num, 2) ?? 0;
|
|
|
+ $balance2 = bcadd((string)$to_user['brokerage_price'], (string)$num, 2) ?? 0;
|
|
|
+ if (!$userService->update($user['uid'], ['brokerage_price' => $balance], 'uid')) {
|
|
|
+ throw new ValidateException('修改用户信息失败');
|
|
|
+ }
|
|
|
+ if (!$userService->update($to_user['uid'], ['brokerage_price' => $balance2], 'uid')) {
|
|
|
+ throw new ValidateException('修改用户信息失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->income('trade_out', $user['uid'], ['mark' => '转账给' . $to_user['nickname'] . '(' . $to_user['uid'] . ')', 'number' => $num], $balance, 0);
|
|
|
+ $this->income('trade_in', $to_user['uid'], ['mark' => '转账自' . $user['nickname'] . '(' . $user['uid'] . ')', 'number' => $num], $balance2, 0);
|
|
|
+ return true;
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|