argument('user_id'); $this->info("开始检查用户 {$userId} 的资金日志..."); try { // 获取用户所有日志 $logs = FundLogModel::where('user_id', $userId) ->orderBy('id', 'asc') ->get(); if ($logs->isEmpty()) { $this->warn("该用户没有资金日志记录"); return 0; } $this->info("共发现 {$logs->count()} 条日志记录"); $this->newLine(); $bar = $this->output->createProgressBar($logs->count()); $bar->start(); $prevHash = ''; $errors = []; foreach ($logs as $log) { // 验证哈希值 $currentHash = $log->generateHash(); if ($currentHash !== $log->hash) { $errors[] = [ 'id' => $log->id, 'type' => 'hash', 'message' => "日志ID {$log->id} 的哈希值不匹配" ]; } // 验证链式哈希 if ($log->prev_hash !== $prevHash) { $errors[] = [ 'id' => $log->id, 'type' => 'chain', 'message' => "日志ID {$log->id} 的前序哈希不匹配" ]; } $prevHash = $log->hash; $bar->advance(); } $bar->finish(); $this->newLine(2); if (empty($errors)) { $this->info("✓ 验证通过!所有日志记录完整性检查通过。"); return 0; } $this->error("× 发现以下问题:"); foreach ($errors as $error) { $this->line("- {$error['message']}"); } return 1; } catch (\Exception $e) { $this->error("检查过程中发生错误:" . $e->getMessage()); return 1; } } }