inputRows($client); $values = $importer->values($rows); if ((bool) $this->option('dry-run')) { $this->info(sprintf('票聚销方额度读取成功:%d 条,未写入镜像。', count($values))); return self::SUCCESS; } $written = $importer->replace($rows); } catch (Throwable $exception) { report($exception); $this->error('票聚销方额度同步失败,已保留上一版镜像。'); return self::FAILURE; } $this->info(sprintf('票聚销方额度同步完成:%d 条。', $written)); return self::SUCCESS; } /** * @return list> */ private function inputRows(PiaojuSellerQuotaClient $client): array { $fromStdin = (bool) $this->option('stdin'); $path = trim((string) $this->option('file')); if (! $fromStdin && $path === '') { return $client->fetchAll(); } $raw = $fromStdin ? stream_get_contents(STDIN) : file_get_contents($path); if (! is_string($raw) || trim($raw) === '') { throw new \RuntimeException('piaoju_input_empty'); } $decoded = json_decode($raw, true, 512, JSON_THROW_ON_ERROR); $rows = null; if (is_array($decoded)) { if (array_is_list($decoded)) { $rows = $decoded; } else { $data = $decoded['data'] ?? null; if (is_array($data)) { $rows = array_is_list($data) ? $data : ($data['list'] ?? $data['records'] ?? null); } } } if (! is_array($rows)) { throw new \RuntimeException('piaoju_input_invalid'); } return array_values(array_filter($rows, 'is_array')); } }