[ '清洗' => 120, '漂洗' => 60, '消毒' => 300, '终末漂洗' => 120, '干燥' => 30, '机洗' => 360, ], '机洗' => [ '清洗' => 120, '漂洗' => 60, '消毒' => 300, '终末漂洗' => 120, '干燥' => 30, '机洗' => 360, ], '手工洗(加强)' => [ '清洗' => 60, '漂洗' => 120, '消毒' => 420, '终末漂洗' => 120, '干燥' => 30, '机洗' => 360, ], '机洗(加强)' => [ '清洗' => 60, '漂洗' => 120, '消毒' => 420, '终末漂洗' => 120, '干燥' => 30, '机洗' => 360, ], '手工洗(晨洗)' => [ '清洗' => 120, '漂洗' => 60, '消毒' => 300, '终末漂洗' => 120, '干燥' => 30, '机洗' => 360, ], '机洗(晨洗)' => [ '清洗' => 120, '漂洗' => 60, '消毒' => 300, '终末漂洗' => 120, '干燥' => 30, '机洗' => 360, ], ]; public function __construct(array $durations = []) { if (empty($durations)) { $this->durations = ProcessDurationRepository::new()->getProcessDurations(); Logger::debug("加载[time_validation]时间验证配置,来源: 数据库"); } else { $this->durations = array_merge($this->durations, $durations); Logger::debug("加载[time_validation]时间验证配置,来源: 自定义参数"); } } /** * 获取指定步骤的时长(不存在则返回 0) */ public function getDuration(string $stepCode, string $processType = '手工洗'): int { $process = $this->durations[$processType]; if (!isset($process)) return 0; return $process[$stepCode] ?? 0; } /** * 设置指定步骤的时长 */ public function setDuration(string $stepCode, int $seconds, string $processType = '手工洗'): self { $this->durations[$processType][$stepCode] = $seconds; return $this; } /** * 判断步骤是否参与时间验证 */ public function hasStep(string $stepCode, string $processType = '手工洗'): bool { return array_key_exists($stepCode, $this->durations[$processType] ?? []); } /** * 从数组创建(兼容旧配置格式 ['durations' => [...]]) */ public static function create(array $config = []): self { $durations = $config['durations'] ?? $config; if (!is_array($durations)) { $durations = []; } $instance = new self($durations); return $instance; } public function toArray(): array { return ['durations' => $this->durations]; } }