argument('month')); $mapping = (string) $this->argument('mapping'); try { $snapshot = $builder->build($month, $mapping); $path = (string) ($this->option('output') ?: storage_path( 'app/local/performance-details/default-compensation/' . $month . '.json' )); $directory = dirname($path); if (! is_dir($directory) && ! mkdir($directory, 0775, true) && ! is_dir($directory)) { throw new \RuntimeException('无法创建快照目录:' . $directory); } $temporary = $path . '.tmp'; $json = json_encode($snapshot, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); if ($json === false || file_put_contents($temporary, $json, LOCK_EX) === false) { throw new \RuntimeException('无法写入本地快照。'); } rename($temporary, $path); $this->info('本地预览快照已生成:' . $path); $this->line('映射条数:' . $snapshot['mapping_rows']); $this->line('关联行数:' . count($snapshot['amounts'])); $this->line('金额合计:' . number_format((float) $snapshot['total'], 2, '.', '')); $this->line('耗时:' . number_format((hrtime(true) - $startedAt) / 1e6, 0) . ' ms'); $this->line('PHP 峰值内存:' . number_format(memory_get_peak_usage(true) / 1024 / 1024, 1) . ' MB'); foreach ($snapshot['source_stats'] as $platform => $stats) { $this->line(sprintf( ' %s:账单行 %d,金额 %s', $platform, $stats['rows'], number_format((float) $stats['amount'], 2, '.', ''), )); } return self::SUCCESS; } catch (Throwable $exception) { $this->error($exception->getMessage()); return self::FAILURE; } } }