用户信息添加hero_uniid自动

This commit is contained in:
aozhiwei 2021-12-31 11:03:03 +08:00
parent 9f3f3fde5a
commit 5ed06adc39
6 changed files with 40 additions and 5 deletions

View File

@ -61,7 +61,7 @@ class User(object):
['sex', 0, '更新性别(可选参数,不传就不更新)'], ['sex', 0, '更新性别(可选参数,不传就不更新)'],
['head_id', 0, '更新头像(可选参数,不传就不更新)'], ['head_id', 0, '更新头像(可选参数,不传就不更新)'],
['head_frame', 0, '更新头像框(可选参数,不传就不更新)'], ['head_frame', 0, '更新头像框(可选参数,不传就不更新)'],
['hero_id', 0, '更新上阵英雄id(可选参数,不传就不更新)'], ['hero_uniid', 0, '更新上阵英雄唯一id(可选参数,不传就不更新)'],
['first_fight', 0, '更新首次战斗(可选参数,不传就不更新)'] ['first_fight', 0, '更新首次战斗(可选参数,不传就不更新)']
], ],
'response': [ 'response': [

View File

@ -57,6 +57,7 @@ class UserInfo(object):
['history_best_rank', 0, '历史最高段位'], ['history_best_rank', 0, '历史最高段位'],
['gold', 0, '金币'], ['gold', 0, '金币'],
['diamond', 0, '钻石'], ['diamond', 0, '钻石'],
['hero_uniid', 0, '当前使用的英雄唯一ID'],
['hero_id', 0, '当前使用的英雄ID'], ['hero_id', 0, '当前使用的英雄ID'],
['first_fight', 0, '是否是第一次战斗'], ['first_fight', 0, '是否是第一次战斗'],
['!head_list', [0], '拥有的头像列表'], ['!head_list', [0], '拥有的头像列表'],
@ -77,6 +78,7 @@ class UserDetailInfo(object):
['max_exp', 0, '经验(上限)'], ['max_exp', 0, '经验(上限)'],
['gold', 0, '金币'], ['gold', 0, '金币'],
['diamond', 0, '钻石'], ['diamond', 0, '钻石'],
['hero_uniid', 0, '当前使用的英雄唯一ID'],
['hero_id', 0, '当前使用的英雄ID'], ['hero_id', 0, '当前使用的英雄ID'],
['current_rank', 0, '当前段位'], ['current_rank', 0, '当前段位'],
['history_best_rank', 0, '历史最高段位'], ['history_best_rank', 0, '历史最高段位'],

View File

@ -40,6 +40,7 @@ CREATE TABLE `t_user` (
`score` int(11) NOT NULL DEFAULT '0' COMMENT '积分', `score` int(11) NOT NULL DEFAULT '0' COMMENT '积分',
`gold` int(11) NOT NULL DEFAULT '0' COMMENT '金币', `gold` int(11) NOT NULL DEFAULT '0' COMMENT '金币',
`diamond` int(11) NOT NULL DEFAULT '0' COMMENT '钻石', `diamond` int(11) NOT NULL DEFAULT '0' COMMENT '钻石',
`hero_uniid` int(11) NOT NULL DEFAULT '0' COMMENT '当前上阵英雄唯一id',
`hero_id` int(11) NOT NULL DEFAULT '0' COMMENT '当前上阵英雄id', `hero_id` int(11) NOT NULL DEFAULT '0' COMMENT '当前上阵英雄id',
`first_fight` int(11) NOT NULL DEFAULT '0' COMMENT '是否首战', `first_fight` int(11) NOT NULL DEFAULT '0' COMMENT '是否首战',
`last_season_id` int(11) NOT NULL DEFAULT '0' COMMENT '最后一次赛季id', `last_season_id` int(11) NOT NULL DEFAULT '0' COMMENT '最后一次赛季id',

View File

@ -119,11 +119,13 @@ class UserController extends BaseAuthedController {
} }
$headId = !empty($headList) ? $headList[rand() % count($headList)] : 0; $headId = !empty($headList) ? $headList[rand() % count($headList)] : 0;
$headFrame = !empty($headFrameList) ? $headFrameList[rand() % count($headFrameList)] : 0; $headFrame = !empty($headFrameList) ? $headFrameList[rand() % count($headFrameList)] : 0;
$heroUniId = 0;
$heroId = !empty($heroList) ? $heroList[rand() % count($heroList)]['id'] : 0; $heroId = !empty($heroList) ? $heroList[rand() % count($heroList)]['id'] : 0;
if ($headId == 0 || count($headList) <= 1) { if ($headId == 0 || count($headList) <= 1) {
$headId = !empty($haveHeadHeroList) ? $headId = !empty($haveHeadHeroList) ?
$haveHeadHeroList[rand() % count($haveHeadHeroList)]['hero_head'] : 0; $haveHeadHeroList[rand() % count($haveHeadHeroList)]['hero_head'] : 0;
} }
Hero::randHero($heroUniId, $heroId);
SqlHelper::upsert SqlHelper::upsert
($this->_getSelfMysql(), ($this->_getSelfMysql(),
't_user', 't_user',
@ -146,6 +148,7 @@ class UserController extends BaseAuthedController {
'history_best_rank' => $initRankMeta ? $initRankMeta['rank'] : 1, 'history_best_rank' => $initRankMeta ? $initRankMeta['rank'] : 1,
'score' => $initRankMeta ? $initRankMeta['min_score'] : 0, 'score' => $initRankMeta ? $initRankMeta['min_score'] : 0,
'head_id' => $headId, 'head_id' => $headId,
'hero_uniid' => $heroUniId,
'hero_id' => $heroId, 'hero_id' => $heroId,
'last_season_id' => $currSeasonMeta ? $currSeasonMeta['id'] : 0, 'last_season_id' => $currSeasonMeta ? $currSeasonMeta['id'] : 0,
'head_list' => json_encode($headList), 'head_list' => json_encode($headList),
@ -216,6 +219,7 @@ class UserController extends BaseAuthedController {
public function update() public function update()
{ {
$userInfo = $this->_getOrmUserInfo(); $userInfo = $this->_getOrmUserInfo();
$heroId = $userInfo['hero_id'];
$validFields = array( $validFields = array(
'sex' => array( 'sex' => array(
'field_name' => 'sex', 'field_name' => 'sex',
@ -262,13 +266,15 @@ class UserController extends BaseAuthedController {
} }
} }
), ),
'hero_id' => array( 'hero_uniid' => array(
'field_name' => 'hero_id', 'field_name' => 'hero_uniid',
'val_func' => function ($val) { 'val_func' => function ($val) {
return $val; return $val;
}, },
'valid_func' => function ($val, &$errCode, &$errMsg) { 'valid_func' => function ($val, &$errCode, &$errMsg) use (&$heroId) {
if (Hero::find($val)) { $heroDb = Hero::find($val);
if ($heroDb) {
$heroId = $heroDb['hero_id'];
return true; return true;
} else { } else {
$errCode = 1; $errCode = 1;

View File

@ -44,6 +44,7 @@ class Hero extends BaseModel {
} }
$tradeLocktime = max(0, $row['unlock_trade_time'] - myself()->_getNowTime()); $tradeLocktime = max(0, $row['unlock_trade_time'] - myself()->_getNowTime());
$dto = array( $dto = array(
'hero_uniid' => $row['idx'],
'hero_id' => $row['hero_id'], 'hero_id' => $row['hero_id'],
'hero_lv' => $row['hero_lv'], 'hero_lv' => $row['hero_lv'],
'hero_tili' => $row['hero_tili'], 'hero_tili' => $row['hero_tili'],
@ -127,4 +128,27 @@ class Hero extends BaseModel {
); );
} }
public static function randHero(&$heroUniId, &$heroId)
{
$heroUniId = 0;
$heroId = 0;
$rows = SqlHelper::select(
myself()->_getSelfMysql(),
't_hero',
array(
'idx',
'hero_id'
),
array(
'account_id' => myself()->_getAccountId(),
'state' => self::GETED_STATE
)
);
$key = array_rand($rows, 1);
if (!is_null($key)) {
$heroUniId = $rows[$key]['idx'];
$heroId = $rows[$key]['hero_id'];
}
}
} }

View File

@ -38,6 +38,7 @@ class User extends BaseModel {
'score' => $row['score'], 'score' => $row['score'],
'gold' => $row['gold'], 'gold' => $row['gold'],
'diamond' => $row['diamond'], 'diamond' => $row['diamond'],
'hero_uniid' => $row['hero_uniid'],
'hero_id' => $row['hero_id'], 'hero_id' => $row['hero_id'],
'first_fight' => $row['first_fight'], 'first_fight' => $row['first_fight'],
'head_list' => self::getHeadList($row), 'head_list' => self::getHeadList($row),
@ -62,6 +63,7 @@ class User extends BaseModel {
'score' => $row['score'], 'score' => $row['score'],
'gold' => $row['gold'], 'gold' => $row['gold'],
'diamond' => $row['diamond'], 'diamond' => $row['diamond'],
'hero_uniid' => $row['hero_uniid'],
'hero_id' => $row['hero_id'], 'hero_id' => $row['hero_id'],
'first_fight' => $row['first_fight'], 'first_fight' => $row['first_fight'],
'head_list' => self::getHeadList($row), 'head_list' => self::getHeadList($row),