'淘系支付宝', 'taobao-wechat' => '淘系微信', 'pinduoduo' => '拼多多', 'dewu' => '得物', ]; public function __construct( private readonly AccountMappingResyncDispatcher $queue, ) { } /** * @return array{jobs:int,months:list} */ public function dispatch(string $platform, string $periodStart, string $periodEnd): array { if (! isset(self::PLATFORM_LABELS[$platform])) { throw new InvalidArgumentException("不支持自动重算业绩明细的平台:{$platform}"); } $months = $this->monthsBetween($periodStart, $periodEnd); if ($months === []) { throw new InvalidArgumentException('账单账期格式无效,无法排队重算业绩明细。'); } $result = $this->queue->dispatchPlatformMonths([ $platform => $months, ]); return [ 'jobs' => (int) $result['jobs'], 'months' => $months, ]; } /** @return list */ private function monthsBetween(string $periodStart, string $periodEnd): array { try { $cursor = (new DateTimeImmutable($periodStart))->modify('first day of this month'); $end = (new DateTimeImmutable($periodEnd))->modify('first day of this month'); } catch (Throwable) { return []; } if ($cursor > $end) { return []; } $months = []; while ($cursor <= $end) { $months[] = $cursor->format('Y-m'); $cursor = $cursor->modify('+1 month'); } return $months; } }