This commit is contained in:
aozhiwei 2022-04-04 13:45:33 +08:00
parent 61827726dc
commit 8ebc8575eb
3 changed files with 57 additions and 12 deletions

View File

@ -4,7 +4,7 @@ namespace mt;
use phpcommon;
class MarketBatch {
class BcShopBatch {
public static function get($id)
{

View File

@ -1,2 +1,57 @@
<?php
?>
namespace mt;
use phpcommon;
class MarketGoods {
public static function get($id)
{
return getXVal(self::getMetaList(), $id, null);
}
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@bcshop.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;
}

View File

@ -2,9 +2,6 @@
namespace mt;
require_once('mt/AttrHelper.php');
require_once('mt/StrHelper.php');
use phpcommon;
class MarketGoods {
@ -14,13 +11,6 @@ class MarketGoods {
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();