2026-05-24 13:56:33 +03:30
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
2026-05-24 19:22:09 +03:30
|
|
|
use App\Models\Setting;
|
2026-05-24 13:56:33 +03:30
|
|
|
|
|
|
|
|
class ConfigService
|
|
|
|
|
{
|
2026-05-25 20:55:05 +03:30
|
|
|
public function Config($name)
|
2026-05-24 13:56:33 +03:30
|
|
|
{
|
2026-05-25 20:55:05 +03:30
|
|
|
return Setting::where('key', $name)->value('value') ?? false;
|
2026-05-24 13:56:33 +03:30
|
|
|
}
|
2026-05-24 19:22:09 +03:30
|
|
|
|
|
|
|
|
public function UpdateConfig($name, $value)
|
2026-05-24 13:56:33 +03:30
|
|
|
{
|
2026-06-01 18:46:57 +03:30
|
|
|
return Setting::updateOrCreate(
|
2026-05-24 22:29:43 +03:30
|
|
|
['key' => $name],
|
|
|
|
|
['value' => $value]
|
|
|
|
|
);
|
2026-05-24 13:56:33 +03:30
|
|
|
}
|
2026-06-01 18:46:57 +03:30
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-05-24 19:22:09 +03:30
|
|
|
}
|