65 lines
1.5 KiB
PHP
65 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace mt;
|
|
|
|
use phpcommon;
|
|
|
|
class MarketGoods {
|
|
|
|
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 getBatchMetas($batchId)
|
|
{
|
|
self::mustBeBatchHash();
|
|
return getXVal(self::$batchHash, $batchId, null);
|
|
}
|
|
|
|
public static function getOnSaleGoods($batchId, $idx, $itemId)
|
|
{
|
|
$metas = self::getBatchMetas($batchId);
|
|
if (!empty($metas)) {
|
|
foreach ($metas as $meta) {
|
|
if ($meta['id'] == $idx && $meta['item_id'] == $itemId) {
|
|
return $meta;
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
protected static function getMetaList()
|
|
{
|
|
if (!self::$metaList) {
|
|
self::$metaList = getMetaTable('goods@market.php');
|
|
}
|
|
return self::$metaList;
|
|
}
|
|
|
|
protected static function mustBeBatchHash()
|
|
{
|
|
if (!self::$batchHash) {
|
|
self::$batchHash = array();
|
|
self::traverseMeta(function ($meta) {
|
|
if (!getXVal(self::$batchHash, $meta['batch_id'], null)) {
|
|
self::$batchHash[$meta['batch_id']] = array();
|
|
}
|
|
array_push(self::$batchHash[$meta['batch_id']], $meta);
|
|
});
|
|
}
|
|
}
|
|
|
|
protected static $metaList;
|
|
protected static $batchHash;
|
|
|
|
}
|