currSeasonMeta = mt\Season::getCurrentSeason(); if (!$this->currSeasonMeta) { $this->_rspErr(10, '服务器内部错误'); die(); } $this->propertyChgService = new services\PropertyChgService(); $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 = SeasonCard::allHash($this->currSeasonMeta['id']); } public function info() { $this->_rspData(array( 'info' => array( 'season_id' => $this->currSeasonMeta['id'], 'card_lv' => $this->seasonDb ? $this->seasonDb['card_lv'] : 1, 'card_exp' => $this->seasonDb ? $this->seasonDb['card_exp'] : 0, 'gift_packages' => $this->getGiftPackages(), 'received_level_rewards' => $this->getReceivedLevelRewards() ) )); } 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); $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; } Season::updateGiftPackageState($this->currSeasonMeta['id'], $packageId); } private function getGiftPackages() { $giftPackages = array( ); return $giftPackages; } private function getReceivedLevelRewards() { return array_map(function ($val) { return $val['card_lv']; }, $this->seasonCardDb); } }