225 lines
6.9 KiB
PHP
225 lines
6.9 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');
|
|
require_once('services/NameService.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,
|
|
'head_list' => json_encode(array(18001)),
|
|
'head_frame_list' => json_encode(array(19003)),
|
|
'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 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($param1, $param2)){
|
|
$this->_rspErr(1, '参数错误名,签名校验失败');
|
|
return;
|
|
}
|
|
if (!$nameService->nameUsed($param1)){
|
|
$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()
|
|
{
|
|
$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)
|
|
));
|
|
}
|
|
|
|
}
|