81 lines
2.2 KiB
PHP
81 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace mt;
|
|
|
|
use phpcommon;
|
|
|
|
class MarketBatch {
|
|
|
|
public static function get($id)
|
|
{
|
|
return getXVal(self::getMetaList(), $id, null);
|
|
}
|
|
|
|
public static function traverseMeta($cb)
|
|
{
|
|
foreach (self::getMetaList() as $meta) {
|
|
$cb($meta);
|
|
}
|
|
}
|
|
|
|
public static function getCurrentBatch()
|
|
{
|
|
self::mustBeSortedList();
|
|
$currentMeta = null;
|
|
foreach (self::$sortedList as $meta) {
|
|
if (!$currentMeta) {
|
|
$currentMeta = $meta;
|
|
continue;
|
|
}
|
|
if (myself()->_getNowTime() > $meta['_start_time_utc']) {
|
|
return $meta;
|
|
}
|
|
}
|
|
return $currentMeta;
|
|
}
|
|
|
|
protected static function getMetaList()
|
|
{
|
|
if (!self::$metaList) {
|
|
self::$metaList = getMetaTable('batch@market.php');
|
|
foreach (self::$metaList as &$meta) {
|
|
if (empty($meta['start_time'])) {
|
|
$meta['_start_time_utc'] = 0;
|
|
} else {
|
|
$meta['_start_time_utc'] = strtotime($meta['start_time']) - $meta['world_time_zone'] * 3600;
|
|
}
|
|
|
|
if (empty($meta['end_time'])) {
|
|
$meta['_end_time_utc'] = 0;
|
|
} else {
|
|
$meta['_end_time_utc'] = strtotime($meta['end_time']) - $meta['world_time_zone'] * 3600;
|
|
}
|
|
}
|
|
}
|
|
return self::$metaList;
|
|
}
|
|
|
|
protected static function mustBeSortedList()
|
|
{
|
|
if (!self::$sortedList) {
|
|
self::$sortedList = array();
|
|
foreach (self::getMetaList() as $meta) {
|
|
array_push(self::$sortedList, $meta);
|
|
}
|
|
usort(self::$sortedList, function ($a, $b) {
|
|
if ($a['_start_time_utc'] == $b['_start_time_utc']) {
|
|
die(json_encode(array(
|
|
'errcode' => 500,
|
|
'errmsg' => 'server internal error'
|
|
)));
|
|
}
|
|
return $a['_start_time_utc'] < $b['_start_time_utc'];
|
|
});
|
|
}
|
|
}
|
|
|
|
protected static $metaList;
|
|
protected static $sortedList;
|
|
|
|
}
|