currSeasonMeta = mt\Season::getCurrentSeason(); if (!$this->currSeasonMeta) { $this->_rspErr(10, '服务器内部错误'); die(); } $this->propertyChgService = new services\PropertyChgService(); $this->awardService = new services\AwardChgService(); $this->userInfo = $this->_safeGetOrmUserInfo(); $this->seasonService = new services\SeasonService(); if (!$this->seasonService->checkSeason($this->userInfo)) { $this->userInfo = $this->_safeGetOrmUserInfo(); $this->propertyChgService->addUserChg(); } $this->seasonDb = Season::find($this->currSeasonMeta['id']); if (!$this->seasonDb) { Season::add($this->currSeasonMeta['id']); $this->seasonDb = Season::find($this->currSeasonMeta['id']); } if (!$this->seasonDb) { $this->_rspErr(10, '服务器内部错误'); die(); } $this->seasonCardDb = array( SeasonCard::NORMAL_PACKAGE_ID => SeasonCard::allHash($this->currSeasonMeta['id'], SeasonCard::NORMAL_PACKAGE_ID), SeasonCard::VIP_PACKAGE_ID => SeasonCard::allHash($this->currSeasonMeta['id'], SeasonCard::VIP_PACKAGE_ID), ); } public function info() { $this->_rspData(array( 'info' => array( 'season_id' => $this->currSeasonMeta['id'], 'season_begin_time' => strtotime($this->currSeasonMeta['begin_time']), 'season_begin_end' => strtotime($this->currSeasonMeta['end_time']), 'card_lv' => $this->seasonDb ? $this->seasonDb['card_lv'] : 1, 'card_exp' => $this->seasonDb ? $this->seasonDb['card_exp'] : 0, 'card_max_exp' => $this->seasonDb ? $this->seasonDb['card_exp'] : 0, 'gift_packages' => $this->getGiftPackages(), 'received_level_rewards1' => $this->getReceivedLevelRewards(SeasonCard::NORMAL_PACKAGE_ID), 'received_level_rewards2' => $this->getReceivedLevelRewards(SeasonCard::VIP_PACKAGE_ID), ) )); } public function getReward() { $level = getReqVal('level', 0); $cardMeta = mt\SeasonCard::get($level); if ($level) { $this->_rspErr(1, 'level参数错误'); return; } if ($level > $this->seasonDb['card_lv']) { $this->_rspErr(2, '等级未解锁不可领取'); return; } $cardDb = getXVal($this->seasonCardDb, $level); if ($cardDd) { $this->_rspErr(3, '不能重复领取'); return; } SeasonCard::add($this->currSeasonMeta['id'], $level); $this->_rspData(array( 'award' => $this->awardService->toDto(), 'property_chg' => $this->propertyChgService->toDto(), )); } public function buyLevel() { $addLevel = (int)getReqVal('add_level', 0); if ($addLevel < 0) { $this->_rspErr(1, 'add_level参数错误'); return; } $newLevel = $this->seasonDb['card_lv'] + $addLevel; $currCardMeta = mt\SeasonCard::get($this->seasonDb['card_lv']); $newCardMeta = mt\SeasonCard::get($newLevel); if (!$currCardMeta || !$newCardMeta) { $this->_rspErr(2, 'add_level越界'); return; } $costItemId = V_ITEM_GOLD; $costItemNum = mt\SeasonCard::calcCost($currCardMeta, $newCardMeta); $itemNum = $this->_getItemCount($costItemId, $this->userInfo); if ($itemNum < $costItemId) { $this->_rspErr(3, '金币不足'); return; } Season::updateCardLv($this->currSeasonMeta['id'], $newLevel); $this->_rspData(array( 'award' => $this->awardService->toDto(), 'property_chg' => $this->propertyChgService->toDto(), )); } public function buyGiftPackage() { $packageId = getReqVal('package_id', 0); $costItemId = getReqVal('cost_item_id', 0); $giftPackage = array_find($this->getGiftPackages(), function ($val) use($packageId) { if ($val['package_id'] == $packageId) { return true; } return false; }); if (!$giftPackage) { $this->_rspErr(1, 'pacakge_id参数错误'); return; } if ($giftPackage['state'] == 1) { $this->_rspErr(2, '不能重复购买'); return; } $priceInfo = $giftPackage['priceInfo']; if (empty($priceInfo)) { $this->_rspErr(3, '配置表错误'); return; } $itemMeta = mt\Item::get($priceInfo['item_id']); if (empty($itemMeta)) { $this->_rspErr(3, '配置表错误1'); return; } $dropMeta = mt\Drop::get($itemMeta['drop']); if (empty($dropMeta)) { $this->_rspErr(3, '配置表错误3'); return; } $costItems = $this->getCostItems($priceInfo, $costItemId); if (empty($costItems)) { $this->_rspErr(3, '配置表错误2'); return; } $lackItem = null; if (!$this->_hasEnoughItems($costItems, $lackItem)) { $this->_rspErr(4, $this->_getLackItemErrMsg($lackItem)); return; } Season::updateGiftPackageState($this->currSeasonMeta['id'], $packageId); $this->_decItems($costItems); $this->_scatterDrop('season:gift_package:' . $packageId, $dropMeta, $this->awardService, $this->propertyChgService); $this->_rspData(array( 'award' => $this->awardService->toDto(), 'property_chg' => $this->propertyChgService->toDto(), )); } private function getGiftPackages() { $itemMeta = mt\Item::get(SeasonCard::VIP_PACKAGE_ITEM_ID); $priceInfo = $itemMeta ? mt\Item::getPriceInfo($itemMeta) : null; $giftPackages = array( 'package_id' => SeasonCard::VIP_PACKAGE_ID, 'state' => $this->seasonDb['gift_state2'], 'price_info' => $priceInfo ); return $giftPackages; } private function getReceivedLevelRewards($type) { return array_map(function ($val) { return $val['card_lv']; }, getXVal($this->seasonCardDb, $type, array())); } }