_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); $this->internalAddItem($heroMeta); $awardService = new services\AwardService(); $heroDb = Hero::find($heroId); if ($heroDb) { $awardService->addHero(Hero::toDto($heroDb)); } $this->rspData(array( 'award' => $awardService->toDto() )); } public function outsideBuy() { $itemId = getReqVal('item_id', 0); $itemNum = getReqVal('item_num', 0); $costItemId = getReqVal('item_id', 0); $itemMeta = mt\Item::get($itemId); if (!$itemMeta) { $this->_rspErr(1, 'item_id参数错误'); return; } if ($itemNum != 1) { $this->_rspErr(1, 'item_num参数必须等于1'); return; } $costItemMeta = mt\Item::get($costItemId); if (!$costItemMeta) { $this->_rspErr(1, 'item_id参数错误'); return; } $types = array(mt\Item::HERO_TYPE, mt\Item::HERO_SKIN_TYPE, mt\Item::GUN_SKIN_TYPE); if (!mt\Item::inTypes($itemMeta, $types)) { $this->_rspErr(1, 'item_id参数错误'); return; } { switch ($itemMeta['type']) { case mt\Item::HERO_TYPE: { $heroDb = Hero::find($itemMeta['id']); if (!$heroDb) { $this->_rspErr(4, '你已经拥有该英雄'); return; } } break; case mt\Item::HERO_SKIN_TYPE: { $heroSkinDb = HeroSkin::find($itemMeta['id']); if (!$heroSkinDb) { $this->_rspErr(4, '你已经拥有该皮肤'); return; } } break; case mt\Item::GUN_SKIN_TYPE: { $gunSkinDb = GunSkin::find($itemMeta['id']); if (!$gunSkinDb) { $this->_rspErr(4, '你已经拥有该皮肤'); return; } } break; default: { $this->_rspErr(1, 'item_id参数错误'); return; } break; } } $priceInfo = mt\Item::getPriceInfo($itemMeta); if (empty($priceInfo)) { $this->_rspErr(2, '配置表错误'); return; } $costItems = $this->getCostTimes($priceInfo, $costItemId); if (empty($costItems)) { $this->_rspErr(2, '配置表错误2'); return; } $lackItem = null; if (!$this->_hasEnoughItems($costItems, $lackItem)) { $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); return; } $this->_decItems($costItems); $this->internalAddItem($itemMeta); $awardService = new services\AwardService(); $awardService->addItem($itemId, $itemNum); $this->rspData(array( 'award' => $awardService->toDto(), 'property_chg' => array( 'user_info' => User::info($this->_getOrmUserInfo()) ) )); } public function getOutsidePriceInfo() { $items = array(); { $types = array(mt\Item::HERO_TYPE, mt\Item::HERO_SKIN_TYPE, mt\Item::GUN_SKIN_TYPE); mt\Item::filter(function ($meta) use(&$items, &$types) { if (mt\Item::inTypes($meta, $types)) { array_push($items, $meta); } return true; }); } $priceList = array(); array_walk($items, function ($val) use(&$priceList) { array_push($priceList, mt\Item::getPriceInfo($val)); }); $this->_rspData(array( 'price_list' => $priceList )); } private function getCostItems($priceInfo, $costItemId) { $costGroup = null; array_walk($priceInfo['cost_list'], function ($val) use(&$costGroup, $costItemId) { if ($costGroup) { return; } if (count($val) > 0 && $val[0]['item_id'] == $costItemId) { $costGroup = $val; return; } }); if (!$costGroup) { return null; } $costItems = array(); array_walk($costGroup, function ($val) use (&$costItems, $priceInfo) { if ($val['is_discount'] && $priceInfo['discount'] > 0 && $this->_getNowTime() >= $priceInfo['discount_begin_time'] && $this->_getNowTime() <= $priceInfo['discount_end_time'] ) { array_push($costItems, array( 'item_id' => $val['item_id'], 'item_num' => (int)($val['item_num'] * ($priceInfo['discount'] / 100)), )); } else { array_push($costItems, array( 'item_id' => $val['item_id'], 'item_num' => $val['item_num'], )); } }); return $costItems; } private function internalAddItem($itemMeta) { switch ($itemMeta['type']) { case mt\Item::HERO_TYPE: { Hero::addHero($itemMeta); } break; case mt\Item::HERO_SKIN_TYPE: { HeroSkin::addSkin($itemMeta); } break; case mt\Item::GUN_SKIN_TYPE: { GunSkin::addSkin($itemMeta); } break; default: { } break; } } }