game2006api/webapp/mt/HashRateCommon.php
2023-08-22 13:22:28 +08:00

68 lines
1.8 KiB
PHP

<?php
namespace mt;
use phpcommon;
class HashRateCommon {
public static function find($id){
return getXVal(self::getMetaList(), $id, null);
}
public static function getCurrentPeriod()
{
foreach (self::getMetaList() as $meta) {
if (myself()->_getNowTime() >= strtotime($meta['start_time']) &&
myself()->_getNowTime() <= strtotime($meta['end_time'])) {
return $meta;
}
}
return array();
}
public static function getNextPeriod()
{
$metaList = self::getMetaList();
foreach ($metaList as $key => $meta) {
if ($key == 1 && myself()->_getNowTime() <= strtotime($meta['start_time'])) {
return $meta;
}
if ($key > 1 &&
myself()->_getNowTime() >= strtotime($metaList[$key-1]['end_time']) &&
myself()->_getNowTime() <= strtotime($metaList[$key]['start_time'])) {
return $meta;
}
}
return array();
}
public static function getLastPeriod()
{
$metaList = self::getMetaList();
$count = count($metaList);
foreach ($metaList as $key => $meta) {
if (myself()->_getNowTime() >= strtotime($metaList[$key]['end_time']) &&
myself()->_getNowTime() <= strtotime($metaList[$key+1]['start_time'])) {
return $meta;
}
if ($key == $count && myself()->_getNowTime() >= strtotime($meta['end_time'])) {
return $meta;
}
}
return array();
}
protected static function getMetaList()
{
if (!self::$metaList) {
self::$metaList = getMetaTable('HashrateCommon@HashrateCommon.php');
}
return self::$metaList;
}
protected static $metaList;
}