Files

41 lines
1.4 KiB
PHP
Raw Permalink Normal View History

2026-08-23 14:16:00 +03:30
<?php
namespace App\Services\Automation;
class AutomationFingerprint
{
public function make(string $triggerType, array $triggerConfig, array $conditions): string
{
$cfg = [
'event' => (string) ($triggerConfig['event'] ?? ''),
'delay_hours' => (int) ($triggerConfig['delay_hours'] ?? 0),
2026-08-23 17:13:30 +03:30
'every_days' => (int) ($triggerConfig['every_days'] ?? 1),
2026-08-23 14:16:00 +03:30
'step_toman' => (float) ($triggerConfig['step_toman'] ?? 0),
'direction' => (string) ($triggerConfig['direction'] ?? ''),
'product_id' => (int) ($triggerConfig['product_id'] ?? 0),
2026-08-23 17:13:30 +03:30
'price_window' => (string) ($triggerConfig['price_window'] ?? 'calendar_day'),
2026-08-23 14:16:00 +03:30
];
$norm = [];
foreach ($conditions as $row) {
if (! is_array($row) || empty($row['field'])) {
continue;
}
$norm[] = [
'field' => (string) $row['field'],
'op' => (string) ($row['op'] ?? ''),
'value' => $row['value'] ?? null,
];
}
usort($norm, fn ($a, $b) => strcmp($a['field'].$a['op'], $b['field'].$b['op']));
$payload = [
't' => $triggerType,
'cfg' => $cfg,
'c' => $norm,
];
return hash('sha256', json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
}
}