作者 yangfu

更新用户资料修改

@@ -16,6 +16,13 @@ type UpdateUserInfoCommand struct { @@ -16,6 +16,13 @@ type UpdateUserInfoCommand struct {
16 Avatar string `cname:"头像" json:"avatar" valid:"Required"` 16 Avatar string `cname:"头像" json:"avatar" valid:"Required"`
17 // 用户姓名 17 // 用户姓名
18 UserName string `cname:"用户姓名" json:"userName" valid:"Required"` 18 UserName string `cname:"用户姓名" json:"userName" valid:"Required"`
  19 + // 邮箱
  20 + Email string `cname:"用户姓名" json:"email"`
  21 + // 邮箱
  22 + Phone string `cname:"用户姓名" json:"phone"`
  23 + // 邮箱
  24 + SmsCode string `cname:"用户姓名" json:"smsCode"`
  25 + BodyKV map[string]interface{} `json:"-"`
19 } 26 }
20 27
21 func (phoneAuthResetPhoneCommand *UpdateUserInfoCommand) Valid(validation *validation.Validation) { 28 func (phoneAuthResetPhoneCommand *UpdateUserInfoCommand) Valid(validation *validation.Validation) {
@@ -90,6 +90,9 @@ func (srv UserService) ChangePhone(resetPhoneCommand *command.ResetPhoneCommand) @@ -90,6 +90,9 @@ func (srv UserService) ChangePhone(resetPhoneCommand *command.ResetPhoneCommand)
90 90
91 //UpdateUserBaseInfo 更新用户信息 91 //UpdateUserBaseInfo 更新用户信息
92 func (srv UserService) UpdateUserBaseInfo(updateUserInfoCommand *command.UpdateUserInfoCommand) (interface{}, error) { 92 func (srv UserService) UpdateUserBaseInfo(updateUserInfoCommand *command.UpdateUserInfoCommand) (interface{}, error) {
  93 + if err := updateUserInfoCommand.ValidateCommand(); err != nil {
  94 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  95 + }
93 creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{}) 96 creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
94 user, err := creationUserGateway.UserGet(allied_creation_user.ReqGetUser{ 97 user, err := creationUserGateway.UserGet(allied_creation_user.ReqGetUser{
95 UserId: int(updateUserInfoCommand.Operator.UserId), 98 UserId: int(updateUserInfoCommand.Operator.UserId),
@@ -97,33 +100,33 @@ func (srv UserService) UpdateUserBaseInfo(updateUserInfoCommand *command.UpdateU @@ -97,33 +100,33 @@ func (srv UserService) UpdateUserBaseInfo(updateUserInfoCommand *command.UpdateU
97 if err != nil { 100 if err != nil {
98 return nil, application.ThrowError(application.BUSINESS_ERROR, "用户不存在") 101 return nil, application.ThrowError(application.BUSINESS_ERROR, "用户不存在")
99 } 102 }
100 - var (  
101 - userName string  
102 - avatar string  
103 - )  
104 - if len(updateUserInfoCommand.Avatar) > 0 {  
105 - avatar = updateUserInfoCommand.Avatar  
106 - } else {  
107 - avatar = user.UserInfo.Avatar 103 +
  104 + if _, ok := updateUserInfoCommand.BodyKV["email"]; !ok {
  105 + updateUserInfoCommand.Email = user.UserInfo.Email
  106 + }
  107 + if _, ok := updateUserInfoCommand.BodyKV["phone"]; !ok {
  108 + updateUserInfoCommand.Phone = user.UserInfo.Phone
  109 + }
  110 + if _, ok := updateUserInfoCommand.BodyKV["smsCode"]; ok && len(updateUserInfoCommand.SmsCode) > 0 {
  111 + smsServeGateway := sms_serve.NewHttplibHttplibSmsServe()
  112 + err := smsServeGateway.CheckSmsCode(updateUserInfoCommand.Phone, updateUserInfoCommand.SmsCode)
  113 + if err != nil {
  114 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
108 } 115 }
109 - if len(updateUserInfoCommand.UserName) > 0 {  
110 - userName = updateUserInfoCommand.UserName  
111 - } else {  
112 - userName = user.UserInfo.UserName  
113 } 116 }
114 _, err = creationUserGateway.UserUpdateBaseInfo(allied_creation_user.ReqUserUpdateBaseInfo{ 117 _, err = creationUserGateway.UserUpdateBaseInfo(allied_creation_user.ReqUserUpdateBaseInfo{
115 UserId: int64(user.UserId), 118 UserId: int64(user.UserId),
116 - UserName: userName,  
117 - Avatar: avatar,  
118 - Phone: user.UserInfo.Phone,  
119 - Email: user.UserInfo.Email, 119 + UserName: updateUserInfoCommand.UserName,
  120 + Avatar: updateUserInfoCommand.Avatar,
  121 + Phone: updateUserInfoCommand.Phone,
  122 + Email: updateUserInfoCommand.Email,
120 }) 123 })
121 if err != nil { 124 if err != nil {
122 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 125 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
123 } 126 }
124 return map[string]interface{}{ 127 return map[string]interface{}{
125 - "avatar": avatar,  
126 - "userName": userName, 128 + "avatar": updateUserInfoCommand.Avatar,
  129 + "userName": updateUserInfoCommand.UserName,
127 }, nil 130 }, nil
128 } 131 }
129 132
@@ -92,13 +92,7 @@ func (controller *BaseController) GetOperator() domain.Operator { @@ -92,13 +92,7 @@ func (controller *BaseController) GetOperator() domain.Operator {
92 Token: token, 92 Token: token,
93 OrgIds: loginToken.OrgIds, 93 OrgIds: loginToken.OrgIds,
94 } 94 }
95 - // TODO:测试数据后期删除  
96 - //if op.UserId == 0 {  
97 - // op.UserId = 1  
98 - // op.CompanyId = 1  
99 - // op.OrgId = 1  
100 - // op.UserBaseId = 1  
101 - //} 95 +
102 // TODO:打印测试日志 96 // TODO:打印测试日志
103 log.Logger.Debug("operator " + json.MarshalToString(op)) 97 log.Logger.Debug("operator " + json.MarshalToString(op))
104 return op 98 return op
@@ -108,6 +102,12 @@ func (controller *BaseController) GetDeviceType() string { @@ -108,6 +102,12 @@ func (controller *BaseController) GetDeviceType() string {
108 return controller.Ctx.Input.Header("x-mmm-devicetype") 102 return controller.Ctx.Input.Header("x-mmm-devicetype")
109 } 103 }
110 104
  105 +func (controller *BaseController) BodyKeys() map[string]interface{} {
  106 + var bodyKV map[string]interface{}
  107 + controller.Unmarshal(&bodyKV)
  108 + return bodyKV
  109 +}
  110 +
111 func Must(err error) { 111 func Must(err error) {
112 if err != nil { 112 if err != nil {
113 log.Logger.Error(err.Error()) 113 log.Logger.Error(err.Error())
@@ -69,6 +69,7 @@ func (controller *UserController) UpdateUserInfo() { @@ -69,6 +69,7 @@ func (controller *UserController) UpdateUserInfo() {
69 return 69 return
70 } 70 }
71 cmd.Operator = controller.GetOperator() 71 cmd.Operator = controller.GetOperator()
  72 + cmd.BodyKV = controller.BodyKeys()
72 data, err := authService.UpdateUserBaseInfo(cmd) 73 data, err := authService.UpdateUserBaseInfo(cmd)
73 controller.Response(data, err) 74 controller.Response(data, err)
74 } 75 }