_rspErr(1, 'hero_id参数错误'); return; } if (empty($heroMeta['itemid'])) { $this->_rspErr(2, 'hero.item_id配置错误'); return; } if (!in_array($buyType, array(0, 1))) { $this->_rspErr(1, 'buy_type参数错误'); return; } $shopMeta = mt\Shop::get(mt\Shop::HERO_SHOP_ID); if (!$shopMeta) { $this->_rspErr(2, '配置表错误1'); return; } $goodsInfo = mt\Shop::getGoodsInfo($shopMeta, $heroMeta['itemid']); if (empty($goodsInfo)) { $this->_rspErr(2, '配置表错误2'); return; } if (Hero::find($heroId)) { $this->_rspErr(3, '你已经有该英雄'); return; } $costItems = array( 'item_id' => $goodsInfo['costItemId'], 'item_num' => $goodsInfo['costItemNum'], ); $lackItem = null; if (!$this->_hasEnoughItems($costItems, $lackItem)) { $this->_rspErr(3, '道具不足'); return; } $this->_decItems($costItems); Hero::addHero($heroMeta); $awardService = new services\AwardService(); $heroDb = Hero::find($heroId); if ($heroDb) { $awardService->addHero(Hero::toDto($heroDb)); } $this->rspData(array( 'award' => $awardService->toData() )); } public function buy() { } }