fix some issu

This commit is contained in:
2026-08-26 21:47:09 +03:30
parent 74cc50149f
commit 40b185187c
14 changed files with 179 additions and 72 deletions
+37 -22
View File
@@ -35,6 +35,20 @@ class LivePriceCacheService
{
$cached = Cache::get(self::FULL_RESPONSE_KEY);
$cachedBody = is_array($cached['body'] ?? null) ? $cached['body'] : null;
$config = app(ConfigService::class);
// no_quote صفر را روی مظنهٔ معتبر قبلی ننویس — قطع فید لحظه‌ای نباید UI را خالی کند
$incomingEmpty = ! $config->payloadHasDisplayablePrice($body)
&& (string) ($body['status'] ?? '') === 'no_quote';
$existingGood = is_array($cachedBody) && $config->payloadHasDisplayablePrice($cachedBody);
if ($incomingEmpty && $existingGood) {
Cache::put(self::FULL_RESPONSE_KEY, [
'body' => $cachedBody,
'stored_at' => now(),
], now()->addSeconds(self::TTL_SECONDS + 5));
return $cachedBody;
}
if ($cachedBody !== null && PriceBroadcastService::lastPriceIdentity($cachedBody) === PriceBroadcastService::lastPriceIdentity($body)) {
Cache::put(self::FULL_RESPONSE_KEY, [
@@ -95,7 +109,7 @@ class LivePriceCacheService
return now()->diffInSeconds($lastTick) <= self::TICK_MAX_AGE_SECONDS;
}
/** پاسخ سریع بدون API خارجی — فقط وقتی کران اخیراً tick زده (همان فرمول lastPrice) */
/** پاسخ سریع بدون API خارجی — از montzar_live_price / آخرین ردیف prices */
public function buildFromDatabase(): array
{
$config = app(ConfigService::class);
@@ -104,6 +118,28 @@ class LivePriceCacheService
$base = $last ? (float) $last->price : 0.0;
$provider = $config->priceProvider();
$montzarSource = 0;
$zaarboxSource = 0;
$mainProductSource = 0;
$priceSource = 'database_last';
if ($provider === 'montzar') {
$liveMontzar = (float) $config->get('montzar_live_price', 0);
if ($liveMontzar > 0 && $config->isPlausibleQuotePrice($liveMontzar)) {
$base = $liveMontzar;
$montzarSource = (int) $liveMontzar;
$priceSource = 'montzar';
}
} elseif ($provider === 'zaarbox' && $base > 0) {
$zaarboxSource = (int) $base;
$priceSource = 'zaarbox';
} elseif ($provider === 'main_product' && $base > 0) {
$mainProductSource = (int) $base;
$priceSource = 'main_product';
}
// قبلاً فقط به جدول prices نگاه می‌کرد؛ اگر خالی بود SSE همان لحظه no_quote صفر
// می‌فرستاد و UI مظنهٔ معتبر HTTP را پاک می‌کرد — در حالی که montzar_live_price پر بود.
if ($base <= 0) {
$payload = [
'sell' => 0,
@@ -119,27 +155,6 @@ class LivePriceCacheService
'time' => now(),
];
} else {
$montzarSource = 0;
$zaarboxSource = 0;
$mainProductSource = 0;
$priceSource = 'database_last';
if ($provider === 'montzar') {
$liveMontzar = (float) $config->get('montzar_live_price', 0);
if ($liveMontzar > 0 && $config->isPlausibleQuotePrice($liveMontzar)) {
$base = $liveMontzar;
$montzarSource = (int) $liveMontzar;
$priceSource = 'montzar';
} else {
$montzarSource = 0;
$priceSource = 'database_last';
}
} elseif ($provider === 'zaarbox') {
$zaarboxSource = (int) $base;
} elseif ($provider === 'main_product') {
$mainProductSource = (int) $base;
}
$trade = $config->buildTradeDisplayPrices($base, $priceSource);
$payload = [