175 lines
5.2 KiB
PHP
175 lines
5.2 KiB
PHP
<?php
|
|
|
|
namespace mt;
|
|
|
|
use phpcommon;
|
|
|
|
class NewShop {
|
|
|
|
|
|
public static function get($equipId)
|
|
{
|
|
return self::getMeta()[$equipId];
|
|
}
|
|
|
|
protected static function getMeta()
|
|
{
|
|
if (!self::$meta) {
|
|
self::$meta = getMetaTable('newshop@newshop.php');
|
|
}
|
|
return self::$meta;
|
|
}
|
|
public static function getShopCfg()
|
|
{
|
|
$shopCfgArr = self::getMeta();
|
|
|
|
return $shopCfgArr;
|
|
}
|
|
public static function getShopItemByID($itemID)
|
|
{
|
|
$shopCfgArr = self::getMeta();
|
|
if(!self::$itemArr)
|
|
{ self::$itemArr = array();
|
|
foreach ($shopCfgArr as $item)
|
|
{
|
|
$goodsIDStr = $item["goods"];
|
|
$tmpPriceStr = $item["price"];
|
|
$goodsIDArrStr = explode("|",$goodsIDStr);
|
|
$goodsPriceArrStr = explode("|",$tmpPriceStr);
|
|
$discountStr = null;
|
|
$limitStr = null;
|
|
if($item["discount"] && $item["discount"] != "")
|
|
{
|
|
$discountStr = $item["discount"];
|
|
}
|
|
if($item["limit"] && $item["limit"] != "")
|
|
{
|
|
$limitStr = $item["limit"];
|
|
}
|
|
$discountStrArr = null;
|
|
$limitStrArr = null;
|
|
if($discountStr)
|
|
{
|
|
$discountStrArr = explode("|",$discountStr);
|
|
}
|
|
if($limitStr)
|
|
{
|
|
$limitStrArr = explode("|",$limitStr);
|
|
}
|
|
$len = count($goodsIDArrStr);
|
|
$len2 = count($goodsIDArrStr);
|
|
for($i = 0 ; $i < $len ;$i++)
|
|
{
|
|
$goodsIDArr = explode(":",$goodsIDArrStr[$i]);
|
|
$goodsPriceStr2 = $goodsPriceArrStr[$i];
|
|
if($goodsPriceStr2 == "")
|
|
{
|
|
$goodsPriceStr2 = "10001:99999";
|
|
}
|
|
$priceArr = explode(":",$goodsPriceStr2);
|
|
$goodsID = $goodsIDArr[0];
|
|
$goodsNum = 1;
|
|
$tmpLen = count($goodsIDArr);
|
|
if($tmpLen >= 2)
|
|
{
|
|
$goodsNum = $goodsIDArr[1];
|
|
}
|
|
$priceID = $priceArr[0];
|
|
$priceNum = $priceArr[1];
|
|
$specailPrice = 0;
|
|
$limitType = 0;
|
|
|
|
if($discountStrArr)
|
|
{
|
|
$len1 = count($discountStrArr);
|
|
if($len1 > 0)
|
|
{
|
|
$specailPrice = $discountStrArr[$i];
|
|
}
|
|
}
|
|
if($limitStrArr)
|
|
{
|
|
$len1 = count($limitStrArr);
|
|
if($len1 > 0)
|
|
{
|
|
if($len1 > $i)
|
|
{
|
|
$limitType = $limitStrArr[$i];
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
$itemInfo = array("goodsID"=>$goodsID,"goodsNum"=>$goodsNum,
|
|
"priceID"=>$priceID,"priceNum"=>$priceNum,
|
|
"specailPrice"=>$specailPrice,"limitType"=>$limitType);
|
|
self::$itemArr[$itemInfo['goodsID']] = $itemInfo;
|
|
}
|
|
}
|
|
}
|
|
|
|
$itemData = null;
|
|
if(self::$itemArr[$itemID])
|
|
{
|
|
$itemData = self::$itemArr[$itemID];
|
|
}
|
|
|
|
return $itemData;
|
|
|
|
|
|
}
|
|
|
|
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 $itemArr;
|
|
protected static $meta;
|
|
|
|
}
|