price changes 2
This commit is contained in:
@@ -126,10 +126,7 @@ class ReportController extends Controller
|
|||||||
$price = Price::orderBy('id', 'desc')->first();
|
$price = Price::orderBy('id', 'desc')->first();
|
||||||
$priceValue = $price ? (float) $price->price : 0.0;
|
$priceValue = $price ? (float) $price->price : 0.0;
|
||||||
|
|
||||||
if (
|
if ($priceValue <= 0) {
|
||||||
$priceValue <= 0
|
|
||||||
|| !$this->isPlausibleStoredPrice($priceValue, $config->priceProvider(), $config)
|
|
||||||
) {
|
|
||||||
return ['sell' => 0, 'buy' => 0];
|
return ['sell' => 0, 'buy' => 0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,50 +143,6 @@ class ReportController extends Controller
|
|||||||
return $payload;
|
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()
|
public function lastPrice()
|
||||||
{
|
{
|
||||||
$config = app(ConfigService::class);
|
$config = app(ConfigService::class);
|
||||||
@@ -466,10 +419,7 @@ class ReportController extends Controller
|
|||||||
$lastPrice = Price::latest()->first();
|
$lastPrice = Price::latest()->first();
|
||||||
$storedPrice = $lastPrice ? (float) $lastPrice->price : 0.0;
|
$storedPrice = $lastPrice ? (float) $lastPrice->price : 0.0;
|
||||||
|
|
||||||
if (
|
if ($storedPrice <= 0) {
|
||||||
$storedPrice <= 0
|
|
||||||
|| !$this->isPlausibleStoredPrice($storedPrice, $priceProvider, $config)
|
|
||||||
) {
|
|
||||||
return $this->appendUpPrices([
|
return $this->appendUpPrices([
|
||||||
'sell' => 0,
|
'sell' => 0,
|
||||||
'buy' => 0,
|
'buy' => 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user