_getOrmUserInfo(); $currSeasonMeta = mt\RankSeason::getCurrentSeason(); if($currSeasonMeta){ $this->_setV(TN_RANK_STATUS, 1, 1); // if ($userInfo['last_season_id'] > 0 && $currSeasonMeta['id'] != $userInfo['last_season_id'] ){ // $this->_setV(TN_RANK_STATUS, 0, 2); // } }else{ $this->_setV(TN_RANK_STATUS, 1, 0); } $countdown = 0; $nextCurrSeasonMeta = mt\RankSeason::getNextCurrentSeason(); if ($nextCurrSeasonMeta){ $countdown = strtotime($nextCurrSeasonMeta['start_time']) - myself()->_getNowTime(); } // $rank_status = $this->_getV(TN_RANK_STATUS, 0 ); $is_rank = $this->_getV(TN_RANK_STATUS, 1 ); $this->_rspData(array( // 'status' => $rank_status, // 0:常规状态 1:引导初始排位 2:赛季初,需结算上个赛季(废弃) 'is_rank' => $is_rank, //赛季是否空挡期 1:赛季开始了 0:赛季未开始 'countdown' => $countdown //下赛季倒计时 )); } public function rankingList() { $userInfo = $this->_getOrmUserInfo(); $mode = getReqVal('mode', 0); $class = getReqVal('class', 0); $type = getReqVal('type', 0); if (! RankBattle::inspectMode($mode)){ $this->_rspErr(1, 'mode param error'); return; } if (! RankBattle::inspectClass($class)){ $this->_rspErr(1, 'class param error'); return; } if (! RankBattle::inspectType($type)){ $this->_rspErr(1, 'type param error'); return; } $list = RankBattle::getTopLimit($mode,$class,$type,100); $rankingList = array(); $ranked = 1; if (count($list) > 0){ foreach ($list as $row) { $user = User::find($row['account_id']); array_push($rankingList, array( 'ranked' => $ranked++, 'user' => $this->_extractUserInfo($user), 'value' => $row['value'], 'modifytime' => $row['modifytime'], )); } } $myRanked = array( 'ranked' => -1, 'user' => $this->_extractUserInfo($userInfo), 'value' => 0, 'modifytime' => 0, ); $row = RankBattle::find($mode,$class,$type); if ($row){ $myRanked['value'] = $row['value']; $myRanked['modifytime'] = $row['modifytime']; } $lists = RankBattle::getTopLimit($mode,$class,$type,10000,array('account_id')); if (count($lists) > 0){ foreach ($lists as $k=>$row){ if ($userInfo['account_id'] == $row['account_id']){ $myRanked['ranked'] = $k+1; } } } $rankingData = array( 'type' => $type, 'ranking_list' => $rankingList, 'my_ranked' => $myRanked ); $this->_rspData(array( 'data' =>$rankingData )); } private function _extractUserInfo($row){ if ($row){ $hero_id = 0; $hero_skin = 0; $heroDb = Hero::findByAccountId($row['account_id'],$row['hero_id']); if ($heroDb){ $hero_id = $heroDb['hero_id']; $skinDb = HeroSkin::findByAccountId($row['account_id'],$heroDb['skin_id']); $hero_skin = $skinDb ? $skinDb['skin_id']:0; } $info = array( 'account_id' => $row['account_id'], 'address' => phpcommon\extractOpenId($row['account_id']), 'name' => $row['name'], 'head_id' => $row['head_id'], 'head_frame' => $row['head_frame'], 'hero_skin' => $hero_skin, 'hero_id' => $hero_id, ); }else{ $info = array(); } return $info; } public function resetRankGainAward(){ return; $userInfo = $this->_getOrmUserInfo(); $lastSeasonRank = $userInfo['rank']; $lastSeasonScore = $userInfo['score']; $currSeasonMeta = mt\RankSeason::getCurrentSeason(); $award = array(); if ($currSeasonMeta && $userInfo['last_season_id'] > 0 && $currSeasonMeta['id'] > $userInfo['last_season_id']) { $rank = $userInfo['rank']; for ($i=$userInfo['last_season_id'];$i<$currSeasonMeta['id'];$i++){ $currRankMeta = mt\Rank::getRankById($rank); $dropRankMeta = mt\Rank::getRankById($currRankMeta ? $currRankMeta['next_season'] : 1); $rank= $dropRankMeta['id']; $award = Season::seasonReward($currRankMeta); } //掉段 if ($dropRankMeta) { myself()->_updateUserInfo(array( 'rank' => $dropRankMeta['id'], 'score' => $dropRankMeta['rank_score'], 'last_season_id' => $currSeasonMeta['id'], )); } $awardService = new services\AwardService(); $propertyChgService = new services\PropertyChgService(); $propertyChgService->addUserChg(); $propertyChgService->addBagChg(); $propertyChgService->addParachute(); $cec = $this->calcCECSeasonAward($currSeasonMeta['id']-1); $award = array_merge($award,$cec); error_log(json_encode(array( 'user'=>$userInfo['account_id'], 'Season' => $currSeasonMeta, 'SeasonAward'=>$award, ))); if ($award){ $this->_addItems($award,$awardService,$propertyChgService); } $this->_setV(TN_RANK_STATUS, 0, 0); $this->_rspData([ 'data'=> array( 'last_rank'=>$lastSeasonRank, 'last_score'=>$lastSeasonScore, 'current_rank'=>$dropRankMeta['id'], 'current_score'=>$dropRankMeta['rank_score'], 'award' => $award ), 'property_chg' => $propertyChgService->toDto(), ]); return; } $this->_rspErr(1, "The new season hasn't started yet"); } private function calcCECSeasonAward($seasonId){ $data = SeasonRanking::getDataBySeasonId($seasonId); $rewardParamMeta = \mt\Parameter::getByName('rank_ring_reward'); $rewardParamMetaValue = $rewardParamMeta ? $rewardParamMeta['param_value'] : ''; $rewardList = explode('|',$rewardParamMetaValue); $award = array(); if (count($data)>0){ $KingCount = 0; foreach ($data as &$value){ if ($value['score'] >= $this->starshine){ $KingCount += 1; $value['echelonTopX'] = \services\FormulaService::echelonTopX($value['ranking']); switch ($value['ranking']){ case 1:$value['ring_item_id'] = $rewardList[0];break; case 2:$value['ring_item_id'] = $rewardList[1];break; case 3:$value['ring_item_id'] = $rewardList[2];break; default : $value['ring_item_id'] = 0; } }else{ $value['ring_item_id'] = 0; } } //当月排位赛最大分配金额 $maxSum = \services\FormulaService::calcCECMaxSum(); //排位赛预计分配额 $expected_CEC_Sum = 0; foreach ($data as &$value){ if ($value['score'] >= $this->starshine){ $value['standardTopX'] = \services\FormulaService::standardTopX($value['ranking'],$value['echelonTopX']); $expected_CEC_Sum += \services\FormulaService::calcCECTopXSum($value['ranking'],$value['echelonTopX'],$KingCount); } } //排位赛金额% $rankAmountPre = min($maxSum/($expected_CEC_Sum+1),1); // foreach ($data as $val){ // if ($val['account_id'] == myself()->_getAccountId() && // $val['score'] >= $this->starshine && // $val['ranking'] <= 10000){ // array_push($award,array( // 'item_id' => V_ITEM_DIAMOND, // 'item_num' => $val['standardTopX']*$rankAmountPre // )); // if ($val['ring_item_id']){ // array_push($award,array( // 'item_id' => $val['ring_item_id'], // 'item_num' => 1 // )); // } // } // } $hashData = array(); foreach ($data as $k=>$v){ $hashData[$v['account_id']] = $v; } $myInfo = $hashData[myself()->_getAccountId()]; if ($myInfo['score'] >= $this->starshine && $myInfo['ranking'] <= 10000){ array_push($award,array( 'item_id' => V_ITEM_DIAMOND, 'item_num' => $myInfo['standardTopX']*$rankAmountPre )); if ($myInfo['ring_item_id']){ array_push($award,array( 'item_id' => $myInfo['ring_item_id'], 'item_num' => 1 )); } } } return $award; } }