option('date')) ?: Workbench::defaultDate(); try { Workbench::parseDate($date); } catch (Throwable $exception) { $this->error($exception->getMessage()); return self::FAILURE; } $failed = false; foreach (Company::enabled()->orderBy('id')->get() as $company) { $company->makeCurrent(); $companyId = (int) $company->id; if ($batches->get($companyId, $date) !== null) { $this->line("#{$companyId}: {$date} 已确认,跳过"); continue; } if (! in_array($repository->syncStatus()['code'], ['ready', 'failed'], true)) { $this->line("#{$companyId}: 聚工单镜像未就绪,跳过"); continue; } try { $result = $workbench->build($companyId, $date); $gate = Gate::check($result); if (! $gate['ok']) { $this->warn("#{$companyId}: {$date} 放行检查没通过,暂不确认:" . implode(';', $gate['reasons'])); $failed = true; continue; } if ($this->option('dry-run')) { $this->line("#{$companyId}: {$date} 可以确认:" . $result['summary']['source']['count'] . ' 单'); continue; } $batch = $batches->confirm($companyId, $date, $result, ['paid_from' => Workbench::defaultPaidFrom($date), 'scope' => Workbench::DEFAULT_SCOPE], null, 'auto'); $this->info("#{$companyId}: 已确认 {$date} 批次 " . $batch['summary']['source']['count'] . ' 单'); } catch (Throwable $exception) { report($exception); $this->error("#{$companyId}: 确认失败:" . $exception->getMessage()); $failed = true; } } return $failed ? self::FAILURE : self::SUCCESS; } }