option('from')); $to = trim((string) $this->option('to')); $to = $to !== '' ? $to : Carbon::now('Asia/Shanghai')->subDay()->toDateString(); try { $result = $synchronizer->sync( $from, $to, (int) $this->option('company'), (int) $this->option('refresh-days'), (bool) $this->option('dry-run'), ); } catch (Throwable $exception) { if ($this->option('json')) { $this->line(json_encode([ 'status' => 'failed', 'from' => $from, 'to' => $to, 'error' => $exception->getMessage(), ], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); } else { $this->error($exception->getMessage()); } return self::FAILURE; } if ($this->option('json')) { $this->line(json_encode($result, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); return self::SUCCESS; } $this->info(sprintf( '聚水潭订单标签明细同步完成:%s ~ %s,覆盖 %d 天。', $result['from'], $result['to'], (int) ($result['checked_days'] ?? 0), )); foreach ($result['backfill_results'] ?? [] as $backfill) { $this->line(sprintf( ' 补导 %s ~ %s:%d 单,%d 行。', $backfill['from'], $backfill['to'], (int) $backfill['orders'], (int) $backfill['rows'], )); } $refresh = $result['refresh'] ?? null; if (is_array($refresh)) { $this->line(sprintf( ' 刷新 %s ~ %s:%d 单,%d 行。', $refresh['from'], $refresh['to'], (int) $refresh['orders'], (int) $refresh['rows'], )); } return self::SUCCESS; } }