updateSession(myself()->_getAccountId(), myself()->_getSessionId()); //$user_name = $_REQUEST['name']; //$avatar_url = $_REQUEST['avatar_url']; $userName = 'guest'; $avatarUrl = '18003'; $userInfo = $this->_safeGetOrmUserInfo(); if (!$userInfo) { $this->createNewUserV2($userName); $this->_addFreeItem(); $userInfo = $this->_getOrmUserInfo(); // $this->_setBattleHero($userInfo); // $this->_setV(TN_RANK_STATUS, 0, 1); } //elo score 衰减 $this->dampingElo($userInfo); $userInfo = $this->_getOrmUserInfo(); //跟新登录时间 $this->_updateUserInfo(array( 'last_login_time'=>myself()->_getNowTime(), )); $this->_updateLastSeason($userInfo); $this->_updateSubUserAccount(); $this->_sign(); $event = array( 'ID' => 'luck', 'SUB_ID' => 'change', 'SUB_KEY' => 'luck_change', 'change' => Hero::getAccountLuckyTemp(), 'reason' => 'login', ); LogService::burialPointEvent($event); $this->_rspData(array( 'info' => User::show($userInfo), )); $this->_incDailyV(TN_DAILY_LOGINS, 0, 1); } private function _addFreeItem(){ $addItems =array(); foreach (mt\Parameter::getListValue('creator_present_items') as $itemsStr) { list($itemId, $itemNum) = explode(':', $itemsStr); if ($itemNum > 0) { array_push($addItems, array( 'item_id' => $itemId, 'item_num' => $itemNum )); } } if (defined('PRESENT_FREE_ITEM')) { array_push($addItems, array( 'item_id' => V_ITEM_GOLD, 'item_num' => 500000 )); } $awardService = new services\AwardService(); $propertyChgService = new services\PropertyChgService(); $this->_addItems($addItems, $awardService, $propertyChgService); } private function loginCheck($userInfo,$awardService,$propertyService) { $seasonService = new services\SeasonService(); return $seasonService->checkSeason($userInfo,$awardService,$propertyService); } public function update() { $userInfo = $this->_getOrmUserInfo(); $validFields = array( 'sex' => array( 'field_name' => 'sex', 'val_func' => function ($val) { return $val; }, 'valid_func' => function ($val, &$errCode, &$errMsg) use($userInfo) { if (isValidSex($val)) { return true; } else { $errCode = 1; $errMsg = 'sex parameter error'; return false; } } ), 'head_id' => array( 'field_name' => 'head_id', 'val_func' => function ($val) { return $val; }, 'valid_func' => function ($val, &$errCode, &$errMsg) use($userInfo) { if (User::isValidHeadId($userInfo, $val)) { return true; } else { $errCode = 1; $errMsg = 'head_id parameter error'; return false; } } ), 'head_frame' => array( 'field_name' => 'head_frame', 'val_func' => function ($val) { return $val; }, 'valid_func' => function ($val, &$errCode, &$errMsg) use($userInfo) { if (User::isValidHeadFrame($userInfo, $val)) { return true; } else { $errCode = 1; $errMsg = 'head_id parameter error'; return false; } } ), 'hero_id' => array( 'field_name' => 'hero_id', 'val_func' => function ($val) { return $val; }, 'valid_func' => function ($val, &$errCode, &$errMsg) use ($userInfo) { $heroDb = Hero::find($val); if (User::isValidHeroId($userInfo, $val) && $heroDb['seal_type'] == Hero::UNSEAL_STATE) { return true; }else{ $errCode = 1; $errMsg = 'hero_id parameter error'; return false; } } ), 'first_fight' => array( 'field_name' => 'first_fight', 'val_func' => function ($val) { return empty($val) ? 0 : 1; }, 'valid_func' => function ($val, &$errCode, &$errMsg) { return true; } ), 'already_guide' => array( 'field_name' => 'already_guide', 'val_func' => function ($val) { return empty($val) ? 0 : 1; }, 'valid_func' => function ($val, &$errCode, &$errMsg) { return true; } ), 'guild_id' => array( 'field_name' => 'guild_id', 'val_func' => function ($val) { return empty($val) ? '' : $val; }, 'valid_func' => function ($val, &$errCode, &$errMsg) { return true; } ), 'guild_job' => array( 'field_name' => 'guild_job', 'val_func' => function ($val) { return empty($val) ? 0 : $val; }, 'valid_func' => function ($val, &$errCode, &$errMsg) { return true; } ), 'guild_name' => array( 'field_name' => 'guild_name', 'val_func' => function ($val) { return empty($val) ? '' : $val; }, 'valid_func' => function ($val, &$errCode, &$errMsg) { return true; } ), 'parachute' => array( 'field_name' => 'parachute', 'val_func' => function ($val) { return $val; }, 'valid_func' => function ($val, &$errCode, &$errMsg) { if (User::isValidParachute($val)) { return true; } else { $errCode = 1; $errMsg = 'parachute parameter error'; return false; } } ), 'ring_id' => array( 'field_name' => 'ring_id', 'val_func' => function ($val) { return $val; }, 'valid_func' => function ($val, &$errCode, &$errMsg) { if (User::isValidRing($val)) { return true; } else { $errCode = 1; $errMsg = 'ring_id parameter error'; return false; } } ) ); $fieldsKv = array(); $errCod = 0; $errMsg = ''; foreach ($validFields as $key => $field) { $reqVal = getReqVal($key, null); if (!is_null($reqVal)) { if (isset($field['valid_func'])) { if (!$field['valid_func']($reqVal, $errCod, $errMsg)) { $this->_rspErr($errCod, $errMsg); return; } $fieldsKv[$field['field_name']] = $field['val_func']($reqVal); } } } if (count($fieldsKv) > 0) { $this->_updateUserInfo($fieldsKv); } $propertyChgService = new services\PropertyChgService(); $propertyChgService->addUserChg(); $propertyChgService->addHeroChg(); $this->_rspData(array( 'property_chg' => $propertyChgService->toDto() )); } public function info() { $targetId = getReqVal('target_id', ''); $userDb = SqlHelper::ormSelectOne ($this->_getMysql($targetId), 't_user', array( 'account_id' => $targetId ) ); if (!$userDb) { $this->_rspErr(1, 'Account does not exist'); return; } $this->_rspData(array( 'info' => User::info($userDb) )); } public function refreshUserInfo(){ $userInfo = $this->_getOrmUserInfo(); $heroDb = Hero::findByAccountId(myself()->_getAccountId(), $userInfo['hero_id']); if (!$heroDb){ $heroUniId = 0; $heroId = 0; Hero::randHero($heroUniId,$heroId); User::update(array( 'hero_id' => $heroUniId, )); $userInfo = $this->_getOrmUserInfo(); } $this->_rspData(array( 'info' => User::info($userInfo) )); } public function getMapConf() { $modeId = getReqVal('mode_id', 0); $mapId = getReqVal('map_id', 0); $mapInfo = array( 'mode_id' => intval($modeId), 'map_id' => 0, 'is_moba' => 0, 'is_open' => 0 ); if (!empty($mapId) && !empty($modeId)) { $mapMeta = mt\Map::get($mapId); $modeMeta = mt\MapMode::find($modeId); if ($mapMeta && $modeMeta) { $mapInfo = $mapMeta; $mapInfo['mode_id'] = $modeMeta['id']; } } myself()->_rspData($mapInfo); } public function getBattleInfo() { $modeId = getReqVal('mode_id', 0); $mapId = getReqVal('map_id', 0); $mapInfo = array( 'mode_id' => intval($modeId), 'map_id' => 0, 'is_moba' => 0, 'is_open' => 0 ); if (!empty($mapId) && !empty($modeId)) { $mapMeta = mt\Map::get($mapId); $modeMeta = mt\MapMode::find($modeId); if ($mapMeta) { $mapInfo = $mapMeta; $mapInfo['mode_id'] = $modeMeta['id']; } } $userDb = SqlHelper::ormSelectOne (myself()->_getSelfMysql(), 't_user', array( 'account_id' => myself()->_getAccountId() ) ); if (!$userDb) { $this->_rspErr(1, 'Account does not exist'); return; } $userInfo = User::Info($userDb); $this->fillBattleUserInfo($userInfo); $heroDb = Hero::findByAccountId(myself()->_getAccountId(), $userInfo['hero_uniid']); if (!$heroDb) { $this->_rspErr(1, 'Hero does not exist'); return; } $heroInfo = Hero::toDto($heroDb); $heroInfo['avatar_info'] = Hero::avatarInfo($heroDb); { $preset = HeroPreset::getHeroPreset($userDb['hero_id']); $heroInfo['spec_skill'] = '' . $preset['skill_id']; } myself()->_rspData(array( 'info' => array( 'user_info' => $userInfo, 'hero_info' => $heroInfo, 'map_info' => $mapInfo ) )); } public function getBattleUser() { $userDb = SqlHelper::ormSelectOne (myself()->_getSelfMysql(), 't_user', array( 'account_id' => myself()->_getAccountId() ) ); if (!$userDb) { $this->_rspErr(1, 'Account does not exist'); return; } $userInfo = User::Info($userDb); $this->fillBattleUserInfo($userInfo); $heroDb = Hero::findByAccountId(myself()->_getAccountId(), $userInfo['hero_uniid']); if (!$heroDb) { $this->_rspErr(1, 'Hero does not exist'); return; } $heroInfo = Hero::toDto($heroDb); $heroInfo['avatar_info'] = Hero::avatarInfo($heroDb); { $preset = HeroPreset::getHeroPreset($userDb['hero_id']); $heroInfo['spec_skill'] = '' . $preset['skill_id']; } myself()->_rspData(array( 'info' => array( 'user_info' => $userInfo, 'hero_info' => $heroInfo, ) )); } public function updateBattleInfo() { $specSkill = getReqVal("skill_id", ""); $heroUniId = getReqVal("hero_uniid", ""); $userDb = SqlHelper::ormSelectOne (myself()->_getSelfMysql(), 't_user', array( 'account_id' => myself()->_getAccountId() ) ); if (!$userDb) { $this->_rspErr(1, 'Account does not exist'); return; } $userInfo = User::Info($userDb); $this->fillBattleUserInfo($userInfo); $heroDb = Hero::findByAccountId(myself()->_getAccountId(), $heroUniId); if (!$heroDb) { $this->_rspErr(1, 'Hero does not exist'); return; } $this->_updateUserInfo(array( 'hero_id' => $heroUniId )); $heroInfo = Hero::toDto($heroDb); $heroInfo['avatar_info'] = Hero::avatarInfo($heroDb); { HeroPreset::upsertPresetNew($heroUniId, $specSkill); $heroInfo['spec_skill'] = '' . $specSkill; } myself()->_rspData(array( 'info' => array( 'user_info' => $userInfo, 'hero_info' => $heroInfo ) )); } public function getBattleItem() { $itemId = getReqVal("item_id", ""); $itemMeta = mt\Item::get($itemId); if (empty($itemMeta)) { myself()->_rspErr(1, 'item_id not found'); return; } if ($itemMeta['type'] == mt\Item::FUNC_TYPE && in_array($itemMeta['sub_type'], array( mt\Item::LUCKY_SYMBOL_SUBTYPE, mt\Item::BATTLE_POTION_SUBTYPE ) )) { $itemNum = myself()->_callModelStatic('Bag', 'getItemCount', $itemId); $hasLuckySymbol = myself()->_callModelStatic('LuckySymbol', 'hasLuckySymbol'); if ($itemMeta['type'] == mt\Item::FUNC_TYPE && $itemMeta['sub_type'] == mt\Item::LUCKY_SYMBOL_SUBTYPE && !$hasLuckySymbol) { $this->_decItems(array( array( 'item_id' => $itemMeta['id'], 'item_num' => 1 ) )); myself()->_callModelStatic('LuckySymbol', 'add'); $hasLuckySymbol = 1; } myself()->_rspData(array( 'item_id' => $itemId, 'item_num' => $itemNum, 'item_type' => $itemMeta['type'], 'item_sub_type' => $itemMeta['sub_type'], 'has_lucky_symbol' => $hasLuckySymbol, 'total_lucky' => Hero::getAccountLuckyTemp(), )); } else { myself()->_rspErr(1, 'item_id not found'); return; } } public function query() { $name = getReqVal('name', ''); $filter = array( 'name' => $name, ); if (SERVER_ENV == _ONLINE) { $filter['channel'] = IMTBL_CHANNEL; } $userDb = SqlHelper::ormSelectOne ($this->_getMysql($name), 't_user', $filter ); if (!$userDb) { $this->_rspErr(1, 'not found'); return; } $channel = phpcommon\extractChannel($userDb['account_id']); if ($channel != IMTBL_CHANNEL) { if (SERVER_ENV == _ONLINE) { $this->_rspErr(1, 'not found'); return; } } $this->_rspData(array( 'info' => User::info($userDb) )); } public function chartInfo(){ $targetId = getReqVal('target_id', ''); $userDb = User::find($targetId); if (!$userDb) { $this->_rspErr(1, 'Account does not exist'); return; } $pvpData = array( 'game_times' => 0, 'total_kills' => 0, 'win_times' => 0, 'alive_avg' => 0, 'kills_avg' => 0, 'assist_avg' => 0, 'damage_avg' => 0, 'recover_avg' => 0, 'star_alive' => 0, 'star_kills' => 0, 'star_assist' => 0, 'star_damage' => 0, 'star_recover' => 0, ); $mobaData = array( 'game_times' => 0, 'total_kills' => 0, 'win_times' => 0, 'level_avg' => 0, 'kills_avg' => 0, 'assist_avg' => 0, 'damage_avg' => 0, 'recover_avg' => 0, 'star_level' => 0, 'star_kills' => 0, 'star_assist' => 0, 'star_damage' => 0, 'star_recover' => 0, ); $battleDb = Battle::find($targetId); if ($battleDb){ $battleData = json_decode($battleDb['battle_data'], true); $dataInfo = isset($battleData) ? getXVal($battleData, 'data', array()) : array(); $gameTimes = getXVal($dataInfo, 'total_battle_times', 0); //游戏场次 $winTimes = getXVal($dataInfo, 'total_win_times', 0); //胜利场次 // $maxWin = $winTimes > 0 ? 1 : 0; //最高胜利 // $winPer = $gameTimes > 0 ? intval($winTimes / $gameTimes) : 0; //胜率 $aliveTime = getXVal($dataInfo, 'total_alive_time', 0) / 1000; //生存时间 $alivePer = $gameTimes > 0 ? intval($aliveTime / $gameTimes) : 0; //胜率 $totalKills = getXVal($dataInfo, 'total_kills_times', 0); //总击杀 // $maxKills = getXVal($dataInfo, 'max_kills_times', 0); //最高击杀 $killsPer = $gameTimes > 0 ? intval($totalKills / $gameTimes) : 0; //场均击杀 $totalAssist = getXVal($dataInfo, 'total_assist_time', 0); //总助攻 // $maxAssist = getXVal($dataInfo, 'max_assist_time', 0); //最高助攻 $assistPer = $gameTimes > 0 ? intval($totalAssist / $gameTimes) : 0; //场均助攻 $totalDamage = getXVal($dataInfo, 'total_damage_out', 0); //总伤害 // $maxDamage = getXVal($dataInfo, 'max_damage_out', 0); //最高伤害 $damagePer = $gameTimes > 0 ? intval($totalDamage / $gameTimes) : 0; //场均伤害 $totalRecoverHp = getXVal($dataInfo, 'total_recover_hp', 0); //总回复 // $maxRecoverHp = getXVal($dataInfo, 'max_recover_hp', 0); //最高回复 $recoverHpPer = $gameTimes > 0 ? intval($totalRecoverHp / $gameTimes) : 0; //场均回复 $pvpData['game_times'] = $gameTimes; $pvpData['total_kills'] = $totalKills; $pvpData['win_times'] = $winTimes; $pvpData['alive_avg'] = $alivePer; $pvpData['kills_avg'] = $killsPer; $pvpData['assist_avg'] = $assistPer; $pvpData['damage_avg'] = $damagePer; $pvpData['recover_avg'] = $recoverHpPer; $mobaDataInfo = isset($battleData) ? getXVal($battleData, 'moba_data', array()) : array(); $gameTimesMoba = getXVal($mobaDataInfo, 'total_battle_times', 0); $winTimesMoba = getXVal($mobaDataInfo, 'total_win_times', 0); $totalLevelMoba = getXVal($mobaDataInfo, 'total_level', 1); $levelPerMoba = $gameTimesMoba > 0 ? intval($totalLevelMoba / $gameTimesMoba) : 0; $totalKillsMoba = getXVal($mobaDataInfo, 'total_kills_times', 0); $killsPerMoba = $gameTimesMoba > 0 ? intval($totalKillsMoba / $gameTimesMoba) : 0; $totalAssistMoba = getXVal($mobaDataInfo, 'total_assist_time', 0); $assistPerMoba = $gameTimesMoba > 0 ? intval($totalAssistMoba / $gameTimesMoba) : 0; $totalDamageMoba = getXVal($mobaDataInfo, 'total_damage_out', 0); $damagePerMoba = $totalDamageMoba > 0 ? intval($totalDamageMoba / $gameTimesMoba) : 0; $totalRecoverHpMoba = getXVal($mobaDataInfo, 'total_recover_hp', 0); $recoverHpPerMoba = $totalDamageMoba > 0 ? intval($totalRecoverHpMoba / $gameTimesMoba) : 0; $mobaData['game_times'] = $gameTimesMoba; $mobaData['total_kills'] = $totalKillsMoba; $mobaData['win_times'] = $winTimesMoba; $mobaData['level_avg'] = $levelPerMoba; $mobaData['kills_avg'] = $killsPerMoba; $mobaData['assist_avg'] = $assistPerMoba; $mobaData['damage_avg'] = $damagePerMoba; $mobaData['recover_avg'] = $recoverHpPerMoba; $totalBattleCount = Battle::getBattleCount(); if ($totalBattleCount >= Battle::VALID_BATTLE_COUNT){ $userChartData = GlobalData::getUserChartData(); $pvpState = isset($userChartData["pvp_state"]) ? $userChartData["pvp_state"] : 0; $mobaState = isset($userChartData["moba_state"]) ? $userChartData["moba_state"] : 0; if (!$userChartData || !$pvpState || !$mobaState){ $battlesDb = Battle::getBattleDataLimit(); $number = count($battlesDb); $totalAlivePerPvp = 0; $totalKillsPerPvp = 0; $totalAssistPerPvp = 0; $totalDamagePerPvp = 0; $totalRecoverHpPerPvp = 0; $totalKillsPerMoba = 0; $totalAssistPerMoba = 0; $totalDamagePerMoba = 0; $totalRecoverHpPerMoba = 0; $totalLevelPerMoba = 0; $totalGameTimesPvp = 0; $totalGameTimesMoba = 0; foreach ($battlesDb as $battle){ $battleDataEx = json_decode($battle['battle_data'], true); $pvpDataInfoEx = isset($battleDataEx) ? getXVal($battleDataEx, 'data', array()) : array(); $gameTimes_pvp = getXVal($pvpDataInfoEx, 'total_battle_times', 0); $aliveTimes_pvp = getXVal($pvpDataInfoEx, 'total_alive_time', 0) / 1000; $totalAlivePerPvp += $gameTimes_pvp > 0 ? ($aliveTimes_pvp / $gameTimes_pvp) : 0; $totalKills_pvp = getXVal($pvpDataInfoEx, 'total_kills_times', 0); $totalKillsPerPvp += $gameTimes_pvp > 0 ? ($totalKills_pvp / $gameTimes_pvp) : 0; $totalAssist_pvp = getXVal($pvpDataInfoEx, 'total_assist_time', 0); $totalAssistPerPvp += $gameTimes_pvp > 0 ? ($totalAssist_pvp / $gameTimes_pvp) : 0; $totalDamage_pvp = getXVal($pvpDataInfoEx, 'total_damage_out', 0); $totalDamagePerPvp += $gameTimes_pvp > 0 ? ($totalDamage_pvp / $gameTimes_pvp) : 0; $totalRecoverHp_pvp = getXVal($pvpDataInfoEx, 'total_recover_hp', 0); $totalRecoverHpPerPvp += $gameTimes_pvp > 0 ? ($totalRecoverHp_pvp / $gameTimes_pvp) : 0; $totalGameTimesPvp += $gameTimes_pvp; $mobaDataInfoEx = isset($battleData) ? getXVal($battleDataEx, 'moba_data', array()) : array(); $gameTimes_moba = getXVal($mobaDataInfoEx, 'total_battle_times', 0); $totalLevel_moba = getXVal($mobaDataInfoEx, 'total_level', 0); $totalLevelPerMoba += $gameTimes_moba > 0 ? ($totalLevel_moba / $gameTimes_moba) : 0; $totalKills_moba = getXVal($mobaDataInfoEx, 'total_kills_times', 0); $totalKillsPerMoba += $gameTimes_moba > 0 ? ($totalKills_moba / $gameTimes_moba) : 0; $totalAssist_moba = getXVal($mobaDataInfoEx, 'total_assist_time', 0); $totalAssistPerMoba += $gameTimes_moba > 0 ? ($totalAssist_moba / $gameTimes_moba) : 0; $totalDamage_moba = getXVal($mobaDataInfoEx, 'total_damage_out', 0); $totalDamagePerMoba += $gameTimes_moba > 0 ? ($totalDamage_moba / $gameTimes_moba) : 0; $totalRecoverHp_moba = getXVal($mobaDataInfoEx, 'total_recover_hp', 0); $totalRecoverHpPerMoba += $gameTimes_moba > 0 ? ($totalRecoverHp_moba / $gameTimes_moba) : 0; $totalGameTimesMoba += $gameTimes_moba; } $userChartData['pvp_server_data'] = array( "pvp_alive_avg" => round($totalAlivePerPvp / $number,2), "pvp_kills_avg" => round($totalKillsPerPvp / $number,2), "pvp_assist_avg" => round($totalAssistPerPvp / $number,2), "pvp_damage_avg" => round($totalDamagePerPvp / $number,2), "pvp_recover_avg" => round($totalRecoverHpPerPvp / $number,2), ); $userChartData["pvp_state"] = $totalGameTimesPvp >= Battle::VALID_BATTLE_COUNT ? 1 :0; if ($userChartData['pvp_server_data']['pvp_alive_avg'] == 0 || $userChartData['pvp_server_data']['pvp_kills_avg'] == 0 || $userChartData['pvp_server_data']['pvp_assist_avg'] == 0 || $userChartData['pvp_server_data']['pvp_damage_avg'] == 0 || $userChartData['pvp_server_data']['pvp_recover_avg'] == 0 ){ $userChartData["pvp_state"] = 0; } $userChartData['moba_server_data'] = array( "moba_kills_avg" => round($totalKillsPerMoba / $number,2), "moba_assist_avg" => round($totalAssistPerMoba / $number,2), "moba_damage_avg" => round($totalDamagePerMoba / $number,2), "moba_recover_avg" => round($totalRecoverHpPerMoba / $number,2), ); $userChartData["moba_state"] = $totalGameTimesMoba >= Battle::VALID_BATTLE_COUNT ? 1 :0; if ( $userChartData['moba_server_data']['moba_kills_avg'] == 0 || $userChartData['moba_server_data']['moba_assist_avg'] == 0 || $userChartData['moba_server_data']['moba_damage_avg'] == 0 || $userChartData['moba_server_data']['moba_recover_avg'] == 0 ){ $userChartData["moba_state"] = 0; } GlobalData::addUserChartData($userChartData); } $param = 0.95; $r = (2*$param-1) / (1-$param); $h = \mt\Parameter::getVal("radar_axis_min",0.2); if ($gameTimes >= Battle::VALID_GAME_TIMES){ // t=x/u r=(2s-1)/(1-s) $t1 = $userChartData['pvp_server_data']['pvp_kills_avg']>0 ? ($killsPer / $userChartData['pvp_server_data']['pvp_kills_avg']) :0; $y1 = (pow($r,$t1) - 1) / (pow($r,$t1)+$r-2); $pvpData['star_kills'] = round((1-$h) * $y1 + $h ,2); // $pvpData['star_kills'] = round((pow($r,$t1) - 1) / (pow($r,$t1)+$r-2),2); $t2 = $userChartData['pvp_server_data']['pvp_alive_avg']>0 ? ($alivePer / $userChartData['pvp_server_data']['pvp_alive_avg']) :0; $y2 = (pow($r,$t2) - 1) / (pow($r,$t2)+$r-2) ; $pvpData['star_alive'] = round((1-$h) * $y2 + $h ,2); // $pvpData['star_alive'] = round((pow($r,$t2) - 1) / (pow($r,$t2)+$r-2),2); $t3 = $userChartData['pvp_server_data']['pvp_assist_avg']>0 ? ($assistPer / $userChartData['pvp_server_data']['pvp_assist_avg']) :0; $y3 = (pow($r,$t3) - 1) / (pow($r,$t3)+$r-2) ; $pvpData['star_assist'] = round((1-$h) * $y3 + $h ,2); // $pvpData['star_assist'] = round((pow($r,$t3) - 1) / (pow($r,$t3)+$r-2),2); $t4 = $userChartData['pvp_server_data']['pvp_damage_avg']>0 ? ($damagePer / $userChartData['pvp_server_data']['pvp_damage_avg']) :0; $y4 = (pow($r,$t4) - 1) / (pow($r,$t4)+$r-2); $pvpData['star_damage'] = round((1-$h) * $y4 + $h ,2); // $pvpData['star_damage'] = round((pow($r,$t4) - 1) / (pow($r,$t4)+$r-2),2); $t5 = $userChartData['pvp_server_data']['pvp_recover_avg']>0 ? ($recoverHpPer / $userChartData['pvp_server_data']['pvp_recover_avg']) :0; $y5 = (pow($r,$t5) - 1) / (pow($r,$t5)+$r-2); $pvpData['star_recover'] = round((1-$h) * $y5 + $h ,2); // $pvpData['star_recover'] = round((pow($r,$t5) - 1) / (pow($r,$t5)+$r-2),2); } if ($gameTimesMoba >= Battle::VALID_GAME_TIMES){ $t6 = $userChartData['moba_server_data']['moba_kills_avg']>0 ? ($killsPerMoba / $userChartData['moba_server_data']['moba_kills_avg']) :0; $y6 = (pow($r,$t6) - 1) / (pow($r,$t6)+$r-2); $mobaData['star_kills'] = round((1-$h) * $y6 + $h ,2); // $mobaData['star_kills'] = round((pow($r,$t6) - 1) / (pow($r,$t6)+$r-2),2); $t8 = $userChartData['moba_server_data']['moba_assist_avg']>0 ? intval($assistPerMoba / $userChartData['moba_server_data']['moba_assist_avg']) :0; $y8 = (pow($r,$t8) - 1) / (pow($r,$t8)+$r-2); $mobaData['star_assist'] = round((1-$h) * $y8 + $h ,2); // $mobaData['star_assist'] = round((pow($r,$t8) - 1) / (pow($r,$t8)+$r-2),2); $t9 = $userChartData['moba_server_data']['moba_damage_avg']>0 ? intval($damagePerMoba / $userChartData['moba_server_data']['moba_damage_avg']) :0; $y9 = (pow($r,$t9) - 1) / (pow($r,$t9)+$r-2); $mobaData['star_damage'] = round((1-$h) * $y9 + $h ,2); // $mobaData['star_damage'] = round((pow($r,$t9) - 1) / (pow($r,$t9)+$r-2),2); $t10 = $userChartData['moba_server_data']['moba_recover_avg']>0 ? intval($recoverHpPerMoba / $userChartData['moba_server_data']['moba_recover_avg']) :0; $y10 = (pow($r,$t10) - 1) / (pow($r,$t10)+$r-2); $mobaData['star_recover'] = round((1-$h) * $y10 + $h ,2); // $mobaData['star_recover'] = round((pow($r,$t10) - 1) / (pow($r,$t10)+$r-2),2); $paramMeta = mt\Parameter::getListValue("radar_moba_level"); $y7 = ($levelPerMoba - $paramMeta[0]) / ($paramMeta[1] - $paramMeta[0]); $mobaData['star_level'] = round((1-$h) * $y7 + $h ,2); // $mobaData['star_level'] = round(($levelPerMoba - $paramMeta[0]) / ($paramMeta[1] - $paramMeta[0]),2); } } } $this->_rspData(array( 'pvpInfo' => $pvpData, 'mobaInfo' => $mobaData, )); } public function detailInfo() { $targetId = getReqVal('target_id', ''); $userDb = User::find($targetId); if (!$userDb) { $this->_rspErr(1, 'Account does not exist'); return; } $userDto = User::info($userDb); $userDto['current_rank'] = $userDb['rank']; $userDto['current_rank_score'] = $userDb['score']; $userDto['history_best_rank_score'] = $userDb['history_best_score']; $this->_rspData(array( 'info' => $userDto )); } public function like(){ $account_id = getReqVal('target_id', ''); if (! $account_id){ $this->_rspErr(1, 'target_id param error'); return; } if ($account_id == $this->_getAccountId()){ $this->_rspErr(1, 'target_id param error'); return; } $userDb = User::find($account_id); if (!$userDb){ $this->_rspErr(1, 'target_id param error'); return; } User::updateLikeCount($account_id); $this->_rspOk(); } public function updateAddressBind() { if (myself()->_getChannel() != IMTBL_CHANNEL) { phpcommon\sendError(1, 'token error'); die(); return; } $data = json_decode(file_get_contents('php://input'), true); if (empty($data)) { phpcommon\rspErr(100, 'data error'); return; } $params = array( 'jwt' => $data['jwt'] ); $url = LOGIN_URL . '?c=Login&a=verifyJwt'; $response = ''; if (!phpcommon\HttpClient::postContent ($url, json_encode($params), $response)) { echo json_encode(array( 'errcode' => 500, 'errmsg' => "server internal error", 'is_retry' => 1, 'retry_time' => 15 )); return; } // error_log($response); if (empty($response)) { echo json_encode(array( 'errcode' => 500, 'errmsg' => "server internal error", 'is_retry' => 1, 'retry_time' => 20 )); return; } $rspObj = json_decode($response, true); if ($rspObj['errcode'] != 0) { echo json_encode(array( 'errcode' => 500, 'errmsg' => "server internal error", 'is_retry' => 1, 'retry_time' => 30 )); return; } if ($rspObj['account_id'] != myself()->_getAccountId()) { myself()->_rspErr(500, 'server internal error'); return; } if (empty($rspObj['address'])) { User::Update(array( 'address' => null )); myself()->_rspOk(); return; } $address = strtolower($rspObj['address']); $oldUser = User::findByAddress($address); if ($oldUser) { if ($oldUser['account_id'] != myself()->_getAccountId()) { User::updateOther( $oldUser['account_id'], array( 'address' => null ) ); } } User::Update(array( 'address' => $address )); $propertyChgService = new services\PropertyChgService(); $propertyChgService->addUserChg(); $this->_rspData(array( 'property_chg' => $propertyChgService->toDto(), )); } public function setUserHonor(){ $token_type = getReqVal('token_type', ''); $state = getReqVal('state', ''); if (!$this->_isValidAddress()) { $this->_rspErr(1, 'address is empty'); return; } if (!UserHonor::_isValidHonorType($token_type)) { $this->_rspErr(1, 'token_type is error'); return; } UserHonor::upsert($token_type,$state); $propertyChgService = new services\PropertyChgService(); $propertyChgService->addUserChg(); $this->_rspData(array( 'property_chg' => $propertyChgService->toDto(), )); } public function getUserGameTimes(){ $targetId = getReqVal('target_id', ''); $userDb = User::find($targetId); if (!$userDb) { $this->_rspErr(1, 'Account does not exist'); return; } $battleDb = Battle::find($targetId); $gameTimes = 0; if ($battleDb){ $battleData = json_decode($battleDb['battle_data'], true); $seasonBattleData = isset($battleData) ? getXVal($battleData, 'data', array()) : array(); $gameTimes = getXVal($seasonBattleData, 'total_battle_times', 0); } $this->_rspData(array( 'data' => $gameTimes )); } public function getFreeItemList(){ $freeHero = mt\Parameter::getListValue('free_hero_list'); $this->_rspData([ 'data'=>$freeHero ]); } public function selectFreeItemS(){ $itemId = getReqVal('itemId', ''); if (!$itemId){ $this->_rspErr(1, 'param is error'); return; } $heroMeta = mt\Item::get($itemId); if (! $heroMeta || $heroMeta['type'] != \mt\Item::HERO_TYPE){ $this->_rspErr(1, 'itemId is error'); return; } $userInfo = $this->_getOrmUserInfo(); if ($userInfo['is_gain_item']){ $this->_rspErr(1, 'Have already received'); return; } $headList = emptyReplace(json_decode($userInfo['head_list'], true), array()); if ($heroMeta['hero_head'] && !in_array($heroMeta['hero_head'],$headList)){ array_push($headList,$heroMeta['hero_head']); } $addHeroMeta = \mt\Hero::get($heroMeta['id']); Hero::addFreeHero($addHeroMeta); $heroUid = SqlHelper::getLastInsertId($this->_getSelfMysql()); $fields = array( 'hero_id' => $heroUid, 'head_id' => $heroMeta['hero_head'], 'head_frame' => 60000, 'head_list' => json_encode($headList), 'head_frame_list' => json_encode(array(60000)), 'is_gain_item' => 1, ); User::update($fields); $propertyChgService = new services\PropertyChgService(); $propertyChgService->addUserChg(); $propertyChgService->addHeroChg(); $propertyChgService->addGunChg(); $this->_rspData([ 'data'=>array( 'hero_id' => $itemId, ), 'property_chg' => $propertyChgService->toDto(), ]); } public function getBattleGoldModeTimes(){ // $userInfo = $this->_getOrmUserInfo(); // $heroDb = Hero::findByAccountId(myself()->_getAccountId(), $userInfo['hero_id']); // if (!$heroDb){ // $this->_rspErr(1, 'battle hero does not exist'); // return; // } // $heroMeta = \mt\Item::get($heroDb['hero_id']); // $heroAtteMeta = mt\EconomyAttribute::findByGrade($heroMeta['relationship'],$heroDb['quality']); $this->_rspData(array( "current_times" => myself()->_getDailyV(TN_DAILY_GOLD_MODE_BATTLE_TIMES,0), // "total_times" => $heroAtteMeta['roundPerDay'], )); } private function dampingElo($userInfo){ //每天elo衰减 $time_diff = myself()->_getNowTime()-$userInfo['last_login_time']; if ($userInfo['elo'] > 1500 && floor($time_diff/86400) > 0){ $newElo = min(round(pow(log10(floor($time_diff/86400)),1.5)*350),450); $this->_updateUserInfo(array( 'elo' => $userInfo['elo'] - $newElo )); } //7天未打排位扣排位分 $last_ranking_time = $this->_getV(TN_LAST_RANKING_TIME,0); if ($last_ranking_time && floor((myself()->_getNowTime()-$last_ranking_time)/86400) >= 7){ $userDb = $this->_getOrmUserInfo(); $rank_key = mt\Rank::getRankById($userDb['rank'])?mt\Rank::getRankById($userDb['rank'])['rank_order2']:0; $paramMeta = mt\Parameter::getByName('rank_point_reduce'); if ($paramMeta){ $param_value = explode('|',$paramMeta['param_value']); $deductScore = $param_value[$rank_key-1]; if ($deductScore>0){ $newRank = $userDb['rank']; $newScore = $userDb['score'] - $deductScore; mt\Rank::calcNewRankAndScore( $newRank, $newScore); $this->_updateUserInfo(array( 'rank' => $newRank, 'score' => $newScore, )); } } } } private function createNewUserV2($userName){ $currSeasonMeta = mt\RankSeason::getCurrentSeason(); $initRank = \mt\Parameter::getVal($this->init_rank,1); $RankMeta = mt\Rank::getRankById($initRank); $initElo = \mt\Parameter::getVal($this->init_elo,1200); $fields = array( 'account_id' => $this->_getAccountId(), 'channel' => $this->_getChannel(), 'name' => $userName, 'sex' => rand() % 2, 'gold' => 0, 'diamond' => 0, 'level' => 1, 'exp' => 0, 'last_season_id' => $currSeasonMeta ? $currSeasonMeta['id'] : 0, 'score_modifytime' => $this->_getNowTime(), 'best_rank_modifytime' => $this->_getNowTime(), 'createtime' => $this->_getNowTime(), 'modifytime' => $this->_getNowTime(), 'last_login_time' => $this->_getNowTime(), 'rank' => $initRank, 'history_best_rank' => $initRank, 'score' => $RankMeta ? $RankMeta['rank_score'] : 300, 'history_best_score' => $RankMeta ? $RankMeta['rank_score'] : 300, 'elo' => $initElo, 'head_id' => 50001, 'head_list' => json_encode(array(50001)), ); $row = SqlHelper::ormSelectOne( myself()->_getAccountMysql(), 't_immutable_account', array( 'account_id' => $this->_getAccountId(), ) ); if ($row && !empty($row['address'])){ $fields['address'] = $row['address']; if (services\NftService::hasAnyNft($fields['address'])){ $fields['is_gain_item'] = 1; } } SqlHelper::upsert ($this->_getSelfMysql(), 't_user', array( 'account_id' => $this->_getAccountId() ), array( ), $fields ); } private function _updateLastSeason($userInfo){ if (! $userInfo['last_season_id']){ $currSeasonMeta = mt\RankSeason::getCurrentSeason(); if ($currSeasonMeta){ $this->_updateUserInfo(array( 'last_season_id'=>$currSeasonMeta['id'], )); } } } private function _updateSubUserAccount() { if ($this->_getChannel() == BC_POLY_CHANNEL) { $shortAccountId = $this->_getShortAccountId(myself()->_getAccountId()); SqlHelper::upsert ($this->_getSelfMysql(), 't_sub_user_bind', array( 'org_account_id' => $shortAccountId ), array( 'cur_account_id' => myself()->_getAccountId(), 'modifytime' => myself()->_getNowTime(), ), array( 'org_account_id' => $shortAccountId, 'cur_account_id' => myself()->_getAccountId(), 'createtime' => myself()->_getNowTime(), 'modifytime' => myself()->_getNowTime(), ) ); } } private function _sign(){ if (CircuitTask::_verifyLoginToday()){ myself()->_callModelStatic('CircuitTask','incTaskVal',mt\CircuitTask::LOGIN_TIMES_END,1); } //用户是否有签到记录 if (SignLog::isSignRecord()){ //有签到记录 $row = SignLog::find(); if ($row['days'] == 7){ return; } $paramMeta = \mt\Parameter::getByName('sign_daily_duration'); $end_time = myself()->_getDaySeconds($row['createtime']) + $paramMeta['param_value']*24*60*60; //判断当前时间是否结束 并且 上次签到是否领取 并且 签到时间是否满足第二天签到 if (myself()->_getNowTime() < $end_time && $row['is_receive'] && $row['sign_time'] < myself()->_getNowDaySeconds() + 6*60*60){ if($row['sign_time'] > myself()->_getNowDaySeconds()){ return; } $fieldKv = array( 'days' => function(){ return "days + 1"; }, 'is_receive' => 0, 'sign_time' => myself()->_getNowTime(), 'modifytime' => myself()->_getNowTime() ); SignLog::update($fieldKv); } }else{ //未有签到记录 SignLog::create(); } } public function getUserVip(){ $this->_rspData( array( 'vip' => User::getVipLv(myself()->_getAddress()), 'exp' => 0, ) ); } private function fillBattleUserInfo(&$userInfo) { $userInfo['total_lucky'] = Hero::getAccountLuckyTemp(); $userInfo['admission_item_num'] = myself()->_getItemCount(900006, $userInfo); $userInfo['circuit_score'] = myself()->_callModelStatic('Circuit', 'getCurrentMyScore'); $userInfo['has_lucky_symbol'] = myself()->_callModelStatic('LuckySymbol', 'hasLuckySymbol'); $userInfo['has_vip_lucky'] = myself()->_getVipRightsVal( myself()->_getMtConstant('StakingVip', 'ACCOUNT_LUCKY_INC') ); } }