game2005api/webapp/controller/UserController.class.php
aozhiwei b90e48824f 1
2021-12-02 19:16:54 +08:00

170 lines
5.1 KiB
PHP

<?php
require_once('models/User.php');
require_once('models/Hero.php');
require_once('mt/Parameter.php');
require_once('mt/Drop.php');
require_once('mt/Season.php');
require_once('mt/Hero.php');
require_once('mt/Rank.php');
require_once('services/PropertyChgService.php');
require_once('services/SeasonService.php');
use phpcommon\SqlHelper;
use models\User;
use models\Hero;
class UserController extends BaseAuthedController {
public function login()
{
//$user_name = $_REQUEST['name'];
//$avatar_url = $_REQUEST['avatar_url'];
$userName = '极乐玩家';
$avatarUrl = '18003';
$userInfo = $this->_safeGetOrmUserInfo();
if (!$userInfo) {
$this->createNewUser($userName, $avatarUrl);
$userInfo = $this->_getOrmUserInfo();
}
if (!$this->loginCheck($userInfo)) {
$userInfo = $this->_getOrmUserInfo();
}
$this->_rspData(array(
'info' => User::show($userInfo)
));
}
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();
SqlHelper::upsert
($this->_getSelfMysql(),
't_user',
array(
'account_id' => $this->_getAccountId()
),
array(
),
array(
'account_id' => $this->_getAccountId(),
'name' => $userName,
'sex' => 2,
#'avatar_url' => $avatar_url,
'gold' => 10000 * 10000,
'diamond' => 10000 * 10000,
'head_frame' => 19003,
'level' => 100,
'exp' => 0,
'rank' => $initRankMeta ? $initRankMeta['rank'] : 0,
'score' => $initRankMeta ? $initRankMeta['min_score'] : 0,
'head_id' => 18001,
'hero_id' => 30100,
'last_season_id' => $currSeasonMeta ? $currSeasonMeta['id'] : 0,
'createtime' => $this->_getNowTime(),
'modifytime' => $this->_getNowTime(),
)
);
{
foreach (mt\Parameter::getListValue('creator_hero_id') as $heroId) {
$heroMeta = mt\Hero::get($heroId);
if ($heroMeta) {
Hero::addHero($heroMeta);
}
}
}
{
$this->_addItems(array(
array(
'item_id' => 16001,
'item_num' => 0,
)
));
}
}
public function update()
{
$validFields = array(
'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)
));
}
}