1.优化提现接口/api/finance/withdrawCreate

This commit is contained in:
2026-05-20 12:01:07 +08:00
parent 91229f4477
commit b9e4d806f7
12 changed files with 219 additions and 13 deletions

View File

@@ -826,18 +826,38 @@ class Finance extends MobileBase
}
$withdrawCoinRaw = $request->post('withdraw_coin', '');
$withdrawCoin = is_string($withdrawCoinRaw) ? trim($withdrawCoinRaw) : (is_numeric($withdrawCoinRaw) ? strval($withdrawCoinRaw) : '');
$channelCode = strtolower($this->stringParam($request->post('channel_code')));
if ($channelCode === '') {
$channelCode = strtolower($this->stringParam($request->post('pay_channel')));
}
$receiveAccount = trim(is_string($request->post('receive_account', '')) ? $request->post('receive_account', '') : '');
$receiveType = trim(is_string($request->post('receive_type', '')) ? $request->post('receive_type', '') : '');
$receiveType = strtolower($receiveType);
// DDPAY 出金Payout所需扩展字段当前仅支持 receive_type=bank
$receiverName = trim(is_string($request->post('receiver_name', '')) ? $request->post('receiver_name', '') : '');
$receiverEmail = trim(is_string($request->post('receiver_email', '')) ? $request->post('receiver_email', '') : '');
$receiverMobile = trim(is_string($request->post('receiver_mobile', '')) ? $request->post('receiver_mobile', '') : '');
$bankCode = trim(is_string($request->post('bank_code', '')) ? $request->post('bank_code', '') : '');
$bankBranch = trim(is_string($request->post('bank_branch', '')) ? $request->post('bank_branch', '') : '');
$idempotencyKey = trim(is_string($request->post('idempotency_key', '')) ? $request->post('idempotency_key', '') : '');
if ($withdrawCoin === '' || $receiveAccount === '' || $receiveType === '' || $idempotencyKey === '') {
if ($withdrawCoin === '' || $channelCode === '' || $receiveAccount === '' || $receiveType === '' || $idempotencyKey === ''
|| $receiverEmail === '' || $receiverMobile === '') {
return $this->mobileError(1001, 'Missing parameters');
}
if (!in_array($channelCode, DepositChannelLib::withdrawPayoutChannelCodes(), true)) {
return $this->mobileError(2004, 'Withdraw only supports DDPay');
}
$effectiveChannels = $this->loadDepositChannelEffective();
if (!DepositChannelLib::assertChannelEnabled($channelCode, $effectiveChannels)) {
return $this->mobileError(2004, 'Pay channel not available');
}
if (mb_strlen($receiverEmail) > 255 || !filter_var($receiverEmail, FILTER_VALIDATE_EMAIL)) {
return $this->mobileError(1001, 'Invalid receiver email');
}
if (mb_strlen($receiverMobile) > 64 || !$this->isValidReceiverMobile($receiverMobile)) {
return $this->mobileError(1001, 'Invalid receiver mobile');
}
if (mb_strlen($idempotencyKey) > 64) {
return $this->mobileError(1002, 'Idempotency key is too long');
}
@@ -970,11 +990,14 @@ class Finance extends MobileBase
'idempotency_key' => $idempotencyKey,
'user_id' => $userId,
'channel_id' => $channelId,
'pay_channel' => $channelCode,
'amount' => $withdrawCoin,
'fee' => $feeCoin,
'actual_amount' => $actualArrivalCoin,
'receive_type' => $receiveType,
'receive_account' => $receiveAccount,
'receiver_email' => $receiverEmail,
'receiver_mobile' => $receiverMobile,
'ddpay_receiver_name' => $receiverName,
'ddpay_bank_name' => $ddpayBankName,
'ddpay_bank_branch' => $bankBranch,
@@ -1044,6 +1067,9 @@ class Finance extends MobileBase
'actual_arrival_coin' => $this->amountNumber($order->actual_amount ?? '0'),
'receive_type' => is_string($order->receive_type ?? null) ? $order->receive_type : strval($order->receive_type ?? ''),
'receive_account' => is_string($order->receive_account ?? null) ? $order->receive_account : strval($order->receive_account ?? ''),
'pay_channel' => is_string($order->pay_channel ?? null) ? $order->pay_channel : strval($order->pay_channel ?? ''),
'receiver_email' => is_string($order->receiver_email ?? null) ? $order->receiver_email : strval($order->receiver_email ?? ''),
'receiver_mobile' => is_string($order->receiver_mobile ?? null) ? $order->receiver_mobile : strval($order->receiver_mobile ?? ''),
'reject_reason' => $statusCode === 2 && $remark !== '' ? $remark : null,
'create_time' => $order->create_time,
'review_time' => $order->review_time,
@@ -1249,8 +1275,10 @@ class Finance extends MobileBase
$wc = $cfg['withdraw_copy'] ?? [];
$rateMode = is_array($wc) && isset($wc['rate_mode']) && is_string($wc['rate_mode']) ? $wc['rate_mode'] : 'fixed';
$payChannels = [];
$effectiveCh = DepositChannelLib::effectiveRowsFromDb();
$withdrawPayChannels = DepositChannelLib::channelsForWithdraw($effectiveCh, $lang);
$payChannels = [];
$regCh = DepositChannelLib::codeRegistry();
foreach ($effectiveCh as $row) {
if (!is_array($row)) {
@@ -1296,6 +1324,7 @@ class Finance extends MobileBase
'banks' => $depositBanks,
],
'withdraw' => [
'pay_channels' => $withdrawPayChannels,
'banks' => $withdrawBanks,
'min_ewallet' => $minEw,
'min_bank' => $minBk,
@@ -1312,8 +1341,11 @@ class Finance extends MobileBase
// 与 DDPay 出金及 withdrawCreate 一致,不由后台开关配置
'fields' => [
'receive_type_bank_only' => true,
'require_channel_code' => true,
'require_receiver_name' => true,
'require_receive_account' => true,
'require_receiver_email' => true,
'require_receiver_mobile' => true,
'require_bank_code' => true,
'require_bank_branch' => false,
],
@@ -1365,6 +1397,23 @@ class Finance extends MobileBase
return trim($raw);
}
/**
* 收款人手机号532 位,仅允许数字与常见分隔符(+ - 空格)
*/
private function isValidReceiverMobile(string $mobile): bool
{
$len = mb_strlen($mobile);
if ($len < 5 || $len > 32) {
return false;
}
if (!preg_match('/^[0-9+\-\s]+$/', $mobile)) {
return false;
}
$digits = preg_replace('/\D/', '', $mobile);
return is_string($digits) && strlen($digits) >= 5;
}
private function loadEnabledTiers(): array
{
$row = GameConfig::where('config_key', DepositTierLib::CONFIG_KEY)->find();