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
+52 -2
View File
@@ -23,6 +23,7 @@ use Morilog\Jalali\Jalalian;
use App\Services\ConfigService;
use App\Services\LivePriceCacheService;
use App\Services\PriceSnapshotService;
use App\Services\PriceSyncLogService;
use App\Services\ProductDisplayPriceService;
@@ -168,7 +169,14 @@ class ReportController extends Controller
'zaarbox' => 0,
], $this->storeLastPrice($config));
app(PriceSnapshotService::class)->recordHalfHourBuyPrice((int) ($storePayload['buy'] ?? 0));
if ($forceRefresh) {
$this->recordHalfHourPriceSnapshot(
(int) ($storePayload['buy'] ?? 0),
'store',
null,
(int) ($storePayload['price'] ?? $storePayload['buy'] ?? 0)
);
}
return $this->appendUpPrices($storePayload, $forceRefresh);
}
@@ -415,7 +423,14 @@ class ReportController extends Controller
$config->trackDailyPriceExtreme((float) $priceValue);
}
app(PriceSnapshotService::class)->recordHalfHourBuyPrice((int) $buy);
if ($forceRefresh) {
$this->recordHalfHourPriceSnapshot(
(int) $buy,
(string) ($priceSource ?: ($priceProvider ?: 'legacy')),
$this->resolvePriceSourceUrl($priceSource, $config),
(int) $priceValue
);
}
return $this->appendUpPrices([
'sell' => $sell,
@@ -430,6 +445,41 @@ class ReportController extends Controller
], $forceRefresh);
}
protected function recordHalfHourPriceSnapshot(
int $buyPrice,
string $source,
?string $sourceUrl,
int $referencePrice
): void {
if ($buyPrice <= 0) {
return;
}
$reference = $referencePrice > 0 ? $referencePrice : $buyPrice;
app(PriceSyncLogService::class)->recordSnapshotIfDue(
$source,
$sourceUrl,
$reference,
PriceSnapshotService::HALF_HOUR_MINUTES
);
app(PriceSnapshotService::class)->recordHalfHourBuyPrice($buyPrice);
}
protected function resolvePriceSourceUrl(?string $priceSource, ConfigService $config): ?string
{
if ($priceSource === 'zaarbox') {
return app(ZaarboxPriceService::class)->apiUrl();
}
if ($priceSource === 'montzar') {
return rtrim($config->Config('montzar_base_url') ?: 'https://montpar.ir', '/');
}
return null;
}
/**
* فروشگاه — منطق lastPrice قبل مرج (ghatreh): montzar_price / nasiryan / prices
*/