option('from') ? Carbon::parse($this->option('from')) : null; $to = $this->option('to') ? Carbon::parse($this->option('to')) : null; // --days=N:滚动最近 N 天(含今天)。显式 --from/--to 优先。 if (! $from && ! $to && $this->option('days')) { $days = max((int) $this->option('days'), 1); $from = now()->startOfDay()->subDays($days - 1); $to = now()->startOfDay()->addDay(); } $limit = (int) ($this->option('limit') ?: 2000); $range = ($from && $to) ? $from->toDateString() . ' ~ ' . $to->toDateString() : '最近 ' . $limit . ' 条'; $this->info('开始从副本库同步发货明细(' . $range . ')...'); $progress = function (string $msg): void { $this->info(' ' . $msg); if (function_exists('fflush')) { @fflush(STDOUT); } }; try { $result = ShippingReplicaSynchronizer::make()->sync($from, $to, $limit, $progress); } catch (\Throwable $e) { $this->error('同步失败:' . $e->getMessage()); return self::FAILURE; } $this->info('完成:写入 ' . ($result['processed'] ?? 0) . ' 条发货明细。'); return self::SUCCESS; } }