1.新增获取充值/提现配置接口/api/finance/depositWithdrawConfig

2.优化充值和提现方式
This commit is contained in:
2026-04-23 10:15:01 +08:00
parent 0f28c0fd2a
commit aa1299c018
55 changed files with 901 additions and 750 deletions

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace app\common\library\finance;
use app\common\service\GameHotDataRedis;
use support\think\Db;
/**
* 提现打码量(流水)门槛工具库
@@ -25,16 +26,16 @@ final class WithdrawFlow
{
public const CONFIG_KEY = 'withdraw_bet_flow_ratio';
public const DEFAULT_RATIO = '1.0000';
public const DEFAULT_RATIO = '1.00';
/** 当 ratio = 0不限打码max_withdraw_by_flow 用此哨兵表示"无限"。14 位整数位足够覆盖任何业务金额。 */
public const UNLIMITED_FLOW = '99999999999999.9999';
public const UNLIMITED_FLOW = '99999999999999.99';
/** 单用户最多允许同时存在的「待审核」(withdraw_order.status=0) 提现订单数。 */
public const MAX_PENDING_WITHDRAW = 3;
/**
* 读取当前打码倍数(字符串 4 位小数,至少 0
* 读取当前打码倍数(字符串 2 位小数,至少 0
*/
public static function ratio(): string
{
@@ -46,32 +47,32 @@ final class WithdrawFlow
if (!is_string($val) || trim($val) === '' || !is_numeric(trim($val))) {
return self::DEFAULT_RATIO;
}
$normalized = bcadd(trim($val), '0', 4);
if (bccomp($normalized, '0', 4) < 0) {
return '0.0000';
$normalized = bcadd(trim($val), '0', 2);
if (bccomp($normalized, '0', 2) < 0) {
return '0.00';
}
return $normalized;
}
/**
* 归一化金额字段到 4 位小数字符串,非法输入返回 '0.0000'
* 归一化金额字段到 2 位小数字符串,非法输入返回 '0.00'
*/
public static function amountString($raw): string
{
if ($raw === null || $raw === '') {
return '0.0000';
return '0.00';
}
if (is_string($raw)) {
$s = trim($raw);
} elseif (is_int($raw) || is_float($raw)) {
$s = strval($raw);
} else {
return '0.0000';
return '0.00';
}
if (!is_numeric($s)) {
return '0.0000';
return '0.00';
}
return bcadd($s, '0', 4);
return bcadd($s, '0', 2);
}
/**
@@ -108,28 +109,28 @@ final class WithdrawFlow
$withdraw = self::amountString($userSnapshot['total_withdraw_coin'] ?? '0');
$flow = self::amountString($userSnapshot['bet_flow_coin'] ?? '0');
$net = bcsub($deposit, $withdraw, 4);
if (bccomp($net, '0', 4) < 0) {
$net = '0.0000';
$net = bcsub($deposit, $withdraw, 2);
if (bccomp($net, '0', 2) < 0) {
$net = '0.00';
}
$ratio = self::ratio();
$required = bcmul($net, $ratio, 4);
$remaining = bcsub($required, $flow, 4);
if (bccomp($remaining, '0', 4) < 0) {
$remaining = '0.0000';
$required = bcmul($net, $ratio, 2);
$remaining = bcsub($required, $flow, 2);
if (bccomp($remaining, '0', 2) < 0) {
$remaining = '0.00';
}
$eligible = bccomp($flow, $required, 4) >= 0;
$eligible = bccomp($flow, $required, 2) >= 0;
// max_withdraw_by_flow = max(0, bet_flow_coin / ratio - total_withdraw_coin)
$unlimited = bccomp($ratio, '0', 4) === 0;
$unlimited = bccomp($ratio, '0', 2) === 0;
if ($unlimited) {
$maxByFlow = self::UNLIMITED_FLOW;
} else {
$lifetime = bcdiv($flow, $ratio, 4);
$maxByFlow = bcsub($lifetime, $withdraw, 4);
if (bccomp($maxByFlow, '0', 4) < 0) {
$maxByFlow = '0.0000';
$lifetime = bcdiv($flow, $ratio, 2);
$maxByFlow = bcsub($lifetime, $withdraw, 2);
if (bccomp($maxByFlow, '0', 2) < 0) {
$maxByFlow = '0.00';
}
}
@@ -147,18 +148,18 @@ final class WithdrawFlow
/**
* 取单笔最大可提现额 = min(coin_balance, max_withdraw_by_flow)。
* 返回值为 4 位小数字符串,已与 ratio=0不限逻辑兼容。
* 返回值为 2 位小数字符串,已与 ratio=0不限逻辑兼容。
*/
public static function maxWithdrawable(string $coinBalance, array $flowStatus): string
{
$coin = self::amountString($coinBalance);
if (bccomp($coin, '0', 4) < 0) {
$coin = '0.0000';
if (bccomp($coin, '0', 2) < 0) {
$coin = '0.00';
}
if (!empty($flowStatus['flow_unlimited'])) {
return $coin;
}
$byFlow = self::amountString($flowStatus['max_withdraw_by_flow'] ?? '0');
return bccomp($coin, $byFlow, 4) <= 0 ? $coin : $byFlow;
return bccomp($coin, $byFlow, 2) <= 0 ? $coin : $byFlow;
}
}