2023-08-10 14:04:23 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Model;
|
|
|
|
|
2023-08-10 14:11:27 +00:00
|
|
|
use Core\Config;
|
2023-08-10 14:04:23 +00:00
|
|
|
use Core\Db;
|
|
|
|
|
|
|
|
class EkrExchangeRates
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var array|false
|
|
|
|
*/
|
|
|
|
private $today;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->today = Db::getRow('select RUB, USD, from_unixtime(id, ?) as date from ekr_exchange_rates order by id desc limit 1', ['%d.%m.%Y']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function oneEkrInUSD(): float
|
|
|
|
{
|
2023-08-10 14:11:27 +00:00
|
|
|
if (!$this->today) {
|
|
|
|
return 0.00;
|
|
|
|
}
|
2023-08-10 14:04:23 +00:00
|
|
|
return round($this->today['RUB'] / $this->today['USD'], 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function oneEkrInRUB(): float
|
|
|
|
{
|
2023-08-10 14:11:27 +00:00
|
|
|
if (!$this->today) {
|
|
|
|
return floatval(Config::EKR_RUB_PRICE);
|
|
|
|
}
|
2023-08-10 14:04:23 +00:00
|
|
|
return $this->today['RUB'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function date(): string
|
|
|
|
{
|
2023-08-10 14:11:27 +00:00
|
|
|
if (!$this->today) {
|
|
|
|
return date('d.m.Y');
|
|
|
|
}
|
2023-08-10 14:04:23 +00:00
|
|
|
return $this->today['date'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|