price changes 2

This commit is contained in:
2026-06-08 11:54:36 +03:30
parent cda6f13308
commit f725e0fe8b
+2 -52
View File
@@ -126,10 +126,7 @@ class ReportController extends Controller
$price = Price::orderBy('id', 'desc')->first();
$priceValue = $price ? (float) $price->price : 0.0;
if (
$priceValue <= 0
|| !$this->isPlausibleStoredPrice($priceValue, $config->priceProvider(), $config)
) {
if ($priceValue <= 0) {
return ['sell' => 0, 'buy' => 0];
}
@@ -146,50 +143,6 @@ class ReportController extends Controller
return $payload;
}
/** حداقل fallback zaarbox: ۱M تومن = ۱۰M ریال */
private const ZAARBOX_MIN_PLAUSIBLE = 10_000_000;
/** حداکثر fallback zaarbox/مس: ۱۰M تومن = ۱۰۰M ریال */
private const ZAARBOX_MAX_PLAUSIBLE = 100_000_000;
/**
* جلوگیری از fallback به قیمت ذخیره‌شدهٔ نامعتبر (مثلاً طلا ~785M روی پروژه مس).
*/
protected function isPlausibleStoredPrice(float $storedPrice, string $priceProvider, ConfigService $config): bool
{
if ($storedPrice <= 0) {
return false;
}
$up = (float) $config->get('up_price', 0);
$down = (float) $config->get('down_price', 0);
if ($up > 0 && $down > 0) {
$min = min($up, $down);
$max = max($up, $down);
// up/down آلوده (مثلاً up=784M و down=23M روی مس) → بازه گشاد اعمال نشود
if ($max <= $min * 10) {
if ($storedPrice < $min * 0.25 || $storedPrice > $max * 4) {
return false;
}
return true;
}
}
if (in_array($priceProvider, ['zaarbox', 'main_product'], true)) {
return $storedPrice >= self::ZAARBOX_MIN_PLAUSIBLE
&& $storedPrice <= self::ZAARBOX_MAX_PLAUSIBLE;
}
if ($priceProvider === 'montzar') {
return $storedPrice > 1_000_000 && $storedPrice < 500_000_000;
}
return $storedPrice < 500_000_000;
}
public function lastPrice()
{
$config = app(ConfigService::class);
@@ -466,10 +419,7 @@ class ReportController extends Controller
$lastPrice = Price::latest()->first();
$storedPrice = $lastPrice ? (float) $lastPrice->price : 0.0;
if (
$storedPrice <= 0
|| !$this->isPlausibleStoredPrice($storedPrice, $priceProvider, $config)
) {
if ($storedPrice <= 0) {
return $this->appendUpPrices([
'sell' => 0,
'buy' => 0,