fix price

This commit is contained in:
2026-06-24 19:13:36 +03:30
parent d968a42db9
commit 65f74453f3
2 changed files with 94 additions and 2 deletions
+42
View File
@@ -57,6 +57,48 @@ class PriceSyncLogService
return $log->load('items');
}
/**
* نمونه دوره‌ای قیمت (مثلاً هر ۳۰ دقیقه) — حتی اگر قیمت نسبت به رکورد قبلی عوض نشده باشد.
*/
public function recordSnapshot(string $source, ?string $sourceUrl, int $referencePrice): ?PriceSyncLog
{
if (! $this->isAvailable() || $referencePrice <= 0) {
return null;
}
return PriceSyncLog::create([
'source' => $source,
'source_url' => $sourceUrl,
'liquid_gold_price' => $referencePrice,
'products_updated' => 0,
'created_at' => now(),
]);
}
/**
* ثبت در تاریخچه ادمین — حداکثر هر ۳۰ دقیقه (مستقل از تغییر قیمت).
*/
public function recordSnapshotIfDue(
string $source,
?string $sourceUrl,
int $referencePrice,
int $intervalMinutes = 30
): ?PriceSyncLog {
if (! $this->isAvailable() || $referencePrice <= 0) {
return null;
}
$loggedRecently = PriceSyncLog::query()
->where('created_at', '>=', now()->subMinutes($intervalMinutes))
->exists();
if ($loggedRecently) {
return null;
}
return $this->recordSnapshot($source, $sourceUrl, $referencePrice);
}
/** فقط وقتی قیمت مرجع آبشده نسبت به آخرین رکورد عوض شده باشد */
public function recordTick(string $source, ?string $sourceUrl, int $liquidGoldPrice, int $productsSynced): ?PriceSyncLog
{