83 lines
2.2 KiB
PHP
83 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace mt;
|
|
|
|
use phpcommon;
|
|
|
|
class ShopGoods
|
|
{
|
|
|
|
public static function get($id)
|
|
{
|
|
return getXVal(self::getMetaList(), $id);
|
|
}
|
|
|
|
public static function getByGoodsUuid($goodsUuid)
|
|
{
|
|
return getXVal(self::getMetaList(), $goodsUuid);
|
|
}
|
|
|
|
public static function getGoodsList($shopId)
|
|
{
|
|
self::mustBeShopGoodsHash();
|
|
$shopData = getXVal(self::$shopGoodsHash, $shopId, null);
|
|
if (!$shopData) {
|
|
return null;
|
|
}
|
|
return $shopData['goodsList'];
|
|
}
|
|
public static function all()
|
|
{
|
|
if (!self::$goodsList) {
|
|
self::$goodsList = array();
|
|
foreach (self::getMetaList() as $meta) {
|
|
array_push(self::$goodsList, $meta);
|
|
}
|
|
}
|
|
|
|
return self::$goodsList;
|
|
}
|
|
|
|
public static function getGoodsInfo($shopId, $goodsId)
|
|
{
|
|
self::mustBeShopGoodsHash();
|
|
$shopData = getXVal(self::$shopGoodsHash, $shopId, null);
|
|
if (!$shopData) {
|
|
return null;
|
|
}
|
|
return getXVal($shopData['goodsHash'], $goodsId, null);
|
|
}
|
|
|
|
protected static function mustBeShopGoodsHash()
|
|
{
|
|
if (!self::$shopGoodsHash) {
|
|
self::$shopGoodsHash = array();
|
|
foreach (self::getMetaList() as $meta) {
|
|
if (!getXVal(self::$shopGoodsHash, $meta['shop_id'], null)) {
|
|
self::$shopGoodsHash[$meta['shop_id']] = array(
|
|
'goodsList' => array(),
|
|
'goodsHash' => array()
|
|
);
|
|
}
|
|
self::$shopGoodsHash[$meta['shop_id']]['goodsHash'][$meta['goods_id']] = $meta;
|
|
array_push(self::$shopGoodsHash[$meta['shop_id']]['goodsList'], $meta);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected static function getMetaList()
|
|
{
|
|
if (!self::$metaList) {
|
|
self::$metaList = getMetaTable('shopGoods@shopGoods.php');
|
|
foreach (self::$metaList as &$meta) {
|
|
$meta['free_type'] = 0;
|
|
}
|
|
}
|
|
return self::$metaList;
|
|
}
|
|
|
|
protected static $goodsList;
|
|
protected static $shopGoodsHash;
|
|
protected static $metaList;
|
|
}
|