fix bug
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Cnt;
|
||||
use App\Models\Price;
|
||||
use App\Models\PriceCandle;
|
||||
use App\Models\Product;
|
||||
use App\Models\Setting;
|
||||
|
||||
@@ -247,6 +249,10 @@ class ConfigService
|
||||
$currentUp = (float) ($upSetting->value ?: 0);
|
||||
$currentDown = (float) ($downSetting->value ?: 0);
|
||||
|
||||
if ($currentUp > 0 && $priceInt < (int) ($currentUp * 0.9)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($currentUp <= 0 || $priceInt > $currentUp) {
|
||||
$this->UpdateConfig('up_price', $priceInt);
|
||||
}
|
||||
@@ -254,4 +260,78 @@ class ConfigService
|
||||
$this->UpdateConfig('down_price', $priceInt);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* بیشترین/کمترین قیمت پایه امروز — با اصلاح outlier در down_price.
|
||||
*
|
||||
* @return array{up: int, down: int}
|
||||
*/
|
||||
public function resolvedDailyBaseExtremes(): array
|
||||
{
|
||||
$up = $this->getInt('up_price', 0);
|
||||
$down = $this->getInt('down_price', 0);
|
||||
|
||||
$candle = PriceCandle::whereDate('date_at', now()->toDateString())->first();
|
||||
$candleHigh = $candle ? (int) round((float) $candle->high) : 0;
|
||||
$candleLow = $candle ? (int) round((float) $candle->low) : 0;
|
||||
|
||||
if ($up > 0 && $down > 0 && $down < (int) ($up * 0.9)) {
|
||||
$correctedDown = $candleLow >= (int) ($up * 0.9) ? $candleLow : $up;
|
||||
$down = $correctedDown;
|
||||
$this->UpdateConfig('down_price', $correctedDown);
|
||||
}
|
||||
|
||||
if ($up <= 0 || $down <= 0) {
|
||||
$fromTable = $this->filteredTodayMinMax();
|
||||
if ($up <= 0 && $fromTable['max'] > 0) {
|
||||
$up = $fromTable['max'];
|
||||
}
|
||||
if ($down <= 0 && $fromTable['min'] > 0) {
|
||||
$down = $fromTable['min'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($up <= 0 && $candleHigh > 0) {
|
||||
$up = $candleHigh;
|
||||
}
|
||||
if ($down <= 0 && $candleLow > 0) {
|
||||
$down = $candleLow;
|
||||
}
|
||||
|
||||
if ($up > 0 && $down > 0 && $down > $up) {
|
||||
[$up, $down] = [$down, $up];
|
||||
}
|
||||
|
||||
return ['up' => $up, 'down' => $down];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{min: int, max: int}
|
||||
*/
|
||||
public function filteredTodayMinMax(): array
|
||||
{
|
||||
$prices = Price::query()
|
||||
->whereDate('date_at', now()->toDateString())
|
||||
->pluck('price')
|
||||
->map(fn ($price) => (int) round((float) $price))
|
||||
->filter(fn (int $price) => $price > 0)
|
||||
->values();
|
||||
|
||||
if ($prices->isEmpty()) {
|
||||
return ['min' => 0, 'max' => 0];
|
||||
}
|
||||
|
||||
$max = (int) $prices->max();
|
||||
$threshold = (int) ($max * 0.9);
|
||||
$valid = $prices->filter(fn (int $price) => $price >= $threshold);
|
||||
|
||||
if ($valid->isEmpty()) {
|
||||
return ['min' => $max, 'max' => $max];
|
||||
}
|
||||
|
||||
return [
|
||||
'min' => (int) $valid->min(),
|
||||
'max' => $max,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user