fix(price): read last quote and daily extremes from the active provider

A stray montzar tick landed in the prices table, which stores no source, so
the database_last fallback served a ~168M quote on a shop whose Zaarbox board
was at ~217M. Last price and today's high/low now come from price_sync_logs
filtered by price_provider, the database fallback no longer counts as today's
price, and daily extremes reset when the provider changes.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-31 09:45:37 +03:30
co-authored by Cursor
parent 1b73305d6f
commit 142cfd7661
5 changed files with 98 additions and 37 deletions
@@ -82,8 +82,7 @@ class ReportController extends Controller
return ['sell' => 0, 'buy' => 0];
}
$price = Price::orderByDesc('id')->first();
$priceValue = $price ? (float) $price->price : 0.0;
$priceValue = (float) app(ProductDisplayPriceService::class)->resolveHistoricalBasePrice();
if ($priceValue <= 0) {
return ['sell' => 0, 'buy' => 0];
@@ -406,8 +405,9 @@ class ReportController extends Controller
}
if ($priceValue <= 0) {
$lastPrice = Price::latest()->first();
$storedPrice = $lastPrice ? (float) $lastPrice->price : 0.0;
// آخرین قیمت همین provider (نه هر ردیفی از جدول prices — ممکن است
// از یک تیک provider دیگر مانده باشد و مظنه را ده‌ها میلیون پرت کند)
$storedPrice = (float) app(ProductDisplayPriceService::class)->resolveHistoricalBasePrice();
// fallback فقط با show_last_price تصمیم‌گیری می‌شود؛ force_refresh (تیک کران) نباید آن را override کند.
// آستانهٔ ثابت قبلی (۳۰ میلیون) برای طلا بود و محصولات ارزان‌تر مثل کاتد مس/نقره را اشتباهاً «بدون مظنه» می‌کرد.
@@ -448,7 +448,9 @@ class ReportController extends Controller
$buy = $display['buy'];
$priceLast = $display['priceLast'];
if (!$closed && $priceValue > 0) {
// سقف/کف روز فقط از مظنهٔ زنده؛ fallback دیتابیس قیمت دیشب را
// به‌عنوان «قیمت امروز» ثبت می‌کرد و بازهٔ روز را خراب می‌کرد.
if (!$closed && $priceValue > 0 && $priceSource !== 'database_last') {
$config->trackDailyPriceExtreme((float) $priceValue);
}