| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace App\Console\Commands;
- use App\Module\Fund\Enums\FUND_TYPE;
- use App\Module\Fund\Services\FundService;
- use App\Module\Fund\Services\AccountService;
- use App\Module\Fund\Services\CurrencyService;
- use Illuminate\Console\Command;
- class VerifyFundDecimal extends Command
- {
- protected $signature = 'fund:verify-decimal';
- protected $description = '验证Fund模块小数适配';
- public function handle()
- {
- $this->info('=== Fund模块小数适配验证 ===');
-
- try {
- $testUserId = 10001;
-
- // 确保测试用户有账户
- AccountService::check4user($testUserId);
-
- // 测试1: 验证balance方法返回类型
- $this->info('1. 测试balance方法返回类型...');
- $fund = new FundService($testUserId, FUND_TYPE::FUND2->value);
- $balance = $fund->balance();
- $this->line(" 余额类型: " . gettype($balance));
- $this->line(" 余额值: " . $balance);
-
- // 测试2: 验证CurrencyService的小数处理和币种ID概念
- $this->info('2. 测试CurrencyService小数处理和币种ID概念...');
- $currency = CurrencyService::getCurrencyByFundId(FUND_TYPE::FUND2->value);
- if ($currency) {
- $this->line(" 数据库表ID: " . $currency->id);
- $this->line(" 币种ID(枚举值): " . $currency->currencyId);
- $this->line(" 币种精度: " . $currency->precision);
- // 测试精度验证(使用币种ID,不是数据库表ID)
- $testAmount = 100.123456789;
- $isValid = CurrencyService::validateAmountPrecision($testAmount, $currency->currencyId);
- $formatted = CurrencyService::formatAmountToPrecision($testAmount, $currency->currencyId);
- $this->line(" 原始金额: " . $testAmount);
- $this->line(" 精度验证: " . ($isValid ? '通过' : '失败'));
- $this->line(" 格式化后: " . $formatted);
- $this->line(" 格式化显示: " . CurrencyService::formatAmount($formatted, $currency->currencyId));
- } else {
- $this->line(" 无法获取币种信息");
- }
-
- // 测试3: 验证FundAccountDto
- $this->info('3. 测试FundAccountDto...');
- $account = $fund->getAccount();
- if ($account) {
- $this->line(" 账户余额类型: " . gettype($account->balance));
- $this->line(" 账户余额值: " . $account->balance);
- } else {
- $this->line(" 无法获取账户信息");
- }
-
- $this->info('=== 验证完成 ===');
-
- } catch (\Exception $e) {
- $this->error("错误: " . $e->getMessage());
- $this->error("文件: " . $e->getFile() . ":" . $e->getLine());
- }
- }
- }
|