refactor: 使用FileManager统一文件操作

将分散在各处的文件操作统一封装到FileManager工具类中,包括文件读写、目录创建、JSON处理等操作
This commit is contained in:
LL
2025-12-12 14:22:40 +08:00
parent fbf39f81c2
commit 6c168246ca
6 changed files with 81 additions and 78 deletions

View File

@@ -19,22 +19,22 @@ class FundAdminAPI extends ApiBase {
FileManager::ensureDirExists('data');
// 初始化配置文件(如果不存在)
if (!file_exists($this->configFile)) {
if (!FileManager::fileExists($this->configFile)) {
$this->initConfig();
}
// 初始化操作日志文件(如果不存在)
if (!file_exists($this->operationFile)) {
if (!FileManager::fileExists($this->operationFile)) {
$this->initOperationLog();
}
// 初始化基金名称文件(如果不存在)
if (!file_exists($this->fundNamesFile)) {
if (!FileManager::fileExists($this->fundNamesFile)) {
$this->initFundNames();
}
// 初始化推荐基金文件(如果不存在)
if (!file_exists($this->recommendedFundsFile)) {
if (!FileManager::fileExists($this->recommendedFundsFile)) {
$this->initRecommendedFunds();
}
}
@@ -142,7 +142,7 @@ class FundAdminAPI extends ApiBase {
* 加载基金名称映射
*/
private function loadFundNames() {
if (!file_exists($this->fundNamesFile)) {
if (!FileManager::fileExists($this->fundNamesFile)) {
$this->initFundNames();
}
@@ -719,7 +719,7 @@ class FundAdminAPI extends ApiBase {
]
]);
$response = file_get_contents($apiUrl, false, $context);
$response = FileManager::loadFile($apiUrl);
if ($response) {
// 处理不同API的响应格式