123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- package user
- import (
- "context"
- "encoding/json"
- "fmt"
- "gorm.io/gorm"
- "property-household/errors"
- dbmodel "property-household/model"
- pb_v1 "property-household/pb/v1"
- "git.getensh.com/common/gopkgs/database"
- "git.getensh.com/common/gopkgs/logger"
- "go.uber.org/zap"
- "google.golang.org/grpc/status"
- )
- // 修改昵称
- func UserUpdateNickName(ctx context.Context, req *pb_v1.UserUpdateNickNameRequest) (reply *pb_v1.UserUpdateNickNameReply, err error) {
- reply = &pb_v1.UserUpdateNickNameReply{}
- // 捕获各个task中的异常并返回给调用者
- defer func() {
- if r := recover(); r != nil {
- err = fmt.Errorf("%+v", r)
- e := &status.Status{}
- if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
- logger.Error("err",
- zap.String("system_err", err.Error()),
- zap.Stack("stacktrace"))
- }
- }
- }()
- if req.NickName == "" || req.Uid < 1 {
- return nil, errors.ParamsError
- }
- user := &dbmodel.TUser{}
- where := map[string]interface{}{
- "id": req.Uid,
- }
- err = user.Find(database.DB(), where)
- if err != nil && err != gorm.ErrRecordNotFound {
- return nil, errors.DataBaseError
- }
- if user.ID == 0 {
- return nil, errors.UserNotExist
- }
- uinfo := dbmodel.TUser{NickName: req.NickName}
- if err = userChange(req.Uid, uinfo); err != nil {
- return nil, err
- }
- return reply, nil
- }
|