|
|
@@ -0,0 +1,191 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+/**
|
|
|
+ * 测试 TransferFeeDto 优化功能
|
|
|
+ *
|
|
|
+ * 验证 calculateWithdrawFee 和 calculateRechargeFee 方法返回 DTO 对象的功能
|
|
|
+ */
|
|
|
+
|
|
|
+require_once __DIR__ . '/vendor/autoload.php';
|
|
|
+
|
|
|
+// 初始化Laravel应用
|
|
|
+$app = require_once __DIR__ . '/bootstrap/app.php';
|
|
|
+$app->make(\Illuminate\Contracts\Console\Kernel::class)->bootstrap();
|
|
|
+
|
|
|
+use App\Module\Transfer\Services\TransferThirdPartyService;
|
|
|
+use App\Module\Transfer\Dtos\TransferFeeDto;
|
|
|
+
|
|
|
+echo "=== Transfer Fee DTO 测试开始 ===\n\n";
|
|
|
+
|
|
|
+// 测试数据
|
|
|
+$testCases = [
|
|
|
+ [
|
|
|
+ 'name' => '正常提现手续费计算',
|
|
|
+ 'third_party_app_id' => 11, // URS应用ID
|
|
|
+ 'amount' => '100.0000',
|
|
|
+ 'method' => 'calculateWithdrawFee'
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'name' => '正常充值手续费计算',
|
|
|
+ 'third_party_app_id' => 11, // URS应用ID
|
|
|
+ 'amount' => '100.0000',
|
|
|
+ 'method' => 'calculateRechargeFee'
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'name' => '不存在的应用ID - 提现',
|
|
|
+ 'third_party_app_id' => 999,
|
|
|
+ 'amount' => '100.0000',
|
|
|
+ 'method' => 'calculateWithdrawFee'
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'name' => '不存在的应用ID - 充值',
|
|
|
+ 'third_party_app_id' => 999,
|
|
|
+ 'amount' => '100.0000',
|
|
|
+ 'method' => 'calculateRechargeFee'
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'name' => '小额提现测试',
|
|
|
+ 'third_party_app_id' => 11,
|
|
|
+ 'amount' => '1.0000',
|
|
|
+ 'method' => 'calculateWithdrawFee'
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'name' => '大额提现测试',
|
|
|
+ 'third_party_app_id' => 11,
|
|
|
+ 'amount' => '10000.0000',
|
|
|
+ 'method' => 'calculateWithdrawFee'
|
|
|
+ ]
|
|
|
+];
|
|
|
+
|
|
|
+foreach ($testCases as $index => $testCase) {
|
|
|
+ echo "测试 " . ($index + 1) . ": {$testCase['name']}\n";
|
|
|
+ echo "应用ID: {$testCase['third_party_app_id']}, 金额: {$testCase['amount']}, 方法: {$testCase['method']}\n";
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 调用对应的方法
|
|
|
+ if ($testCase['method'] === 'calculateWithdrawFee') {
|
|
|
+ $result = TransferThirdPartyService::calculateWithdrawFee(
|
|
|
+ $testCase['third_party_app_id'],
|
|
|
+ $testCase['amount']
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ $result = TransferThirdPartyService::calculateRechargeFee(
|
|
|
+ $testCase['third_party_app_id'],
|
|
|
+ $testCase['amount']
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证返回类型
|
|
|
+ if (!($result instanceof TransferFeeDto)) {
|
|
|
+ echo "❌ 错误: 返回类型不是 TransferFeeDto,实际类型: " . get_class($result) . "\n";
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ echo "✅ 返回类型正确: TransferFeeDto\n";
|
|
|
+
|
|
|
+ // 显示DTO属性
|
|
|
+ echo "DTO 属性:\n";
|
|
|
+ echo " - 原始金额: {$result->originalAmount}\n";
|
|
|
+ echo " - 手续费率: {$result->feeRate} ({$result->getFeeRatePercent()})\n";
|
|
|
+ echo " - 手续费金额: {$result->feeAmount}\n";
|
|
|
+ echo " - 实际到账金额: {$result->actualAmount}\n";
|
|
|
+ echo " - 是否有错误: " . ($result->hasError ? '是' : '否') . "\n";
|
|
|
+
|
|
|
+ if ($result->hasError) {
|
|
|
+ echo " - 错误信息: {$result->errorMessage}\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ echo " - 是否有手续费: " . ($result->hasFee() ? '是' : '否') . "\n";
|
|
|
+ echo " - 格式化手续费信息: {$result->getFormattedFeeInfo()}\n";
|
|
|
+
|
|
|
+ // 测试向后兼容性 - toLegacyArray 方法
|
|
|
+ echo "\n向后兼容性测试:\n";
|
|
|
+ $legacyArray = $result->toLegacyArray();
|
|
|
+ echo "Legacy Array 格式:\n";
|
|
|
+ foreach ($legacyArray as $key => $value) {
|
|
|
+ echo " - {$key}: {$value}\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ // 测试 toArray 方法
|
|
|
+ echo "\n完整 Array 格式:\n";
|
|
|
+ $fullArray = $result->toArray();
|
|
|
+ foreach ($fullArray as $key => $value) {
|
|
|
+ if (is_array($value)) {
|
|
|
+ echo " - {$key}: " . json_encode($value) . "\n";
|
|
|
+ } else {
|
|
|
+ echo " - {$key}: {$value}\n";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 测试 fromLegacyArray 静态方法
|
|
|
+ echo "\n测试 fromLegacyArray 静态方法:\n";
|
|
|
+ $recreatedDto = TransferFeeDto::fromLegacyArray($legacyArray, $testCase['amount']);
|
|
|
+ echo "重新创建的DTO是否与原DTO相等: " .
|
|
|
+ ($recreatedDto->feeAmount === $result->feeAmount &&
|
|
|
+ $recreatedDto->actualAmount === $result->actualAmount ? '是' : '否') . "\n";
|
|
|
+
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ echo "❌ 异常: " . $e->getMessage() . "\n";
|
|
|
+ echo "堆栈跟踪: " . $e->getTraceAsString() . "\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ echo "\n" . str_repeat("-", 80) . "\n\n";
|
|
|
+}
|
|
|
+
|
|
|
+// 测试URS余额检查功能的兼容性
|
|
|
+echo "=== URS余额检查兼容性测试 ===\n\n";
|
|
|
+
|
|
|
+try {
|
|
|
+ // 模拟URS余额检查中的调用
|
|
|
+ $thirdPartyAppId = 11; // URS应用ID
|
|
|
+ $amount = '50.0000';
|
|
|
+
|
|
|
+ echo "模拟URS余额检查调用:\n";
|
|
|
+ echo "应用ID: {$thirdPartyAppId}, 金额: {$amount}\n";
|
|
|
+
|
|
|
+ $feeDto = TransferThirdPartyService::calculateWithdrawFee($thirdPartyAppId, $amount);
|
|
|
+
|
|
|
+ echo "返回的DTO类型: " . get_class($feeDto) . "\n";
|
|
|
+ echo "是否有错误: " . ($feeDto->hasError ? '是' : '否') . "\n";
|
|
|
+
|
|
|
+ if ($feeDto->hasError) {
|
|
|
+ echo "错误信息: {$feeDto->errorMessage}\n";
|
|
|
+
|
|
|
+ // 模拟URS余额检查中的错误处理
|
|
|
+ $response = [
|
|
|
+ 'check' => false,
|
|
|
+ 'diamond_balance' => '0.0000',
|
|
|
+ 'principal_total' => $amount,
|
|
|
+ 'fee_total' => '0.0000',
|
|
|
+ 'required_total' => $amount,
|
|
|
+ 'message' => $feeDto->errorMessage
|
|
|
+ ];
|
|
|
+
|
|
|
+ echo "URS错误响应:\n";
|
|
|
+ echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n";
|
|
|
+ } else {
|
|
|
+ echo "手续费金额: {$feeDto->feeAmount}\n";
|
|
|
+
|
|
|
+ // 模拟URS余额检查中的成功处理
|
|
|
+ $principalAmount = $amount;
|
|
|
+ $feeAmount = $feeDto->feeAmount;
|
|
|
+ $requiredTotal = bcadd($principalAmount, $feeAmount, 4);
|
|
|
+
|
|
|
+ $response = [
|
|
|
+ 'check' => true, // 这里假设余额充足
|
|
|
+ 'diamond_balance' => '1000.0000', // 假设余额
|
|
|
+ 'principal_total' => $principalAmount,
|
|
|
+ 'fee_total' => $feeAmount,
|
|
|
+ 'required_total' => $requiredTotal,
|
|
|
+ 'message' => '余额充足,允许提取'
|
|
|
+ ];
|
|
|
+
|
|
|
+ echo "URS成功响应:\n";
|
|
|
+ echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n";
|
|
|
+ }
|
|
|
+
|
|
|
+} catch (\Exception $e) {
|
|
|
+ echo "❌ URS兼容性测试异常: " . $e->getMessage() . "\n";
|
|
|
+}
|
|
|
+
|
|
|
+echo "\n=== 测试完成 ===\n";
|