831 lines
30 KiB
PHP
831 lines
30 KiB
PHP
<?php
|
|
|
|
require_once('models/User.php');
|
|
require_once('models/Hero.php');
|
|
require_once('models/Season.php');
|
|
require_once('models/Nft.php');
|
|
require_once('models/Gun.php');
|
|
require_once('models/UserSeasonRing.php');
|
|
require_once('models/Chip.php');
|
|
require_once('models/Battle.php');
|
|
require_once('models/SignLog.php');
|
|
require_once('models/UserHonor.php');
|
|
|
|
require_once('mt/Parameter.php');
|
|
require_once('mt/Drop.php');
|
|
require_once('mt/Season.php');
|
|
require_once('mt/RankSeason.php');
|
|
require_once('mt/Hero.php');
|
|
require_once('mt/Rank.php');
|
|
require_once('mt/Item.php');
|
|
require_once('mt/PveGeminiMode.php');
|
|
require_once('mt/PveGemini.php');
|
|
|
|
require_once('services/AwardService.php');
|
|
require_once('services/PropertyChgService.php');
|
|
require_once('services/SeasonService.php');
|
|
require_once('services/NameService.php');
|
|
require_once('services/ChipPageService.php');
|
|
|
|
use phpcommon\SqlHelper;
|
|
use models\User;
|
|
use models\Hero;
|
|
use models\Gun;
|
|
use models\Season;
|
|
use models\Nft;
|
|
use models\Chip;
|
|
use models\UserSeasonRing;
|
|
use models\Battle;
|
|
use models\SignLog;
|
|
use models\UserHonor;
|
|
|
|
class UserController extends BaseAuthedController {
|
|
private $init_rank = 'rank_init_rank';
|
|
private $init_elo = 'rank_init_elo';
|
|
|
|
public function login()
|
|
{
|
|
$this->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);
|
|
//初始化芯片页
|
|
$chipPageObj = new services\ChipPageService();
|
|
$chipPageObj->init();
|
|
}
|
|
//elo score 衰减
|
|
$this->dampingElo($userInfo);
|
|
$userInfo = $this->_getOrmUserInfo();
|
|
//跟新登录时间
|
|
$this->_updateUserInfo(array(
|
|
'last_login_time'=>myself()->_getNowTime(),
|
|
));
|
|
if ($this->_getChannel() == BC_CHANNEL &&
|
|
empty($userInfo['address'])
|
|
) {
|
|
User::Update(array(
|
|
'address' => $this->_getOpenId()
|
|
));
|
|
$userInfo['address'] = $this->_getOpenId();
|
|
}
|
|
$this->_updateLastSeason($userInfo);
|
|
$this->_sign();
|
|
$this->_rspData(array(
|
|
'info' => User::show($userInfo),
|
|
));
|
|
$this->_incDailyV(TN_DAILY_LOGINS, 0, 1);
|
|
}
|
|
|
|
private function _setBattleHero($userInfo){
|
|
$heroUniId = 0;
|
|
$heroId = 0;
|
|
Hero::randHero($heroUniId,$heroId);
|
|
$heroMeta = mt\Item::get($heroId);
|
|
$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']);
|
|
}
|
|
User::update(array(
|
|
'hero_id' => $heroUniId,
|
|
'head_id' => $heroMeta['hero_head'],
|
|
'head_frame' => 60000,
|
|
'head_list' => json_encode($headList),
|
|
'head_frame_list' => json_encode(array(60000)),
|
|
));
|
|
}
|
|
|
|
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 (SERVER_ENV == _TEST) {
|
|
|
|
array_push($addItems,
|
|
array(
|
|
'item_id' => V_ITEM_GOLD,
|
|
'item_num' => 500000
|
|
));
|
|
$itemIds = array(30100,30200,30300,30400,30500,30600,30700,30800,30900,31000,40702,40902,40102);
|
|
foreach ($itemIds as $row){
|
|
array_push($addItems,
|
|
array(
|
|
'item_id' => $row,
|
|
'item_num' => 1
|
|
));
|
|
}
|
|
}
|
|
|
|
$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);
|
|
}
|
|
|
|
private function createNewUser($userName, $avatarUrl)
|
|
{
|
|
$initRankParameterMeta = mt\Parameter::getByName($this->init_rank);
|
|
$initRankMeta = mt\Rank::getRankById($initRankParameterMeta['param_value']);
|
|
$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;
|
|
$heroUniId = 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;
|
|
}
|
|
//Hero::randHero($heroUniId, $heroId);
|
|
$fields = array(
|
|
'account_id' => $this->_getAccountId(),
|
|
'channel' => $this->_getChannel(),
|
|
'name' => $userName,
|
|
'sex' => rand() % 2,
|
|
#'avatar_url' => $avatar_url,
|
|
'gold' => $gold,
|
|
'diamond' => $diamond,
|
|
'head_frame' => $headFrame,
|
|
'level' => 1,
|
|
'exp' => 0,
|
|
'rank' => $initRankMeta ? $initRankMeta['id'] : 1,
|
|
'history_best_rank' => $initRankMeta ? $initRankMeta['id'] : 1,
|
|
'score' => $initRankMeta ? $initRankMeta['rank_score'] : 0,
|
|
'history_best_score' => $initRankMeta ? $initRankMeta['rank_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),
|
|
'score_modifytime' => $this->_getNowTime(),
|
|
'best_rank_modifytime' => $this->_getNowTime(),
|
|
'createtime' => $this->_getNowTime(),
|
|
'modifytime' => $this->_getNowTime(),
|
|
'last_login_time' => $this->_getNowTime(),
|
|
);
|
|
if ($this->_getChannel() == BC_CHANNEL) {
|
|
$fields['address'] = $this->_getOpenId();
|
|
}
|
|
|
|
SqlHelper::upsert
|
|
($this->_getSelfMysql(),
|
|
't_user',
|
|
array(
|
|
'account_id' => $this->_getAccountId()
|
|
),
|
|
array(
|
|
),
|
|
$fields
|
|
);
|
|
$awardService = new services\AwardService();
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$this->_addItems($addItems, $awardService, $propertyChgService);
|
|
}
|
|
|
|
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) {
|
|
if (User::isValidHeroId($userInfo, $val)) {
|
|
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 query()
|
|
{
|
|
$name = getReqVal('name', '');
|
|
$filter = array(
|
|
'name' => $name,
|
|
);
|
|
if (SERVER_ENV == _ONLINE) {
|
|
$filter['channel'] = BC_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 != BC_CHANNEL) {
|
|
if (SERVER_ENV == _ONLINE) {
|
|
$this->_rspErr(1, 'not found');
|
|
return;
|
|
}
|
|
}
|
|
$this->_rspData(array(
|
|
'info' => User::info($userDb)
|
|
));
|
|
}
|
|
|
|
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'];
|
|
$userDto['history_seasons'] = array();
|
|
$seasonDbs = Season::getHistorySeasons($targetId);
|
|
$battleDb = Battle::find($targetId);
|
|
// foreach ($seasonDbs as $seasonDb) {
|
|
// $battleData = json_decode($seasonDb['battle_data'], true);
|
|
if ($battleDb){
|
|
$battleData = json_decode($battleDb['battle_data'], true);
|
|
$seasonBattleData = isset($battleData) ? getXVal($battleData, 'data', array()) : array();
|
|
$gameTimes = getXVal($seasonBattleData, 'total_battle_times', 0);
|
|
$winTimes = getXVal($seasonBattleData, 'total_win_times', 0);
|
|
$winRate = $gameTimes > 0 ? intval($winTimes / $gameTimes * 100) : 0;
|
|
$totalKills = getXVal($seasonBattleData, 'total_kills_times', 0);
|
|
$totalDamage = getXVal($seasonBattleData, 'total_damage_out', 0);
|
|
$totalAlive = getXVal($seasonBattleData, 'total_alive_time', 0);
|
|
$totalRecoverHp = getXVal($seasonBattleData, 'total_recover_hp', 0);
|
|
$avgDamage = $gameTimes > 0 ? intval($totalDamage / $gameTimes) : 0;
|
|
$avgKills = $gameTimes > 0 ? intval($totalKills / $gameTimes) : 0;
|
|
$starKills = $gameTimes > 0 ? intval($totalKills / $gameTimes / 10 *100) : 0;
|
|
$starDamage = $gameTimes > 0 ? intval($totalDamage / $gameTimes / 1500 * 100) : 0;
|
|
$starAlive = $gameTimes > 0 ? intval($totalAlive / $gameTimes / 300 * 0.1) : 0;
|
|
$starRecover = $gameTimes > 0 ? intval($totalRecoverHp / $gameTimes / 300 * 100) : 0;
|
|
$starWin = $gameTimes > 0 ? intval($winTimes / $gameTimes / 0.5 * 100) : 0;
|
|
array_push($userDto['history_seasons'],
|
|
array(
|
|
// 'season_id' => $seasonDb['season_id'],
|
|
'total_kills' => $totalKills,
|
|
'game_times' => $gameTimes,
|
|
'win_times' => $winTimes,
|
|
'win_rate' => $winRate,
|
|
'max_kills' => getXVal($seasonBattleData, 'max_kills_times', 0),
|
|
'avg_kills' => $avgKills,
|
|
'max_damage_out' => getXVal($seasonBattleData, 'max_damage_out', 0),
|
|
'avg_damage_out' => $avgDamage,
|
|
'star_kills' => min(100, $starKills),
|
|
'star_damage' => min(100, $starDamage),
|
|
'star_alive' => min(100, $starAlive),
|
|
'star_recover' => min(100, $starRecover),
|
|
'star_win' => min(100, $starWin),
|
|
));
|
|
}
|
|
if (count($userDto['history_seasons']) <= 0) {
|
|
// $currSeasonMeta = mt\Season::getCurrentSeason();
|
|
array_push($userDto['history_seasons'],
|
|
array(
|
|
// 'season_id' => $currSeasonMeta['id'],
|
|
'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' => min(100, 0),
|
|
'star_damage' => min(100, 0),
|
|
'star_alive' => min(100, 0),
|
|
'star_recover' => min(100, 0),
|
|
'star_win' => min(100, 0),
|
|
));
|
|
}
|
|
$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() != BC_POLY_CHANNEL) {
|
|
phpcommon\sendError(1, 'token error');
|
|
die();
|
|
return;
|
|
}
|
|
error_log(json_encode($_REQUEST));
|
|
$jwt = getReqVal('jwt', '');
|
|
|
|
$arr = explode('.', $jwt);
|
|
if (count($arr) < 3) {
|
|
phpcommon\sendError(1, 'token error');
|
|
die();
|
|
return;
|
|
}
|
|
$header = base64_decode($arr[0]);
|
|
$payload = base64_decode($arr[1]);
|
|
$sign = base64_decode($arr[2]);
|
|
$data = json_decode($payload, true);
|
|
|
|
$subIdxPre = '';
|
|
$subIdx = getXVal($data, 'version', '');
|
|
if (!empty($subIdx)) {
|
|
$subIdxPre = 's' . $subIdx . '_';
|
|
}
|
|
{
|
|
$jwtAccountId = BC_POLY_CHANNEL . '_' . myself()->_getGameId() . '_' .
|
|
$subIdxPre . $data['plat'] . '_' . $data['openid'];
|
|
if ($jwtAccountId != myself()->_getAccountId()) {
|
|
myself()->_rspErr(1, 'token error3');
|
|
return;
|
|
}
|
|
}
|
|
|
|
//$url = 'https://pay.cebggame.com/wallet/info?';
|
|
$url = 'https://oauth-svr.cebggame.com/test/wallet/info?';
|
|
$params = array(
|
|
'token' => $jwt
|
|
);
|
|
$response = '';
|
|
if (!phpcommon\HttpClient::get
|
|
($url,
|
|
$params,
|
|
$response)) {
|
|
myself()->_rspErr(500, 'server internal error');
|
|
die();
|
|
return;
|
|
}
|
|
error_log($response);
|
|
$rspObj = json_decode($response, true);
|
|
if (empty($rspObj['data']['address'])) {
|
|
User::Update(array(
|
|
'address' => null
|
|
));
|
|
myself()->_rspOk();
|
|
die();
|
|
return;
|
|
}
|
|
$address = strtolower($rspObj['data']['address']);
|
|
$oldUser = User::findByAddress($address);
|
|
if ($oldUser) {
|
|
if ($oldUser['account_id'] != myself()->_getAccountId()) {
|
|
if (!phpcommon\isSameSeriesAccount(
|
|
$oldUser['account_id'],
|
|
myself()->_getAccountId()
|
|
)) {
|
|
myself()->_rspErr(1, 'is not SameSeriesAccount');
|
|
return;
|
|
}
|
|
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(),
|
|
));
|
|
error_log(11111111111111111111111111);
|
|
}
|
|
|
|
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
|
|
));
|
|
}
|
|
|
|
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,
|
|
);
|
|
if ($this->_getChannel() == BC_CHANNEL) {
|
|
$fields['address'] = $this->_getOpenId();
|
|
}
|
|
|
|
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 _sign(){
|
|
//用户是否有签到记录
|
|
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();
|
|
}
|
|
}
|
|
|
|
}
|