option('month'); if (! preg_match('/^20\d{2}-(0[1-9]|1[0-2])$/', $month)) { $this->error('--month 要写成 2026-10 这样'); return self::FAILURE; } $blocks = json_decode((string) @file_get_contents((string) $this->argument('file')), true); if (! is_array($blocks)) { $this->error('读不了 JSON 文件'); return self::FAILURE; } $blocks = array_values(array_filter(array_map(static fn ($b): ?array => is_array($b) && isset($b['title'], $b['headers'], $b['labels']) && is_array($b['headers']) && is_array($b['labels']) ? ['title' => (string) $b['title'], 'headers' => array_map('strval', $b['headers']), 'labels' => array_map('strval', $b['labels']), 'total' => isset($b['total']) ? (string) $b['total'] : '合计', 'factory' => isset($b['factory']) ? (string) $b['factory'] : null, 'source' => isset($b['source']) ? (string) $b['source'] : null] : null, $blocks))); $result = $store->saveSummaryTemplates($blocks, $month); $this->info('读到 ' . $result['blocks'] . ' 家,记下 ' . count($result['saved']) . ' 家 ' . $month . ' 的汇总样子:' . implode('、', $result['saved'])); if ($result['unknown'] !== []) { $this->warn('系统里没找到这些厂家(没有代发运费的厂家可以不管):' . implode('、', $result['unknown'])); } return self::SUCCESS; } }