diff --git a/app/Http/Controllers/Site/ReportController.php b/app/Http/Controllers/Site/ReportController.php index 8bbbe8c..aff7e47 100644 --- a/app/Http/Controllers/Site/ReportController.php +++ b/app/Http/Controllers/Site/ReportController.php @@ -183,7 +183,7 @@ class ReportController extends Controller if ($forceRefresh) { $this->recordHalfHourPriceSnapshot( (int) ($storePayload['buy'] ?? 0), - 'store', + (string) ($storePayload['price_source'] ?? 'store'), null, (int) ($storePayload['price'] ?? $storePayload['buy'] ?? 0) ); @@ -450,6 +450,7 @@ class ReportController extends Controller 'buy' => $buy, 'price_last' => $priceLast, 'price' => $priceValue, + 'price_source' => $priceSource, 'main_product' => $pr_price ?? 0, 'montzar' => $montzar_price ?? 0, 'zaarbox' => $zaarbox_price ?? 0, @@ -464,7 +465,12 @@ class ReportController extends Controller ?string $sourceUrl, int $referencePrice ): void { - if ($buyPrice <= 0) { + if ($buyPrice <= 0 && $referencePrice <= 0) { + return; + } + + // فقط fallback دیتابیس — مظنهٔ زنده نیست؛ لاگ/رکورد جدید نساز (همان قیمت دیشب تکرار می‌شود). + if ($source === 'database_last') { return; } @@ -582,6 +588,7 @@ class ReportController extends Controller 'buy' => $display['buy'], 'price_last' => $display['priceLast'], 'price' => $priceValue, + 'price_source' => $priceSource, 'tala_ir' => $talaIr, ]; diff --git a/app/Services/LivePriceTickService.php b/app/Services/LivePriceTickService.php index f4d54df..ce854eb 100644 --- a/app/Services/LivePriceTickService.php +++ b/app/Services/LivePriceTickService.php @@ -71,12 +71,17 @@ class LivePriceTickService $liquidGold = app(ProductDisplayPriceService::class)->resolveHistoricalBasePrice(); } + $tickSource = (string) ($payload['price_source'] ?? $source); + if ($tickSource === '') { + $tickSource = $source; + } + $activeProducts = Product::query() ->where('active', 1) ->whereNotNull('reading_method') ->count(); - $syncLog = app(PriceSyncLogService::class)->recordTick($source, $sourceUrl, $liquidGold, $activeProducts); + $syncLog = app(PriceSyncLogService::class)->recordTick($tickSource, $sourceUrl, $liquidGold, $activeProducts); app(LivePriceCacheService::class)->markTick(); diff --git a/app/Services/PriceSyncLogService.php b/app/Services/PriceSyncLogService.php index d5877c4..e303d9a 100644 --- a/app/Services/PriceSyncLogService.php +++ b/app/Services/PriceSyncLogService.php @@ -102,7 +102,7 @@ class PriceSyncLogService /** فقط وقتی قیمت مرجع آبشده نسبت به آخرین رکورد عوض شده باشد */ public function recordTick(string $source, ?string $sourceUrl, int $liquidGoldPrice, int $productsSynced): ?PriceSyncLog { - if (! $this->isAvailable() || $liquidGoldPrice <= 0) { + if (! $this->isAvailable() || $liquidGoldPrice <= 0 || $source === 'database_last') { return null; }