game/_incl_data/class/Model/EkrExchangeRates.php
2023-08-10 17:11:27 +03:00

45 lines
863 B
PHP

<?php
namespace Model;
use Core\Config;
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
{
if (!$this->today) {
return 0.00;
}
return round($this->today['RUB'] / $this->today['USD'], 2);
}
public function oneEkrInRUB(): float
{
if (!$this->today) {
return floatval(Config::EKR_RUB_PRICE);
}
return $this->today['RUB'];
}
public function date(): string
{
if (!$this->today) {
return date('d.m.Y');
}
return $this->today['date'];
}
}