This commit is contained in:
aozhiwei 2021-11-29 14:18:02 +08:00
parent 11d3b7cdf4
commit b933b7f747
2 changed files with 39 additions and 2 deletions

View File

@ -30,6 +30,7 @@ class User(object):
],
'response': [
_common.RspHead(),
['info',_common.UserInfo(), '更新后的用户信息'],
]
},
{
@ -43,7 +44,7 @@ class User(object):
],
'response': [
_common.RspHead(),
['info',_common.UserInfo(), '用户信息']
['info',_common.UserInfo(), '用户信息'],
]
},
{

View File

@ -94,8 +94,44 @@ class UserController extends BaseAuthedController {
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;
}
}
)
);
$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);
}
$this->_rspData(array(
'info' => User::info($this->_getUserInfo())
));
}
public function info()