This commit is contained in:
aozhiwei 2022-04-04 13:35:33 +08:00
parent e262c8ce1e
commit 61827726dc
3 changed files with 68 additions and 2 deletions

View File

@ -1,7 +1,5 @@
<?php
require_once('mt/MarketGoods.php');
require_once('mt/MarketBatch.php');
require_once('mt/Item.php');
require_once('mt/Currency.php');
require_once('mt/Hero.php');

66
webapp/mt/BcShopBatch.php Normal file
View File

@ -0,0 +1,66 @@
<?php
namespace mt;
use phpcommon;
class MarketBatch {
public static function get($id)
{
return getXVal(self::getMetaList(), $id, null);
}
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, $currBatchMeta['start_time'] - myself()->_getNowTime());
return $countdown;
}
protected static function getMetaList()
{
if (!self::$metaList) {
self::$metaList = getMetaTable('batch@bcshop.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;
}

View File

@ -0,0 +1,2 @@
<?php
?>