fix register 3

This commit is contained in:
2026-06-01 18:46:57 +03:30
parent 205d4c2502
commit 0a50125ee9
4 changed files with 68 additions and 15 deletions
+34 -1
View File
@@ -13,9 +13,42 @@ class ConfigService
public function UpdateConfig($name, $value)
{
return \App\Models\Setting::updateOrCreate(
return Setting::updateOrCreate(
['key' => $name],
['value' => $value]
);
}
public function trackDailyPriceExtreme(float $price): void
{
if ($price <= 0) {
return;
}
$upSetting = Setting::where('key', 'up_price')->first();
$downSetting = Setting::where('key', 'down_price')->first();
if (!$upSetting || !$downSetting) {
return;
}
$priceInt = (int) round($price);
$today = now()->toDateString();
if (!$upSetting->updated_at || $upSetting->updated_at->toDateString() !== $today) {
$this->UpdateConfig('up_price', $priceInt);
$this->UpdateConfig('down_price', $priceInt);
return;
}
$currentUp = (float) ($upSetting->value ?: 0);
$currentDown = (float) ($downSetting->value ?: 0);
if ($currentUp <= 0 || $priceInt > $currentUp) {
$this->UpdateConfig('up_price', $priceInt);
}
if ($currentDown <= 0 || $priceInt < $currentDown) {
$this->UpdateConfig('down_price', $priceInt);
}
}
}