Новая реализация курсов валют.

This commit is contained in:
2023-08-10 17:04:23 +03:00
parent f4a66a1147
commit deac9203bd
7 changed files with 421 additions and 509 deletions
+28
View File
@@ -0,0 +1,28 @@
<?php
use Core\{Config, Db};
/**
* Парсинг данных ЦБ РФ.
* https://www.cbr-xml-daily.ru/#howto
* Раз в день в час ночи.
*/
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'autoload.php';
$todayExchangeRate = new class {
private const API = 'https://www.cbr-xml-daily.ru/daily_json.js';
public static function getUSDEkrPrice(): float
{
$rates = json_decode(file_get_contents(self::API));
return round(Config::EKR_RUB_PRICE / $rates->Valute->USD->Value, 2);
}
};
$sql = 'insert into ekr_exchange_rates (RUB, USD) values (?,?)';
$args = [
round(Config::EKR_RUB_PRICE, 2),
$todayExchangeRate::getUSDEkrPrice(),
];
Db::sql($sql, $args);