_getMysql($targetId), 't_user', array( 'account_id' => $targetId ) ); return $row ? $row : null; } public static function findByAddress($address) { $row = SqlHelper::ormSelectOne (myself()->_getMysql(''), 't_user', array( 'address' => $address ) ); return $row ? $row : null; } public static function findUserAddress($accountId) { $row = SqlHelper::ormSelectOne (myself()->_getMysql($accountId), 't_user', array( 'account_id' => $accountId ) ); return $row ? $row['address'] : null; } public static function getListByGuildId($guildId) { $rows = SqlHelper::ormSelect (myself()->_getSelfMysql(), 't_user', array( 'guild_id' => $guildId ) ); return $rows ? $rows : null; } public static function show($row) { $heroDb = Hero::findByAccountId($row['account_id'],$row['hero_id']); $heroUniid = $heroDb ? $row['hero_id'] : 0; $heroId = $heroDb ? $heroDb['hero_id'] : 0; $skinId = 0; if ($heroDb){ $skinDb = HeroSkin::find($heroDb['skin_id']); $skinId = $skinDb ? $skinDb['skin_id']:0; } $honorInfo = array(); if ($row['address']){ $honorInfo = UserHonor::info($row['address']); } $lucky = Hero::getAccountLuckyTemp(); $luckyParam = \mt\Parameter::getVal('economy_account_luck_K',0); $rangeArr = explode("|",\mt\Parameter::getVal('economy_account_luck_range',0)); $rate = ($rangeArr[1]-$rangeArr[0]) * $lucky/($lucky+$luckyParam) + $rangeArr[0]; return array( 'activated' => $row['activated'], 'rename_count' => $row['rename_count'], 'account_id' => $row['account_id'], 'address' => $row['address'], 'name' => $row['name'], 'sex' => $row['sex'], 'head_id' => $row['head_id'], 'head_frame' => $row['head_frame'], 'level' => $row['level'], 'exp' => $row['exp'], 'rank' => $row['rank'], 'history_best_rank' => $row['history_best_rank'], 'score' => $row['score'], 'history_best_score' => $row['history_best_score'], 'bceg' => cegFormat($row['bceg']), 'gold' => cegFormat($row['gold']), 'diamond' => cecFormat($row['diamond']), 'hero_uniid' => $heroUniid, 'hero_id' => $heroId, 'skin_id' => $skinId, 'first_fight' => $row['first_fight'], 'already_guide' => $row['already_guide'], 'pve_instance_id' => $row['pve_instance_id'], 'like_count' => $row['like_count'], 'head_list' => self::getHeadList($row), // 'head_list' => self::exportHeadList($row)['head_list'], // 'hero_list' => self::exportHeadList($row)['hero_list'], 'head_frame_list' => emptyReplace(json_decode($row['head_frame_list'], true), array()), 'is_gain_item' => $row['is_gain_item'], 'guild_id' => $row['guild_id'], 'guild_job' => $row['guild_job'], 'guild_name' => $row['guild_name'], 'parachute' => $row['parachute'] ? $row['parachute'] : Parachute::$parachute, 'parachute_list' => Parachute::getMyParachute(), 'ring_id' => $row['ring_id'], 'ring_list' => UserSeasonRing::ringList($row['account_id']), 'honor_info' => $honorInfo, 'account_lucky' => $lucky, 'chest_rate' => $rate, ); } public static function info($row) { $heroDb = Hero::findByAccountId($row['account_id'],$row['hero_id']); $heroUniid = $heroDb ? $row['hero_id'] : 0; $heroId = $heroDb ? $heroDb['hero_id'] : 0; $skinId = 0; if ($heroDb){ $skinDb = HeroSkin::find($heroDb['skin_id']); $skinId = $skinDb ? $skinDb['skin_id']:0; } $honorInfo = array(); if ($row['address']){ $honorInfo = UserHonor::info($row['address']); } $lucky = Hero::getAccountLuckyTemp(); $luckyParam = \mt\Parameter::getVal('economy_account_luck_K',0); $rangeArr = explode("|",\mt\Parameter::getVal('economy_account_luck_range',0)); $rate = ($rangeArr[1]-$rangeArr[0]) * $lucky/($lucky+$luckyParam) + $rangeArr[0]; return array( 'activated' => $row['activated'], 'rename_count' => $row['rename_count'], 'account_id' => $row['account_id'], 'address' => $row['address'], 'name' => $row['name'], 'sex' => $row['sex'], 'head_id' => $row['head_id'], 'head_frame' => $row['head_frame'], 'level' => $row['level'], 'exp' => $row['exp'], 'rank' => $row['rank'], 'history_best_rank' => $row['history_best_rank'], 'score' => $row['score'], 'history_best_score' => $row['history_best_score'], 'bceg' => cegFormat($row['bceg']), 'gold' => cegFormat($row['gold']), 'diamond' => cecFormat($row['diamond']), 'hero_uniid' => $heroUniid, 'hero_id' => $heroId, 'skin_id' => $skinId, 'first_fight' => $row['first_fight'], 'already_guide' => $row['already_guide'], 'head_list' => self::getHeadList($row), // 'head_list' => self::exportHeadList($row)['head_list'], // 'hero_list' => self::exportHeadList($row)['hero_list'], 'pve_instance_id' => $row['pve_instance_id'], 'like_count' => $row['like_count'], 'head_frame_list' => emptyReplace(json_decode($row['head_frame_list'], true), array()), 'is_gain_item' => $row['is_gain_item'], 'is_leader' => 0, 'guild_id' => $row['guild_id'], 'guild_job' => $row['guild_job'], 'guild_name' => $row['guild_name'], 'ring_id' => $row['ring_id'], 'ring_list' => UserSeasonRing::ringList($row['account_id']), 'parachute' => $row['parachute'] ? $row['parachute'] : Parachute::$parachute, 'parachute_list' => Parachute::getMyParachute(), 'honor_info' => $honorInfo, 'last_login_time' => $row['last_login_time'], 'account_lucky' => $lucky, 'chest_rate' => $rate, ); } public static function toSimple($row) { $heroDb = Hero::find($row['hero_id']); if ($heroDb){ $heroId = $heroDb['hero_id']; }else{ $heroUniId = 0; $heroId = 0; Hero::randHero($heroUniId,$heroId); self::update(array( 'hero_id' => $heroUniId )); } return array( 'account_id' => $row['account_id'], 'address' => $row['address'], 'name' => $row['name'], 'sex' => $row['sex'], 'head_id' => $row['head_id'], 'head_frame' => $row['head_frame'], 'level' => $row['level'], 'exp' => $row['exp'], 'rank' => $row['rank'], 'score' => $row['score'], 'gold' => cegFormat($row['gold']), 'diamond' => cecFormat($row['diamond']), 'hero_id' => $heroId, 'pve_instance_id' => $row['pve_instance_id'], 'like_count' => $row['like_count'], 'first_fight' => $row['first_fight'], ); } public static function toPreset($row){ // mt\LevelUp::getExpByLv($row['level'],$row['exp']); $heroDb = Hero::find($row['hero_id']); $heroId = 0; if ($heroDb){ $heroId = $heroDb['hero_id']; } $preset = HeroPreset::getHeroPreset($row['hero_id']); $skinDb = HeroSkin::find($heroDb['skin_id']); $honorInfo = array(); if ($row['address']){ $honorInfo = UserHonor::info($row['address']); } return array( 'account_id' => $row['account_id'], 'address' => $row['address'], 'name' => $row['name'], 'sex' => $row['sex'], 'head_id' => $row['head_id'], 'head_frame' => $row['head_frame'], 'level' => $row['level'], 'exp' => $row['exp'], 'rank' => $row['rank'], 'score' => $row['score'], // 'gold' => cegFormat($row['gold']), // 'diamond' => cecFormat($row['diamond']), 'pve_instance_id' => $row['pve_instance_id'], // 'like_count' => $row['like_count'], 'first_fight' => $row['first_fight'], 'parachute' => $row['parachute'] ? $row['parachute'] : Parachute::$parachute, 'hero_uniId' => $row['hero_id'], 'hero_id' => $heroId, 'hero_skin' =>$skinDb ? $skinDb['skin_id']:0, 'hero_lv' =>$heroDb['hero_lv'], 'presetInfo' => $preset, 'is_leader' => 0, 'is_ready' => 0, 'permission' => 0, 'honor_info' => $honorInfo, ); } public static function isValidHeadId($userInfo, $headId) { // $headList = emptyReplace(json_decode($userInfo['head_list'], true), array()); $headList = self::getHeadList($userInfo); return in_array($headId, $headList); } public static function isValidHeroId($userInfo, $heroId) { $heroDb = Hero::findByAccountId($userInfo['account_id'],$heroId); return empty($heroDb) ? false : true ; } public static function isValidHeadFrame($userInfo, $headFrame) { $headFrameList = emptyReplace(json_decode($userInfo['head_frame_list'], true), array()); return in_array($headFrame, $headFrameList); } public static function isValidParachute($parachute){ $parachuteList = Parachute::getMyParachute(); return in_array($parachute, $parachuteList); } public static function isValidRing($parachute){ $ringList = UserSeasonRing::ringList(myself()->_getAccountId()); return in_array($parachute, $ringList); } private static function getHeadList($userInfo) { $headList = emptyReplace(json_decode($userInfo['head_list'], true), array()); $rows = array(); Hero::getHeroList(function ($row) use (&$rows){ array_push($rows,$row); }); foreach ($rows as $row) { $itemMeta = mt\Item::get($row['hero_id']); if ($itemMeta && $itemMeta['hero_head'] && !in_array($itemMeta['hero_head'],$headList)) { array_push($headList, $itemMeta['hero_head']); } } return $headList; } public static function update( $fieldsKv){ SqlHelper::update (myself()->_getSelfMysql(), 't_user', array( 'account_id' => myself()->_getAccountId(), ), $fieldsKv ); } public static function updateOther($accountId, $fieldsKv){ SqlHelper::update (myself()->_getMysql($accountId), 't_user', array( 'account_id' => $accountId, ), $fieldsKv ); } public static function updateLikeCount($targetId){ SqlHelper::update (myself()->_getSelfMysql(), 't_user', array( 'account_id' => $targetId, ), array( 'like_count' => function(){ return "like_count + 1"; } ) ); } public static function getUserByRankMess($row){ // $currSeasonMeta = mt\RankSeason::getCurrentSeason(); // $gameTimes = 0; // if ($currSeasonMeta){ // $season = Season::findByAccount($row['account_id'],$currSeasonMeta['id']); // if ($season){ // $battleData = json_decode($season['battle_data'], true); // $seasonBattleData = isset($battleData) ? getXVal($battleData, 'season_data', array()) : array(); // $gameTimes = getXVal($seasonBattleData, 'total_battle_times', 0); // } // } $toDto =array( 'idx' => $row['idx'], 'account_id' => $row['account_id'], 'channel' => $row['channel'], 'name' => $row['name'], 'head_id' => $row['head_id'], 'head_frame' => $row['head_frame'], 'rank' => $row['rank'], // 'history_best_rank' => $row['history_best_rank'], 'score' => $row['score'], // 'history_best_score' => $row['history_best_score'], //排位场数 // 'rank_num' => $gameTimes, ); return $toDto; } public static function getListByRank($rank){ $field = "idx,account_id,channel,name,head_id,head_frame,rank,score"; $sql = "select {$field} from t_user where rank=:rank order by score desc,score_modifytime asc limit 20 "; $whereKv = array( "rank" => $rank, ); $rows = myself()->_getSelfMysql()->execQuery($sql,$whereKv); if (!$rows){ $rows = array(); } return $rows; } public static function getKingCount($starshine){ $sql = "select count(*) as `count` from t_user where score>:score "; $whereKv = array( "score" => $starshine, ); $count = myself()->_getSelfMysql()->execQueryOne($sql,$whereKv); return $count?$count['count']:0; } }