added automation
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?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),
|
||||
'step_toman' => (float) ($triggerConfig['step_toman'] ?? 0),
|
||||
'direction' => (string) ($triggerConfig['direction'] ?? ''),
|
||||
'product_id' => (int) ($triggerConfig['product_id'] ?? 0),
|
||||
];
|
||||
|
||||
$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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user