| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- /**
- * 验证AddHandler多币种资金验证修正
- *
- * 运行方式:php app/Module/Mex/Tests/verify_addhandler_fix.php
- */
- require_once __DIR__ . '/../../../../vendor/autoload.php';
- use App\Module\Fund\Enums\FUND_CURRENCY_TYPE;
- use App\Module\Mex\Logic\FundLogic;
- use App\Module\Fund\Services\FundService;
- echo "=== AddHandler多币种资金验证修正验证 ===\n\n";
- try {
- // 1. 验证默认币种设置
- echo "1. 验证默认币种设置\n";
- $defaultCurrency = FundLogic::getDefaultCurrency();
- echo " 默认币种: {$defaultCurrency->value} ({$defaultCurrency->name})\n";
-
- // 2. 验证币种映射
- echo "\n2. 验证币种映射\n";
- $availableAccount = FundLogic::getAvailableAccountType($defaultCurrency);
- $frozenAccount = FundLogic::getFrozenAccountType($defaultCurrency);
- echo " 钻石币种 - 可用账户: FUND{$availableAccount->value}, 冻结账户: FUND{$frozenAccount->value}\n";
-
- // 3. 验证精度处理
- echo "\n3. 验证精度处理\n";
- $precision = $defaultCurrency->getPrecision();
- $testAmount = 100.5;
- $storageAmount = (int)bcmul($testAmount, bcpow('10', $precision), 0);
- $displayAmount = bcdiv($storageAmount, bcpow('10', $precision), $precision);
- echo " 钻石精度: {$precision}位小数\n";
- echo " 测试金额: {$testAmount}\n";
- echo " 存储格式: {$storageAmount}\n";
- echo " 显示格式: {$displayAmount}\n";
- echo " 转换正确: " . (bccomp($displayAmount, $testAmount, $precision) === 0 ? '✅' : '❌') . "\n";
-
- // 4. 验证资金服务
- echo "\n4. 验证资金服务(测试用户ID: 1001)\n";
- $testUserId = 1001;
-
- try {
- $fundService = new FundService($testUserId, $availableAccount->value);
- $balance = $fundService->balance();
- $displayBalance = bcdiv($balance, bcpow('10', $precision), $precision);
- echo " 用户{$testUserId}的钻石余额: {$displayBalance} (原始: {$balance})\n";
- } catch (Exception $e) {
- echo " ❌ 资金服务测试失败: " . $e->getMessage() . "\n";
- }
-
- // 5. 验证买入订单资金需求计算
- echo "\n5. 验证买入订单资金需求计算\n";
- $quantity = 10;
- $price = 2.5;
- $totalCost = $quantity * $price;
- $requiredStorage = (int)bcmul($totalCost, bcpow('10', $precision), 0);
- echo " 订单: {$quantity}个 × {$price} = {$totalCost}\n";
- echo " 存储需求: {$requiredStorage}\n";
-
- // 6. 验证不同币种对比
- echo "\n6. 验证不同币种对比\n";
- $goldCurrency = FUND_CURRENCY_TYPE::JINBI;
- $goldPrecision = $goldCurrency->getPrecision();
- $goldAccount = FundLogic::getAvailableAccountType($goldCurrency);
- echo " 金币精度: {$goldPrecision}位小数, 账户: FUND{$goldAccount->value}\n";
- echo " 钻石精度: {$precision}位小数, 账户: FUND{$availableAccount->value}\n";
-
- echo "\n✅ 所有验证完成,AddHandler多币种资金验证修正成功!\n";
-
- } catch (Exception $e) {
- echo "\n❌ 验证失败: " . $e->getMessage() . "\n";
- echo "错误堆栈:\n" . $e->getTraceAsString() . "\n";
- }
- echo "\n=== 验证完成 ===\n";
|