From 8ebc8575eb9e385629c3288d4252949ae016907e Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 4 Apr 2022 13:45:33 +0800 Subject: [PATCH] 1 --- webapp/mt/BcShopBatch.php | 2 +- webapp/mt/BcShopGoods.php | 57 ++++++++++++++++++++++++++++++++++++++- webapp/mt/MarketGoods.php | 10 ------- 3 files changed, 57 insertions(+), 12 deletions(-) diff --git a/webapp/mt/BcShopBatch.php b/webapp/mt/BcShopBatch.php index 3ba735b0..5e13388b 100644 --- a/webapp/mt/BcShopBatch.php +++ b/webapp/mt/BcShopBatch.php @@ -4,7 +4,7 @@ namespace mt; use phpcommon; -class MarketBatch { +class BcShopBatch { public static function get($id) { diff --git a/webapp/mt/BcShopGoods.php b/webapp/mt/BcShopGoods.php index acb6c354..8463580a 100644 --- a/webapp/mt/BcShopGoods.php +++ b/webapp/mt/BcShopGoods.php @@ -1,2 +1,57 @@ + +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; + +} diff --git a/webapp/mt/MarketGoods.php b/webapp/mt/MarketGoods.php index 6f43d0a7..07a921ee 100644 --- a/webapp/mt/MarketGoods.php +++ b/webapp/mt/MarketGoods.php @@ -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();