| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- namespace App\Console\Commands;
- use App\Module\Fund\Enums\FUND_CURRENCY_TYPE;
- use App\Module\Fund\Enums\FUND_TYPE;
- use App\Module\Fund\Services\CurrencyService;
- use App\Module\Fund\Models\FundCurrencyModel;
- use Illuminate\Console\Command;
- class VerifyFundCurrencyId extends Command
- {
- protected $signature = 'fund:verify-currency-id';
- protected $description = '验证Fund模块币种ID概念的正确性';
- public function handle()
- {
- $this->info('=== Fund模块币种ID概念验证 ===');
-
- try {
- // 测试1: 验证币种ID概念
- $this->info('1. 验证币种ID概念...');
- $this->line(' 币种ID应该是FUND_CURRENCY_TYPE枚举的value,不是数据库表的ID');
-
- foreach (FUND_CURRENCY_TYPE::cases() as $currencyType) {
- $this->line(" - {$currencyType->getCurrencyName()}: 币种ID = {$currencyType->value}");
- }
-
- // 测试2: 验证数据库表ID vs 币种ID
- $this->info('2. 验证数据库表ID vs 币种ID...');
- $currencies = FundCurrencyModel::all();
- foreach ($currencies as $currency) {
- $this->line(" - {$currency->name}: 数据库表ID = {$currency->id}, 币种ID = " . ($currency->type ? $currency->type->value : 'NULL'));
- }
-
- // 测试3: 验证账户类型到币种的映射
- $this->info('3. 验证账户类型到币种的映射...');
- foreach (FUND_TYPE::cases() as $fundType) {
- $currency = CurrencyService::getCurrencyByFundId($fundType->value);
- if ($currency) {
- $this->line(" - {$fundType->name} (账户ID:{$fundType->value}) -> 币种ID:{$currency->currencyId} ({$currency->name})");
- } else {
- $this->line(" - {$fundType->name} (账户ID:{$fundType->value}) -> 无对应币种");
- }
- }
-
- // 测试4: 验证币种一致性检查
- $this->info('4. 验证币种一致性检查...');
- $fund1 = FUND_TYPE::FUND1->value; // 金币账户
- $fund2 = FUND_TYPE::FUND2->value; // 钻石账户
- $fund3 = FUND_TYPE::FUND3->value; // 钻石冻结账户
-
- $check1 = CurrencyService::check($fund1, $fund2);
- $check2 = CurrencyService::check($fund2, $fund3);
-
- $this->line(" - 金币账户 vs 钻石账户: " . ($check1 ? '币种一致' : '币种不一致') . ' (应该不一致)');
- $this->line(" - 钻石账户 vs 钻石冻结账户: " . ($check2 ? '币种一致' : '币种不一致') . ' (应该一致)');
-
- // 测试5: 验证精度获取
- $this->info('5. 验证精度获取...');
- foreach (FUND_CURRENCY_TYPE::cases() as $currencyType) {
- $precision = CurrencyService::getCurrencyPrecision($currencyType->value);
- $this->line(" - {$currencyType->getCurrencyName()} (币种ID:{$currencyType->value}): 精度 = {$precision}");
- }
-
- // 测试6: 验证格式化显示
- $this->info('6. 验证格式化显示...');
- $testAmount = 123.456789;
- foreach (FUND_CURRENCY_TYPE::cases() as $currencyType) {
- $formatted = CurrencyService::formatAmount($testAmount, $currencyType->value);
- $this->line(" - {$currencyType->getCurrencyName()}: {$testAmount} -> {$formatted}");
- }
-
- $this->info('=== 验证完成 ===');
-
- } catch (\Exception $e) {
- $this->error("错误: " . $e->getMessage());
- $this->error("文件: " . $e->getFile() . ":" . $e->getLine());
- }
- }
- }
|