_safeGetOrmUserInfo(); if (!$userInfo) { $this->createNewUser($userName, $avatarUrl); $userInfo = $this->_getOrmUserInfo(); } if (!$this->loginCheck($userInfo)) { $userInfo = $this->_getOrmUserInfo(); } $this->_rspData(array( 'info' => User::show($userInfo) )); $this->_incDailyV(TN_DAILY_LOGINS, 0); } private function loginCheck($userInfo) { $seasonService = new services\SeasonService(); return $seasonService->checkSeason($userInfo); } private function createNewUser($userName, $avatarUrl) { $initRankMeta = mt\Rank::getInitRank(); $currSeasonMeta = mt\Season::getCurrentSeason(); $gold = 0; $diamond = 0; $heroList = array(); $haveHeadHeroList = array(); $headList = array(); $headFrameList = array(); $addItems = array(); { foreach (mt\Parameter::getListValue('creator_hero_id') as $heroId) { $heroMeta = mt\Item::get($heroId); if ($heroMeta) { Hero::addHero($heroMeta); array_push($heroList, $heroMeta); if ($heroMeta['hero_head']) { array_push($haveHeadHeroList, $heroMeta); } } } } { foreach (mt\Parameter::getListValue('creator_present_items') as $itemsStr) { list($itemId, $itemNum) = explode(':', $itemsStr); if ($itemNum > 0) { switch ($itemId) { case V_ITEM_GOLD: { $gold += $itemNum; } break; case V_ITEM_DIAMOND: { $diamond += $itemNum; } break; default: { $itemMeta = mt\Item::get($itemId); switch ($itemMeta['type']) { case mt\Item::HEAD_TYPE: { array_push($headList, $itemId); } break; case mt\Item::HEAD_FRAME_TYPE: { array_push($headFrameList, $itemId); } break; default: { array_push($addItems, array( 'item_id' => $itemId, 'item_num' => $itemNum )); } break; } } break; } } } } $headId = !empty($headList) ? $headList[rand() % count($headList)] : 0; $headFrame = !empty($headFrameList) ? $headFrameList[rand() % count($headFrameList)] : 0; $heroId = !empty($heroList) ? $heroList[rand() % count($heroList)]['id'] : 0; if ($headId == 0 || count($headList) <= 1) { $headId = !empty($haveHeadHeroList) ? $haveHeadHeroList[rand() % count($haveHeadHeroList)]['hero_head'] : 0; } SqlHelper::upsert ($this->_getSelfMysql(), 't_user', array( 'account_id' => $this->_getAccountId() ), array( ), array( 'account_id' => $this->_getAccountId(), 'name' => $userName, 'sex' => rand() % 2, #'avatar_url' => $avatar_url, 'gold' => $gold, 'diamond' => $diamond, 'head_frame' => $headFrame, 'level' => 1, 'exp' => 0, 'rank' => $initRankMeta ? $initRankMeta['rank'] : 0, 'score' => $initRankMeta ? $initRankMeta['min_score'] : 0, 'head_id' => $headId, 'hero_id' => $heroId, 'last_season_id' => $currSeasonMeta ? $currSeasonMeta['id'] : 0, 'head_list' => json_encode($headList), 'head_frame_list' => json_encode($headFrameList), 'createtime' => $this->_getNowTime(), 'modifytime' => $this->_getNowTime(), ) ); $awardService = new services\AwardService(); $propertyChgService = new services\PropertyChgService(); $this->_addItems($addItems, $awardService, $propertyChgService); } public function active() { $name = getReqVal('name', ''); $nameSign = getReqVal('name_sign', ''); $sex = getReqVal('sex', 0); $headId = getReqVal('head_id', 0); $headFrame = getReqVal('head_frame', 0); $userInfo = $this->_getOrmUserInfo(); if ($userInfo['activated']) { $this->_rspErr(10, '不能重复激活'); return; } $nameService = new services\NameService(); if (!$nameService->verifyNameSign($name, $nameSign)){ $this->_rspErr(1, '参数错误名,签名校验失败'); return; } if ($nameService->nameUsed($name)){ $this->_rspErr(2, '名字已被占用'); return; } if (!isValidSex($sex)) { $this->_rspErr(1, '参数错误名,sex不合法'); return; } if (!User::isValidHeadId($userInfo, $headId)) { $this->_rspErr(1, '参数错误名,head_id不合法'); return; } if (!User::isValidHeadFrame($userInfo, $headFrame)) { $this->_rspErr(1, '参数错误名,head_frame不合法'); return; } if (!$nameService->useName($name)) { $this->_rspErr(2, '名字已被占用'); return; } $this->_updateUserInfo(array( 'name' => $name, 'sex' => $sex, 'head_id' => $headId, 'head_frame' => $headFrame, 'activated' => 1 )); $propertyChgService = new services\PropertyChgService(); $propertyChgService->addUserChg(); $this->_rspData(array( 'property_chg' => $propertyChgService->toDto() )); } 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参数错误'; 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参数错误'; 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参数错误'; return false; } } ), 'hero_id' => array( 'field_name' => 'hero_id', 'val_func' => function ($val) { return $val; }, 'valid_func' => function ($val, &$errCode, &$errMsg) { if (Hero::find($val)) { return true; } else { $errCode = 1; $errMsg = '英雄不存在'; 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; } ) ); $fieldsKv = array(); $errCod = 0; $errMsg = ''; foreach ($validFields as $key => $field) { $reqVal = getReqVal($key, ''); if (!empty($reqVal)) { if (isset($field['valid_func'])) { if (!$field['valid_func']($reqVal, $errCode, $errMsg)) { $this->_rspErr($errCode, $errMsg); return; } $fieldsKv[$field['field_name']] = $field['val_func']($reqVal); } } } if (count($fieldsKv) > 0) { $this->_updateUserInfo($fieldsKv); } $propertyChgService = new services\PropertyChgService(); $propertyChgService->addUserChg(); $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, '账号不存在'); return; } $this->_rspData(array( 'info' => User::info($userDb) )); } public function detailInfo() { $targetId = getReqVal('target_id', ''); $userDb = SqlHelper::ormSelectOne ($this->_getMysql($targetId), 't_user', array( 'account_id' => $targetId ) ); if (!$userDb) { $this->_rspErr(1, '账号不存在'); return; } $userDto = User::info($userDb); $userDto['current_rank'] = 1; $userDto['history_best_rank'] = 1; $userDto['history_seasons'] = array( array( 'season_id' => 0, 'total_kills' => 0, 'game_times' => 0, 'win_times' => 0, 'win_rate' => 0, 'max_kills' => 0, 'avg_kills' => 0, 'max_damage_out' => 0, 'avg_damage_out' => 0, 'star_kills' => 0, 'star_damage' => 0, 'star_alive' => 0, 'star_recover' => 0, 'star_win' => 0, ) ); $this->_rspData(array( 'info' => $userDto )); } }