41 lines
1.4 KiB
PHP
41 lines
1.4 KiB
PHP
<?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),
|
|
'every_days' => (int) ($triggerConfig['every_days'] ?? 1),
|
|
'step_toman' => (float) ($triggerConfig['step_toman'] ?? 0),
|
|
'direction' => (string) ($triggerConfig['direction'] ?? ''),
|
|
'product_id' => (int) ($triggerConfig['product_id'] ?? 0),
|
|
'price_window' => (string) ($triggerConfig['price_window'] ?? 'calendar_day'),
|
|
];
|
|
|
|
$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));
|
|
}
|
|
}
|