fix price
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user