76 lines
1.8 KiB
PHP
76 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace mt;
|
|
|
|
use phpcommon;
|
|
|
|
class Shop {
|
|
|
|
const HERO_SHOP_ID = 1;
|
|
|
|
public static function get($id)
|
|
{
|
|
getXVal(self::getMetaList(), $id);
|
|
}
|
|
|
|
public static function getGoodsInfo($meta, $goodsId)
|
|
{
|
|
$goodsStrArr = explode("|", $meta['goods']);
|
|
$priceStrArr = explode("|", $meta['price']);
|
|
if (count($goodsStrArr) != count($priceStrArr)) {
|
|
return null;
|
|
}
|
|
$idx = -1;
|
|
{
|
|
$i = 0;
|
|
array_filter($goodsStrArr, function($str) use(&$i, &$idx, $goodsId) {
|
|
if ($idx != -1) {
|
|
$strArr = explode(":", $str);
|
|
if (count($strArr) >= 2) {
|
|
if ($strArr[0] == $goodsId) {
|
|
$idx = $i;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
++$i;
|
|
return false;
|
|
});
|
|
}
|
|
if ($idx <= 0) {
|
|
return null;
|
|
}
|
|
$info = array(
|
|
'goodsId' => 0,
|
|
'goodsNum' => 0,
|
|
'costItemId' => 0,
|
|
'costItemNum' => 0
|
|
);
|
|
{
|
|
$strArr = explode(":", $goodsStrArr[$idx]);
|
|
$info['goodsId'] = $strArr[0];
|
|
$info['goodsNum'] = $strArr[1];
|
|
}
|
|
{
|
|
$strArr = explode(":", $priceStrArr[$idx]);
|
|
if (count($strArr) < 2) {
|
|
return null;
|
|
}
|
|
$info['costItemId'] = $strArr[0];
|
|
$info['costItemNum'] = $strArr[1];
|
|
}
|
|
return $info;
|
|
}
|
|
|
|
protected static function getMetaList()
|
|
{
|
|
if (!self::$metaList) {
|
|
self::$meta = getMetaTable('newshop@newshop.php');
|
|
}
|
|
return self::$metaList;
|
|
}
|
|
|
|
protected static $metaList;
|
|
|
|
}
|