74 lines
1.8 KiB
PHP
74 lines
1.8 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']) {
|
|
return $meta;
|
|
}
|
|
}
|
|
return $currentMeta;
|
|
}
|
|
|
|
public static function getCountdown($meta)
|
|
{
|
|
$countdown = max(0, $meta['start_time'] - myself()->_getNowTime());
|
|
return $countdown;
|
|
}
|
|
|
|
protected static function getMetaList()
|
|
{
|
|
if (!self::$metaList) {
|
|
self::$metaList = getMetaTable('batch@market.php');
|
|
}
|
|
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'] == $b['start_time']) {
|
|
die(json_encode(array(
|
|
'errcode' => 500,
|
|
'errmsg' => 'server internal error'
|
|
)));
|
|
}
|
|
return $a['start_time'] < $b['start_time'];
|
|
});
|
|
}
|
|
}
|
|
|
|
protected static $metaList;
|
|
protected static $sortedList;
|
|
|
|
}
|