This commit is contained in:
aozhiwei 2021-11-29 11:02:57 +08:00
parent 46028a3aaa
commit d2c5cb2481
2 changed files with 15 additions and 8 deletions

View File

@ -6,9 +6,12 @@ require_once('mt/Item.php');
require_once('mt/Parameter.php'); require_once('mt/Parameter.php');
require_once('mt/Drop.php'); require_once('mt/Drop.php');
require_once('models/Hero.php');
require_once('services/AwardService.php'); require_once('services/AwardService.php');
use phpcommon\SqlHelper; use phpcommon\SqlHelper;
use models\Hero;
class ShopController extends BaseAuthedController { class ShopController extends BaseAuthedController {
@ -17,7 +20,7 @@ class ShopController extends BaseAuthedController {
$heroId = getReqVal('hero_id', 0); $heroId = getReqVal('hero_id', 0);
$buyType = getReqVal('buy_type', 0); $buyType = getReqVal('buy_type', 0);
$heroMeta = mt\Hero::get($heroId); $heroMeta = mt\Hero::get($heroId);
if ($heroMeta) { if (!$heroMeta) {
$this->_rspErr(1, 'hero_id参数错误'); $this->_rspErr(1, 'hero_id参数错误');
return; return;
} }
@ -31,12 +34,12 @@ class ShopController extends BaseAuthedController {
} }
$shopMeta = mt\Shop::get(mt\Shop::HERO_SHOP_ID); $shopMeta = mt\Shop::get(mt\Shop::HERO_SHOP_ID);
if (!$shopMeta) { if (!$shopMeta) {
$this->_rspErr(2, '配置表错误'); $this->_rspErr(2, '配置表错误1');
return; return;
} }
$goodsInfo = mt\Shop::getGoodsInfo($shopMeta, $heroMeta['itemid']); $goodsInfo = mt\Shop::getGoodsInfo($shopMeta, $heroMeta['itemid']);
if (empty($goodsInfo)) { if (empty($goodsInfo)) {
$this->_rspErr(2, '配置表错误'); $this->_rspErr(2, '配置表错误2');
return; return;
} }
if (Hero::find($heroId)) { if (Hero::find($heroId)) {
@ -48,7 +51,7 @@ class ShopController extends BaseAuthedController {
'item_num' => $goodsInfo['costItemNum'], 'item_num' => $goodsInfo['costItemNum'],
); );
$lackItem = null; $lackItem = null;
if (!$this->_hasEnoughItemsEx($costItems, $lackItem)) { if (!$this->_hasEnoughItems($costItems, $lackItem)) {
$this->_rspErr(3, '道具不足'); $this->_rspErr(3, '道具不足');
return; return;
} }

View File

@ -7,10 +7,13 @@ use phpcommon;
class Shop { class Shop {
const HERO_SHOP_ID = 1; const HERO_SHOP_ID = 1;
const HEROSKIN_SHOP_ID = 2;
const GUNSKIN1_SHOP_ID = 3;
const GUNSKIN2_SHOP_ID = 4;
public static function get($id) public static function get($id)
{ {
getXVal(self::getMetaList(), $id); return getXVal(self::getMetaList(), $id);
} }
public static function getGoodsInfo($meta, $goodsId) public static function getGoodsInfo($meta, $goodsId)
@ -18,13 +21,14 @@ class Shop {
$goodsStrArr = explode("|", $meta['goods']); $goodsStrArr = explode("|", $meta['goods']);
$priceStrArr = explode("|", $meta['price']); $priceStrArr = explode("|", $meta['price']);
if (count($goodsStrArr) != count($priceStrArr)) { if (count($goodsStrArr) != count($priceStrArr)) {
echo '111';
return null; return null;
} }
$idx = -1; $idx = -1;
{ {
$i = 0; $i = 0;
array_filter($goodsStrArr, function($str) use(&$i, &$idx, $goodsId) { array_filter($goodsStrArr, function($str) use(&$i, &$idx, $goodsId) {
if ($idx != -1) { if ($idx == -1) {
$strArr = explode(":", $str); $strArr = explode(":", $str);
if (count($strArr) >= 2) { if (count($strArr) >= 2) {
if ($strArr[0] == $goodsId) { if ($strArr[0] == $goodsId) {
@ -37,7 +41,7 @@ class Shop {
return false; return false;
}); });
} }
if ($idx <= 0) { if ($idx < 0) {
return null; return null;
} }
$info = array( $info = array(
@ -65,7 +69,7 @@ class Shop {
protected static function getMetaList() protected static function getMetaList()
{ {
if (!self::$metaList) { if (!self::$metaList) {
self::$meta = getMetaTable('newshop@newshop.php'); self::$metaList = getMetaTable('newshop@newshop.php');
} }
return self::$metaList; return self::$metaList;
} }