170 lines
4.9 KiB
PHP
170 lines
4.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/EquipUpgrade.php');
|
|
require_once('mt/Season.php');
|
|
require_once('mt/SeasonPoint.php');
|
|
require_once('mt/RankReward.php');
|
|
require_once('mt/Equip.php');
|
|
require_once('mt/Hero.php');
|
|
require_once('mt/Rank.php');
|
|
|
|
require_once('services/PropertyChgService.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)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
private function createNewUser($userName, $avatarUrl)
|
|
{
|
|
$rankMeta = mt\Rank::get(1);
|
|
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' => $rankMeta ? $rankMeta['id'] : 0,
|
|
'score' => $rankMeta ? $rankMeta['min_score'] : 0,
|
|
'head_id' => 18001,
|
|
'hero_id' => 30100,
|
|
'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)
|
|
));
|
|
}
|
|
|
|
}
|