game/_incl_data/class/Model/EkrExchangeRates.php

45 lines
863 B
PHP
Raw Normal View History

<?php
namespace Model;
2023-08-10 14:11:27 +00:00
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
{
2023-08-10 14:11:27 +00:00
if (!$this->today) {
return 0.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);
}
return $this->today['RUB'];
}
public function date(): string
{
2023-08-10 14:11:27 +00:00
if (!$this->today) {
return date('d.m.Y');
}
return $this->today['date'];
}
}