get(); // 获取所有账户种类配置 $fundConfigs = FundConfigModel::orderBy('id')->get(); // 准备JSON数据 $jsonData = [ 'generated_ts' => time(), 'currencies' => [], 'fund' => [] ]; // 处理币种数据 foreach ($currencies as $currency) { $currencyData = [ 'id' => $currency->id, 'display_attributes' => $currency->display_attributes, 'identification' => $currency->identification, 'name' => $currency->name, 'icon' => $currency->icon, ]; // 如果有额外数据,解析并添加 if (!empty($currency->data1)) { $extraData = json_decode($currency->data1, true); if (is_array($extraData)) { $currencyData['extra_data'] = $extraData; } } $jsonData['currencies'][] = $currencyData; } // 处理账户种类数据 foreach ($fundConfigs as $fundConfig) { // 直接使用数据库中存储的currency_id字段 $fundConfigData = [ 'id' => $fundConfig->id, 'display_attributes' => $fundConfig->display_attributes, 'name' => $fundConfig->name, 'currency_id' => $fundConfig->currency_id, // 关联的币种ID ]; $jsonData['fund'][] = $fundConfigData; } return $jsonData; } catch (\Exception $e) { if (php_sapi_name() === 'cli') { echo "Error: Generate fund_currency.json failed: {$e->getMessage()}\n"; } return false; } } /** * 执行命令 * * @return int */ public function handle() { $this->info('开始生成货币配置JSON文件...'); try { $result = FundCurrencyJsonConfig::getData([], true); if ($result !== false) { $this->info('货币配置JSON文件生成成功'); $this->info('共生成 ' . count($result['currencies']) . ' 条币种配置数据'); $this->info('共生成 ' . count($result['fund']) . ' 条账户种类配置数据'); return Command::SUCCESS; } else { $this->error('生成货币配置JSON文件失败'); return Command::FAILURE; } } catch (\Exception $e) { $this->error('生成货币配置JSON文件失败: ' . $e->getMessage()); return Command::FAILURE; } } }