作者 tangxuhui
... ... @@ -16,6 +16,13 @@ type UpdateUserInfoCommand struct {
Avatar string `cname:"头像" json:"avatar" valid:"Required"`
// 用户姓名
UserName string `cname:"用户姓名" json:"userName" valid:"Required"`
// 邮箱
Email string `cname:"用户姓名" json:"email"`
// 邮箱
Phone string `cname:"用户姓名" json:"phone"`
// 邮箱
SmsCode string `cname:"用户姓名" json:"smsCode"`
BodyKV map[string]interface{} `json:"-"`
}
func (phoneAuthResetPhoneCommand *UpdateUserInfoCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -90,6 +90,9 @@ func (srv UserService) ChangePhone(resetPhoneCommand *command.ResetPhoneCommand)
//UpdateUserBaseInfo 更新用户信息
func (srv UserService) UpdateUserBaseInfo(updateUserInfoCommand *command.UpdateUserInfoCommand) (interface{}, error) {
if err := updateUserInfoCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
user, err := creationUserGateway.UserGet(allied_creation_user.ReqGetUser{
UserId: int(updateUserInfoCommand.Operator.UserId),
... ... @@ -97,33 +100,33 @@ func (srv UserService) UpdateUserBaseInfo(updateUserInfoCommand *command.UpdateU
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, "用户不存在")
}
var (
userName string
avatar string
)
if len(updateUserInfoCommand.Avatar) > 0 {
avatar = updateUserInfoCommand.Avatar
} else {
avatar = user.UserInfo.Avatar
if _, ok := updateUserInfoCommand.BodyKV["email"]; !ok {
updateUserInfoCommand.Email = user.UserInfo.Email
}
if _, ok := updateUserInfoCommand.BodyKV["phone"]; !ok {
updateUserInfoCommand.Phone = user.UserInfo.Phone
}
if len(updateUserInfoCommand.UserName) > 0 {
userName = updateUserInfoCommand.UserName
} else {
userName = user.UserInfo.UserName
if _, ok := updateUserInfoCommand.BodyKV["smsCode"]; ok && len(updateUserInfoCommand.SmsCode) > 0 {
smsServeGateway := sms_serve.NewHttplibHttplibSmsServe()
err := smsServeGateway.CheckSmsCode(updateUserInfoCommand.Phone, updateUserInfoCommand.SmsCode)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
}
_, err = creationUserGateway.UserUpdateBaseInfo(allied_creation_user.ReqUserUpdateBaseInfo{
UserId: int64(user.UserId),
UserName: userName,
Avatar: avatar,
Phone: user.UserInfo.Phone,
Email: user.UserInfo.Email,
UserName: updateUserInfoCommand.UserName,
Avatar: updateUserInfoCommand.Avatar,
Phone: updateUserInfoCommand.Phone,
Email: updateUserInfoCommand.Email,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return map[string]interface{}{
"avatar": avatar,
"userName": userName,
"avatar": updateUserInfoCommand.Avatar,
"userName": updateUserInfoCommand.UserName,
}, nil
}
... ...
... ... @@ -92,13 +92,7 @@ func (controller *BaseController) GetOperator() domain.Operator {
Token: token,
OrgIds: loginToken.OrgIds,
}
// TODO:测试数据后期删除
//if op.UserId == 0 {
// op.UserId = 1
// op.CompanyId = 1
// op.OrgId = 1
// op.UserBaseId = 1
//}
// TODO:打印测试日志
log.Logger.Debug("operator " + json.MarshalToString(op))
return op
... ... @@ -108,6 +102,12 @@ func (controller *BaseController) GetDeviceType() string {
return controller.Ctx.Input.Header("x-mmm-devicetype")
}
func (controller *BaseController) BodyKeys() map[string]interface{} {
var bodyKV map[string]interface{}
controller.Unmarshal(&bodyKV)
return bodyKV
}
func Must(err error) {
if err != nil {
log.Logger.Error(err.Error())
... ...
... ... @@ -69,6 +69,7 @@ func (controller *UserController) UpdateUserInfo() {
return
}
cmd.Operator = controller.GetOperator()
cmd.BodyKV = controller.BodyKeys()
data, err := authService.UpdateUserBaseInfo(cmd)
controller.Response(data, err)
}
... ...