window(); $result = $synchronizer->sync( $from, $to, (int) $this->option('company'), (bool) $this->option('dry-run'), (bool) $this->option('force-clear'), ); } catch (Throwable $exception) { $this->error($exception->getMessage()); return self::FAILURE; } $unmatched = $result['unmatched_stores']; $result['unmatched_stores'] = count($unmatched); $this->info(json_encode($result, JSON_UNESCAPED_UNICODE)); foreach (array_slice($unmatched, 0, 20, true) as $store => $count) { $this->warn(sprintf('未匹配利润中心:%s(%d 行)', $store, $count)); } if (count($unmatched) > 20) { $this->warn('……还有 ' . (count($unmatched) - 20) . ' 家店铺未匹配到利润中心。'); } return self::SUCCESS; } /** @return array{0:string,1:string} */ private function window(): array { $from = trim((string) $this->option('from')); $to = trim((string) $this->option('to')); $month = trim((string) $this->option('month')); if ($month !== '') { if ($from !== '' || $to !== '') { throw new InvalidArgumentException('--month 与 --from/--to 只能给一个。'); } if (preg_match('/^\d{4}-\d{2}$/', $month) !== 1) { throw new InvalidArgumentException('--month 必须是 YYYY-MM。'); } return [$month . '-01', date('Y-m-t', strtotime($month . '-01'))]; } if ($from === '' || $to === '') { throw new InvalidArgumentException('请给 --month=YYYY-MM,或同时给 --from 与 --to。'); } return [$from, $to]; } }