feat(withdraw): 后台支持提现总开关与方式过滤并升级钱包与提现页面体验
这个提交包含在:
@@ -69,6 +69,7 @@ class Index extends Common
|
||||
'bind_mobile' => $platformConfig['bind_mobile'] ?? 0,
|
||||
'payment' => $platformConfig['payment']['methods'],
|
||||
'recharge_payment' => sheep_config('shop.recharge_withdraw.recharge.methods'), // 充值支持的支付方式
|
||||
'withdraw_status' => (bool)(intval(sheep_config('shop.recharge_withdraw.withdraw.status', !empty(sheep_config('shop.recharge_withdraw.withdraw.methods', [])) ? 1 : 0)) && !empty(sheep_config('shop.recharge_withdraw.withdraw.methods', []))),
|
||||
'share' => $platformConfig['share'],
|
||||
],
|
||||
'template' => $template,
|
||||
|
||||
@@ -13,6 +13,10 @@ use app\admin\model\shopro\ThirdOauth;
|
||||
use addons\shopro\service\Wallet as WalletService;
|
||||
use addons\shopro\library\pay\PayService;
|
||||
use app\admin\model\shopro\user\User;
|
||||
use addons\shopro\service\partner\PartnerConfig;
|
||||
use addons\shopro\service\partner\RateService;
|
||||
use addons\shopro\service\partner\PartnerRewardService;
|
||||
use app\admin\model\shopro\commission\Agent as AgentModel;
|
||||
|
||||
class Withdraw
|
||||
{
|
||||
@@ -33,6 +37,10 @@ class Withdraw
|
||||
// 提现规则
|
||||
$config = sheep_config('shop.recharge_withdraw.withdraw');
|
||||
|
||||
// 提现开关与是否允许提现综合状态
|
||||
$config['status'] = isset($config['status']) ? intval($config['status']) : (!empty($config['methods']) ? 1 : 0);
|
||||
$config['is_withdraw_open'] = (bool)($config['status'] === 1 && !empty($config['methods']));
|
||||
|
||||
$config['min_amount'] = $config['min_amount'] == 0 ? $config['min_amount'] : number_format(floatval($config['min_amount']), 2, '.', '');
|
||||
$config['max_amount'] = $config['max_amount'] == 0 ? $config['max_amount'] : number_format(floatval($config['max_amount']), 2, '.', '');
|
||||
$config['charge_rate_format'] = round(floatval($config['charge_rate']), 1); // 1 位小数
|
||||
@@ -45,10 +53,15 @@ class Withdraw
|
||||
// 发起提现申请
|
||||
public function apply($params)
|
||||
{
|
||||
$type = $params['type'];
|
||||
$walletType = $params['wallet_type'] ?? 'commission';
|
||||
$type = $params['type'] ?? '';
|
||||
$money = $params['money'] ?? 0;
|
||||
$money = (string)$money;
|
||||
|
||||
if ($walletType === 'madow') {
|
||||
return $this->applyMadow($params, $type, $money);
|
||||
}
|
||||
|
||||
// 手续费
|
||||
$charge = bcmul($money, (string)$this->config['charge_rate'], 2);
|
||||
|
||||
@@ -83,6 +96,104 @@ class Withdraw
|
||||
return $withdraw;
|
||||
}
|
||||
|
||||
// 发起 dmepa 提现申请
|
||||
protected function applyMadow($params, $type, $money)
|
||||
{
|
||||
if (!PartnerConfig::isMadowWithdrawEnabled()) {
|
||||
throw new ShoproException('dmepa提现功能暂未开启');
|
||||
}
|
||||
|
||||
if ($type !== 'bank') {
|
||||
throw new ShoproException('dmepa提现仅支持银行卡转账');
|
||||
}
|
||||
|
||||
if (floatval($money) <= 0) {
|
||||
throw new ShoproException('请输入正确的提现金额');
|
||||
}
|
||||
|
||||
$minAmount = PartnerConfig::madowWithdrawMin();
|
||||
if ($minAmount > 0 && floatval($money) < $minAmount) {
|
||||
throw new ShoproException('提现金额不能少于 ' . $minAmount . '元');
|
||||
}
|
||||
|
||||
$rate = (new RateService())->currentRate();
|
||||
if ($rate <= 0) {
|
||||
throw new ShoproException('当前dmepa暂无有效市值汇率,无法发起提现');
|
||||
}
|
||||
|
||||
// 计算需扣除的 dmepa = 金额 / 汇率
|
||||
$rateStr = number_format($rate, 12, '.', '');
|
||||
$deductMadow = function_exists('bcdiv') ? bcdiv($money, $rateStr, 4) : number_format(floatval($money) / $rate, 4, '.', '');
|
||||
if (floatval($deductMadow) <= 0) {
|
||||
throw new ShoproException('折算dmepa数量不足');
|
||||
}
|
||||
|
||||
// 检查合伙人资产
|
||||
$agent = AgentModel::where('user_id', $this->user->id)->lock(true)->find();
|
||||
if (!$agent) {
|
||||
throw new ShoproException('未找到您的合伙资产账户');
|
||||
}
|
||||
|
||||
$currentMadow = strval($agent->madow ?? 0);
|
||||
if (bccomp($currentMadow, $deductMadow, 4) < 0) {
|
||||
throw new ShoproException('持仓dmepa不足,无法提现');
|
||||
}
|
||||
|
||||
// 校验银行卡信息
|
||||
$withdrawInfo = $this->getAccountInfo($type, $params);
|
||||
$rateClean = rtrim(rtrim(number_format((float)$rate, 12, '.', ''), '0'), '.');
|
||||
$moneyClean = number_format((float)$money, 2, '.', '');
|
||||
$withdrawInfo['提现资产'] = 'DMEPA';
|
||||
$withdrawInfo['扣除DMEPA'] = $deductMadow . ' DMEPA';
|
||||
$withdrawInfo['市值汇率'] = '1 DMEPA ≈ ' . $rateClean . ' 元';
|
||||
$withdrawInfo['换算市值'] = $moneyClean . ' 元';
|
||||
$withdrawInfo['wallet_type'] = 'madow';
|
||||
$withdrawInfo['madow_amount'] = $deductMadow;
|
||||
$withdrawInfo['rate'] = $rate;
|
||||
|
||||
// 扣减 dmepa
|
||||
$agent->setDec('madow', $deductMadow);
|
||||
|
||||
// 创建提现记录
|
||||
$withdraw = new WithdrawModel();
|
||||
$withdraw->user_id = $this->user->id;
|
||||
$withdraw->amount = $money;
|
||||
$withdraw->charge_fee = 0;
|
||||
$withdraw->charge_rate = 0;
|
||||
$withdraw->withdraw_sn = get_sn($this->user->id, 'W');
|
||||
$withdraw->withdraw_type = 'bank';
|
||||
$withdraw->withdraw_info = $withdrawInfo;
|
||||
$withdraw->status = 0;
|
||||
$withdraw->platform = request()->header('platform');
|
||||
$withdraw->save();
|
||||
|
||||
// 记录合伙人流水
|
||||
PartnerRewardService::write([
|
||||
'order_id' => -$withdraw->id,
|
||||
'buyer_id' => $this->user->id,
|
||||
'user_id' => $this->user->id,
|
||||
'role' => 'partner',
|
||||
'reward_type' => 'madow_withdraw',
|
||||
'amount' => -$money,
|
||||
'madow' => -$deductMadow,
|
||||
'base_amount' => $money,
|
||||
'rate' => $rate,
|
||||
'ext' => [
|
||||
'withdraw_sn' => $withdraw->withdraw_sn,
|
||||
'withdraw_id' => $withdraw->id,
|
||||
'deduct_madow' => $deductMadow,
|
||||
'cny_amount' => $money,
|
||||
'rate' => $rate,
|
||||
],
|
||||
'settle_date' => date('Y-m-d'),
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
$this->handleLog($withdraw, '用户发起dmepa提现申请(扣除 ' . $deductMadow . ' dmepa)', $this->user);
|
||||
|
||||
return $withdraw;
|
||||
}
|
||||
|
||||
|
||||
// 继续提现
|
||||
public function retry($params)
|
||||
@@ -256,6 +367,51 @@ class Withdraw
|
||||
$withdraw->status = -1;
|
||||
$withdraw->save();
|
||||
|
||||
if (!$this->user && !empty($withdraw->user_id)) {
|
||||
$this->user = User::get($withdraw->user_id);
|
||||
}
|
||||
$userId = $this->user ? $this->user->id : intval($withdraw->user_id);
|
||||
|
||||
$info = $withdraw->withdraw_info;
|
||||
if (is_string($info)) {
|
||||
$info = json_decode($info, true) ?: [];
|
||||
}
|
||||
$isMadow = (isset($info['wallet_type']) && $info['wallet_type'] === 'madow')
|
||||
|| (isset($info['提现资产']) && strcasecmp($info['提现资产'], 'dmepa') === 0);
|
||||
|
||||
if ($isMadow) {
|
||||
$madowRefund = $info['madow_amount'] ?? ($info['扣除DMEPA'] ?? ($info['扣除dmepa'] ?? 0));
|
||||
if (is_string($madowRefund)) {
|
||||
$madowRefund = trim(str_ireplace(['dmepa', ' '], '', $madowRefund));
|
||||
}
|
||||
if (floatval($madowRefund) > 0) {
|
||||
$agent = AgentModel::where('user_id', $userId)->lock(true)->find();
|
||||
if ($agent) {
|
||||
$agent->setInc('madow', $madowRefund);
|
||||
}
|
||||
PartnerRewardService::write([
|
||||
'order_id' => -$withdraw->id,
|
||||
'buyer_id' => $userId,
|
||||
'user_id' => $userId,
|
||||
'role' => 'partner',
|
||||
'reward_type' => 'madow_withdraw_refund',
|
||||
'amount' => $withdraw->amount,
|
||||
'madow' => $madowRefund,
|
||||
'base_amount' => $withdraw->amount,
|
||||
'rate' => $info['rate'] ?? 0,
|
||||
'ext' => [
|
||||
'withdraw_sn' => $withdraw->withdraw_sn,
|
||||
'withdraw_id' => $withdraw->id,
|
||||
'refund_madow' => $madowRefund,
|
||||
'refuse_msg' => $refuse_msg,
|
||||
],
|
||||
'settle_date' => date('Y-m-d'),
|
||||
'status' => 1,
|
||||
]);
|
||||
}
|
||||
return $this->handleLog($withdraw, '拒绝:' . $refuse_msg . ',已退还扣除的 ' . $madowRefund . ' dmepa');
|
||||
}
|
||||
|
||||
// 退回用户佣金
|
||||
WalletService::change($this->user, 'commission', bcadd($withdraw->charge_fee, $withdraw->amount, 2), 'withdraw_error', [
|
||||
'withdraw_id' => $withdraw->id,
|
||||
@@ -277,6 +433,51 @@ class Withdraw
|
||||
$withdraw->status = $status;
|
||||
$withdraw->save();
|
||||
|
||||
if (!$this->user && !empty($withdraw->user_id)) {
|
||||
$this->user = User::get($withdraw->user_id);
|
||||
}
|
||||
$userId = $this->user ? $this->user->id : intval($withdraw->user_id);
|
||||
|
||||
$info = $withdraw->withdraw_info;
|
||||
if (is_string($info)) {
|
||||
$info = json_decode($info, true) ?: [];
|
||||
}
|
||||
$isMadow = (isset($info['wallet_type']) && $info['wallet_type'] === 'madow')
|
||||
|| (isset($info['提现资产']) && strcasecmp($info['提现资产'], 'dmepa') === 0);
|
||||
|
||||
if ($isMadow) {
|
||||
$madowRefund = $info['madow_amount'] ?? ($info['扣除DMEPA'] ?? ($info['扣除dmepa'] ?? 0));
|
||||
if (is_string($madowRefund)) {
|
||||
$madowRefund = trim(str_ireplace(['dmepa', ' '], '', $madowRefund));
|
||||
}
|
||||
if (floatval($madowRefund) > 0) {
|
||||
$agent = AgentModel::where('user_id', $userId)->lock(true)->find();
|
||||
if ($agent) {
|
||||
$agent->setInc('madow', $madowRefund);
|
||||
}
|
||||
PartnerRewardService::write([
|
||||
'order_id' => -$withdraw->id,
|
||||
'buyer_id' => $userId,
|
||||
'user_id' => $userId,
|
||||
'role' => 'partner',
|
||||
'reward_type' => 'madow_withdraw_refund',
|
||||
'amount' => $withdraw->amount,
|
||||
'madow' => $madowRefund,
|
||||
'base_amount' => $withdraw->amount,
|
||||
'rate' => $info['rate'] ?? 0,
|
||||
'ext' => [
|
||||
'withdraw_sn' => $withdraw->withdraw_sn,
|
||||
'withdraw_id' => $withdraw->id,
|
||||
'refund_madow' => $madowRefund,
|
||||
'fail_msg' => $refuse_msg,
|
||||
],
|
||||
'settle_date' => date('Y-m-d'),
|
||||
'status' => 1,
|
||||
]);
|
||||
}
|
||||
return $this->handleLog($withdraw, '提现失败,已退还 ' . $madowRefund . ' dmepa:' . $refuse_msg);
|
||||
}
|
||||
|
||||
// 退回用户佣金
|
||||
WalletService::change($this->user, 'commission', bcadd($withdraw->charge_fee, $withdraw->amount, 2), 'withdraw_error', [
|
||||
'withdraw_id' => $withdraw->id,
|
||||
@@ -412,6 +613,14 @@ class Withdraw
|
||||
// 提现条件检查
|
||||
private function checkApply($type, $money, $charge)
|
||||
{
|
||||
if (isset($this->config['status']) && intval($this->config['status']) === 0) {
|
||||
throw new ShoproException('系统提现功能已关闭');
|
||||
}
|
||||
|
||||
if (empty($this->config['methods'])) {
|
||||
throw new ShoproException('暂未开启任何提现方式');
|
||||
}
|
||||
|
||||
if (!in_array($type, $this->config['methods'])) {
|
||||
throw new ShoproException('暂不支持该提现方式');
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户