feat(withdraw): 落地方案B一体化商城余额提现与手续费内扣模式,完善多端打款退款与对账闭环
这个提交包含在:
@@ -53,7 +53,10 @@ class Withdraw
|
||||
// 发起提现申请
|
||||
public function apply($params)
|
||||
{
|
||||
$walletType = $params['wallet_type'] ?? 'commission';
|
||||
$walletType = $params['wallet_type'] ?? 'money';
|
||||
if (!in_array($walletType, ['money', 'commission', 'madow'])) {
|
||||
$walletType = 'money';
|
||||
}
|
||||
$type = $params['type'] ?? '';
|
||||
$money = $params['money'] ?? 0;
|
||||
$money = (string)$money;
|
||||
@@ -66,10 +69,17 @@ class Withdraw
|
||||
$charge = bcmul($money, (string)$this->config['charge_rate'], 2);
|
||||
|
||||
// 检查提现规则
|
||||
$this->checkApply($type, $money, $charge);
|
||||
$this->checkApply($type, $money, $charge, $walletType);
|
||||
|
||||
// 获取账号信息
|
||||
$withdrawInfo = $this->getAccountInfo($type, $params);
|
||||
$withdrawInfo['wallet_type'] = $walletType;
|
||||
if ($walletType === 'money') {
|
||||
$withdrawInfo['提现资产'] = '商城余额';
|
||||
} elseif ($walletType === 'commission') {
|
||||
$withdrawInfo['提现资产'] = '佣金钱包';
|
||||
}
|
||||
|
||||
// 添加提现记录
|
||||
$withdraw = new WithdrawModel();
|
||||
$withdraw->user_id = $this->user->id;
|
||||
@@ -83,15 +93,26 @@ class Withdraw
|
||||
$withdraw->platform = request()->header('platform');
|
||||
$withdraw->save();
|
||||
|
||||
// 佣金钱包变动
|
||||
WalletService::change($this->user, 'commission', -bcadd($charge, $money, 2), 'withdraw', [
|
||||
'withdraw_id' => $withdraw->id,
|
||||
'amount' => $withdraw->amount,
|
||||
'charge_fee' => $withdraw->charge_fee,
|
||||
'charge_rate' => $withdraw->charge_rate,
|
||||
]);
|
||||
|
||||
$this->handleLog($withdraw, '用户发起提现申请', $this->user);
|
||||
// 扣减对应钱包资金(内扣模式:仅扣除提现申请本金,手续费从提现金额中内扣)
|
||||
if ($walletType === 'money') {
|
||||
WalletService::change($this->user, 'money', -$money, 'withdraw', [
|
||||
'withdraw_id' => $withdraw->id,
|
||||
'amount' => $withdraw->amount,
|
||||
'charge_fee' => $withdraw->charge_fee,
|
||||
'charge_rate' => $withdraw->charge_rate,
|
||||
'wallet_type' => 'money',
|
||||
], '申请提现扣除余额');
|
||||
$this->handleLog($withdraw, '用户发起商城余额提现申请', $this->user);
|
||||
} else {
|
||||
WalletService::change($this->user, 'commission', -$money, 'withdraw', [
|
||||
'withdraw_id' => $withdraw->id,
|
||||
'amount' => $withdraw->amount,
|
||||
'charge_fee' => $withdraw->charge_fee,
|
||||
'charge_rate' => $withdraw->charge_rate,
|
||||
'wallet_type' => 'commission',
|
||||
]);
|
||||
$this->handleLog($withdraw, '用户发起佣金提现申请', $this->user);
|
||||
}
|
||||
|
||||
return $withdraw;
|
||||
}
|
||||
@@ -272,7 +293,7 @@ class Withdraw
|
||||
'transfer_scene_id' => '1005',
|
||||
'openid' => $withdraw->withdraw_info['微信ID'] ?? '',
|
||||
'user_name' => $withdraw->withdraw_info['真实姓名'] ?? '', // 明文传参即可,sdk 会自动加密
|
||||
'transfer_amount' => $withdraw->amount,
|
||||
'transfer_amount' => bcsub((string)$withdraw->amount, (string)$withdraw->charge_fee, 2),
|
||||
'transfer_remark' => "用户[" . ($withdraw->withdraw_info['微信用户'] ?? '') . "]提现",
|
||||
'transfer_scene_report_infos' => [
|
||||
['info_type' => '岗位类型', 'info_content' => '推广专员'],
|
||||
@@ -351,7 +372,7 @@ class Withdraw
|
||||
}
|
||||
if ($withDrawStatus) {
|
||||
$withdraw->status = 2;
|
||||
$withdraw->paid_fee = $withdraw->amount;
|
||||
$withdraw->paid_fee = bcsub((string)$withdraw->amount, (string)$withdraw->charge_fee, 2);
|
||||
$withdraw->save();
|
||||
return $this->handleLog($withdraw, '已打款', $oper);
|
||||
}
|
||||
@@ -379,6 +400,9 @@ class Withdraw
|
||||
$isMadow = (isset($info['wallet_type']) && $info['wallet_type'] === 'madow')
|
||||
|| (isset($info['提现资产']) && strcasecmp($info['提现资产'], 'dmepa') === 0);
|
||||
|
||||
$isMoney = (isset($info['wallet_type']) && $info['wallet_type'] === 'money')
|
||||
|| (isset($info['提现资产']) && $info['提现资产'] === '商城余额');
|
||||
|
||||
if ($isMadow) {
|
||||
$madowRefund = $info['madow_amount'] ?? ($info['扣除DMEPA'] ?? ($info['扣除dmepa'] ?? 0));
|
||||
if (is_string($madowRefund)) {
|
||||
@@ -410,17 +434,29 @@ class Withdraw
|
||||
]);
|
||||
}
|
||||
return $this->handleLog($withdraw, '拒绝:' . $refuse_msg . ',已退还扣除的 ' . $madowRefund . ' dmepa');
|
||||
} elseif (isset($info['wallet_type']) && $info['wallet_type'] === 'commission') {
|
||||
// 仅显式标注佣金提现的退回用户佣金
|
||||
WalletService::change($this->user, 'commission', $withdraw->amount, 'withdraw_error', [
|
||||
'withdraw_id' => $withdraw->id,
|
||||
'amount' => $withdraw->amount,
|
||||
'charge_fee' => $withdraw->charge_fee,
|
||||
'charge_rate' => $withdraw->charge_rate,
|
||||
'wallet_type' => 'commission',
|
||||
]);
|
||||
|
||||
return $this->handleLog($withdraw, '拒绝:' . $refuse_msg . ',已退还提现佣金');
|
||||
} else {
|
||||
// 方案 B 一体化内扣:常规提现默认退回商城可用余额本金
|
||||
WalletService::change($this->user, 'money', $withdraw->amount, 'withdraw_error', [
|
||||
'withdraw_id' => $withdraw->id,
|
||||
'amount' => $withdraw->amount,
|
||||
'charge_fee' => $withdraw->charge_fee,
|
||||
'charge_rate' => $withdraw->charge_rate,
|
||||
'wallet_type' => 'money',
|
||||
], '提现驳回退还余额');
|
||||
|
||||
return $this->handleLog($withdraw, '拒绝:' . $refuse_msg . ',已退还提现商城余额');
|
||||
}
|
||||
|
||||
// 退回用户佣金
|
||||
WalletService::change($this->user, 'commission', bcadd($withdraw->charge_fee, $withdraw->amount, 2), 'withdraw_error', [
|
||||
'withdraw_id' => $withdraw->id,
|
||||
'amount' => $withdraw->amount,
|
||||
'charge_fee' => $withdraw->charge_fee,
|
||||
'charge_rate' => $withdraw->charge_rate,
|
||||
]);
|
||||
|
||||
return $this->handleLog($withdraw, '拒绝:' . $refuse_msg);
|
||||
}
|
||||
|
||||
|
||||
@@ -445,6 +481,9 @@ class Withdraw
|
||||
$isMadow = (isset($info['wallet_type']) && $info['wallet_type'] === 'madow')
|
||||
|| (isset($info['提现资产']) && strcasecmp($info['提现资产'], 'dmepa') === 0);
|
||||
|
||||
$isMoney = (isset($info['wallet_type']) && $info['wallet_type'] === 'money')
|
||||
|| (isset($info['提现资产']) && $info['提现资产'] === '商城余额');
|
||||
|
||||
if ($isMadow) {
|
||||
$madowRefund = $info['madow_amount'] ?? ($info['扣除DMEPA'] ?? ($info['扣除dmepa'] ?? 0));
|
||||
if (is_string($madowRefund)) {
|
||||
@@ -476,17 +515,29 @@ class Withdraw
|
||||
]);
|
||||
}
|
||||
return $this->handleLog($withdraw, '提现失败,已退还 ' . $madowRefund . ' dmepa:' . $refuse_msg);
|
||||
} elseif (isset($info['wallet_type']) && $info['wallet_type'] === 'commission') {
|
||||
// 仅显式标注佣金提现的退回用户佣金
|
||||
WalletService::change($this->user, 'commission', $withdraw->amount, 'withdraw_error', [
|
||||
'withdraw_id' => $withdraw->id,
|
||||
'amount' => $withdraw->amount,
|
||||
'charge_fee' => $withdraw->charge_fee,
|
||||
'charge_rate' => $withdraw->charge_rate,
|
||||
'wallet_type' => 'commission',
|
||||
]);
|
||||
|
||||
return $this->handleLog($withdraw, '提现失败,已退还提现佣金:' . $refuse_msg);
|
||||
} else {
|
||||
// 方案 B 一体化内扣:常规提现默认退回商城可用余额本金
|
||||
WalletService::change($this->user, 'money', $withdraw->amount, 'withdraw_error', [
|
||||
'withdraw_id' => $withdraw->id,
|
||||
'amount' => $withdraw->amount,
|
||||
'charge_fee' => $withdraw->charge_fee,
|
||||
'charge_rate' => $withdraw->charge_rate,
|
||||
'wallet_type' => 'money',
|
||||
], '提现失败退还余额');
|
||||
|
||||
return $this->handleLog($withdraw, '提现失败,已退还提现商城余额:' . $refuse_msg);
|
||||
}
|
||||
|
||||
// 退回用户佣金
|
||||
WalletService::change($this->user, 'commission', bcadd($withdraw->charge_fee, $withdraw->amount, 2), 'withdraw_error', [
|
||||
'withdraw_id' => $withdraw->id,
|
||||
'amount' => $withdraw->amount,
|
||||
'charge_fee' => $withdraw->charge_fee,
|
||||
'charge_rate' => $withdraw->charge_rate,
|
||||
]);
|
||||
|
||||
return $this->handleLog($withdraw, '提现失败,已退还提现佣金:' . $refuse_msg);
|
||||
}
|
||||
|
||||
|
||||
@@ -560,7 +611,7 @@ class Withdraw
|
||||
if ($type == 'alipay') {
|
||||
$payload = [
|
||||
'out_biz_no' => $withdraw->withdraw_sn,
|
||||
'trans_amount' => $withdraw->amount,
|
||||
'trans_amount' => bcsub((string)$withdraw->amount, (string)$withdraw->charge_fee, 2),
|
||||
'product_code' => 'TRANS_ACCOUNT_NO_PWD',
|
||||
'biz_scene' => 'DIRECT_TRANSFER',
|
||||
// 'order_title' => '余额提现到',
|
||||
@@ -611,7 +662,7 @@ class Withdraw
|
||||
|
||||
|
||||
// 提现条件检查
|
||||
private function checkApply($type, $money, $charge)
|
||||
private function checkApply($type, $money, $charge, $walletType = 'money')
|
||||
{
|
||||
if (isset($this->config['status']) && intval($this->config['status']) === 0) {
|
||||
throw new ShoproException('系统提现功能已关闭');
|
||||
@@ -638,9 +689,19 @@ class Withdraw
|
||||
throw new ShoproException('提现金额不能大于 ' . $this->config['max_amount'] . '元');
|
||||
}
|
||||
|
||||
if ($walletType === 'money') {
|
||||
if (bccomp((string)($this->user->money ?? 0), (string)$money, 2) < 0) {
|
||||
throw new ShoproException('商城可用余额不足');
|
||||
}
|
||||
} else {
|
||||
if (bccomp((string)($this->user->commission ?? 0), (string)$money, 2) < 0) {
|
||||
throw new ShoproException('可提现佣金不足');
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->user->commission < bcadd($charge, $money, 2)) {
|
||||
throw new ShoproException('可提现佣金不足');
|
||||
$realAmount = bcsub($money, $charge, 2);
|
||||
if (bccomp($realAmount, '0.00', 2) <= 0) {
|
||||
throw new ShoproException('扣除手续费后实际到账金额必须大于0元');
|
||||
}
|
||||
|
||||
// 检查最大提现次数
|
||||
|
||||
在新工单中引用
屏蔽一个用户