|
|
@@ -533,19 +533,17 @@ class UserExtractServices extends BaseServices
|
|
|
throw new ApiException(410024);
|
|
|
}
|
|
|
|
|
|
- /** @var UserBrokerageServices $services */
|
|
|
- $services = app()->make(UserBrokerageServices::class);
|
|
|
- $data['broken_commission'] = $services->getUserFrozenPrice($uid);
|
|
|
- if ($data['broken_commission'] < 0)
|
|
|
- $data['broken_commission'] = 0;
|
|
|
- $data['brokerage_price'] = $user['brokerage_price'];
|
|
|
- //可提现佣金
|
|
|
- $commissionCount = bcsub((string)$data['brokerage_price'], (string)$data['broken_commission'], 2);
|
|
|
- if ($data['money'] > $commissionCount) {
|
|
|
+ // ===== 余额提现逻辑(新增) =====
|
|
|
+ /** @var UserMoneyServices $userMoneyServices */
|
|
|
+ $userMoneyServices = app()->make(UserMoneyServices::class);
|
|
|
+
|
|
|
+ // 可提现余额
|
|
|
+ $moneyCount = $user['now_money'];
|
|
|
+ if ($data['money'] > $moneyCount) {
|
|
|
throw new ApiException(400661);
|
|
|
}
|
|
|
|
|
|
- $extractPrice = $user['brokerage_price'];
|
|
|
+ $extractPrice = $user['now_money'];
|
|
|
$userExtractMinPrice = sys_config('user_extract_min_price');
|
|
|
if ($data['money'] < $userExtractMinPrice) {
|
|
|
throw new ApiException(400662, ['money' => $userExtractMinPrice]);
|
|
|
@@ -559,15 +557,20 @@ class UserExtractServices extends BaseServices
|
|
|
if ($data['money'] <= 0) {
|
|
|
throw new ApiException(400664);
|
|
|
}
|
|
|
- $data['extract_price'] = bcmul($data['money'], '1', 2);
|
|
|
+
|
|
|
+ // 计算手续费
|
|
|
+ $extract_price = bcmul($data['money'], '1', 2);
|
|
|
+ $withdrawalFeeRate = sys_config('withdrawal_fee', '0');
|
|
|
+ $extract_fee = bcmul((string)$extract_price, bcdiv((string)$withdrawalFeeRate, '100', 4), 2);
|
|
|
+
|
|
|
$insertData = [
|
|
|
'wechat_order_id' => app()->make(StoreOrderCreateServices::class)->getNewOrderId('tx'),
|
|
|
'uid' => $user['uid'],
|
|
|
'extract_type' => $data['extract_type'],
|
|
|
- 'extract_price' => $data['extract_price'],
|
|
|
- 'extract_fee' => bcmul((string)$data['extract_price'], bcdiv((string)sys_config('withdrawal_fee', '0'), '100', 4), 2),
|
|
|
+ 'extract_price' => $extract_price,
|
|
|
+ 'extract_fee' => $extract_fee,
|
|
|
'add_time' => time(),
|
|
|
- 'balance' => $user['brokerage_price'],
|
|
|
+ 'balance' => $user['now_money'],
|
|
|
'status' => 0,
|
|
|
'channel_type' => $data['channel_type']
|
|
|
];
|
|
|
@@ -580,39 +583,60 @@ class UserExtractServices extends BaseServices
|
|
|
if (isset($data['weixin'])) $insertData['wechat'] = $data['weixin'];
|
|
|
else $insertData['wechat'] = $user['nickname'];
|
|
|
$mark = '';
|
|
|
- $feeMark = sys_config('withdrawal_fee', 0) == 0 ? '' : ',手续费' . $insertData['extract_fee'] . '元';
|
|
|
+ $feeMark = $withdrawalFeeRate == 0 ? '' : ',手续费' . $extract_fee . '元';
|
|
|
if ($data['extract_type'] == 'alipay') {
|
|
|
$insertData['alipay_code'] = $data['alipay_code'];
|
|
|
$insertData['qrcode_url'] = $data['qrcode_url'];
|
|
|
$insertData['user_name'] = $data['user_name'];
|
|
|
$insertData['real_name'] = $data['user_name'];
|
|
|
- $mark = '使用支付宝提现' . $insertData['extract_price'] . '元' . $feeMark;
|
|
|
+ $mark = '使用支付宝提现' . $extract_price . '元' . $feeMark;
|
|
|
} else if ($data['extract_type'] == 'bank') {
|
|
|
- $mark = '使用银联卡' . $insertData['bank_code'] . '提现' . $insertData['extract_price'] . '元' . $feeMark;
|
|
|
+ $mark = '使用银联卡' . $insertData['bank_code'] . '提现' . $extract_price . '元' . $feeMark;
|
|
|
} else if ($data['extract_type'] == 'weixin') {
|
|
|
$insertData['user_name'] = $data['user_name'];
|
|
|
$insertData['real_name'] = $data['user_name'];
|
|
|
$insertData['qrcode_url'] = $data['qrcode_url'];
|
|
|
- $mark = '使用微信提现' . $insertData['extract_price'] . '元' . $feeMark;
|
|
|
+ $mark = '使用微信提现' . $extract_price . '元' . $feeMark;
|
|
|
if (sys_config('weixin_extract_type', 0) && $openid) {
|
|
|
- if ($data['extract_price'] < 0.1) {
|
|
|
+ if ($extract_price < 0.1) {
|
|
|
throw new ApiException(400665);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- $res1 = $this->transaction(function () use ($insertData, $data, $uid, $userService, $user, $mark) {
|
|
|
+
|
|
|
+ $res1 = $this->transaction(function () use ($insertData, $data, $uid, $userService, $user, $mark, $extract_fee, $extract_price) {
|
|
|
if (!$res1 = $this->dao->save($insertData)) {
|
|
|
throw new ApiException(410121);
|
|
|
}
|
|
|
- $balance = bcsub((string)$user['brokerage_price'], $data['extract_price'], 2) ?? 0;
|
|
|
- if (!$userService->update($uid, ['brokerage_price' => $balance], 'uid')) {
|
|
|
+ // 扣除用户余额
|
|
|
+ $balance = bcsub((string)$user['now_money'], $extract_price, 2);
|
|
|
+ if (!$userService->update($uid, ['now_money' => $balance], 'uid')) {
|
|
|
throw new ApiException(410121);
|
|
|
}
|
|
|
|
|
|
+ // ===== 保存余额记录(新增) =====
|
|
|
+ /** @var UserMoneyServices $userMoneyServices */
|
|
|
+ $userMoneyServices = app()->make(UserMoneyServices::class);
|
|
|
+ // 提现记录
|
|
|
+ $userMoneyServices->income('extract', $uid, [
|
|
|
+ 'mark' => $mark,
|
|
|
+ 'number' => $extract_price
|
|
|
+ ], $balance, $res1['id'], 0);
|
|
|
+
|
|
|
+ // 手续费记录
|
|
|
+ if ($extract_fee > 0) {
|
|
|
+ $userMoneyServices->income('extract_fee', $uid, [
|
|
|
+ 'mark' => '提现手续费',
|
|
|
+ 'number' => $extract_fee
|
|
|
+ ], $balance, $res1['id'], 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ // ===== 原佣金记录逻辑(已注释) =====
|
|
|
//保存佣金记录
|
|
|
/** @var UserBrokerageServices $userBrokerageServices */
|
|
|
- $userBrokerageServices = app()->make(UserBrokerageServices::class);
|
|
|
- $userBrokerageServices->income('extract', $uid, ['mark' => $mark, 'number' => $data['extract_price']], $balance, $res1['id']);
|
|
|
+ // $userBrokerageServices = app()->make(UserBrokerageServices::class);
|
|
|
+ // $userBrokerageServices->income('extract', $uid, ['mark' => $mark, 'number' => $extract_price], $balance, $res1['id']);
|
|
|
+
|
|
|
return $res1;
|
|
|
});
|
|
|
|
|
|
@@ -624,7 +648,7 @@ class UserExtractServices extends BaseServices
|
|
|
$systemAdmin = app()->make(SystemAdminServices::class);
|
|
|
$systemAdmin->adminNewPush();
|
|
|
//消息
|
|
|
- event('NoticeListener', [['nickname' => $user['nickname'], 'money' => $data['extract_price']], 'kefu_send_extract_application']);
|
|
|
+ event('NoticeListener', [['nickname' => $user['nickname'], 'money' => $extract_price], 'kefu_send_extract_application']);
|
|
|
|
|
|
//自定义事件-用户提现
|
|
|
event('CustomEventListener', ['user_extract', [
|