email_update.go 1020 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2019 githup.com. All rights reserved.
  2. // Use of this source code is governed by githup.com.
  3. package user
  4. import (
  5. "context"
  6. "github.com/jaryhe/gopkgs/database"
  7. "github.com/jaryhe/gopkgs/logger"
  8. "go.uber.org/zap"
  9. "smart-site-management/errors"
  10. dbmodel "smart-site-management/model"
  11. pb_v1 "smart-site-management/pb/v1"
  12. "time"
  13. )
  14. func EmailUpdate(ctx context.Context, req *pb_v1.EmailUpdateRequest)(reply *pb_v1.EmailUpdateReply, err error) {
  15. p := &dbmodel.TSiteUser{}
  16. where := map[string]interface{}{
  17. "id":req.Id,
  18. }
  19. // 状态判断
  20. err = p.Find(database.DB(), where, nil)
  21. if err != nil {
  22. logger.Error("EmailUpdate",
  23. zap.String("err", err.Error()))
  24. return nil, errors.DataBaseError
  25. }
  26. if p.Id == 0 {
  27. return nil, errors.NoRecordError
  28. }
  29. reply = &pb_v1.EmailUpdateReply{}
  30. values := map[string]interface{}{
  31. "email":req.Email,
  32. "updated_at":time.Now(),
  33. }
  34. err = p.Update(database.DB(), where, values)
  35. if err != nil {
  36. return nil, errors.DataBaseError
  37. }
  38. return reply, nil
  39. }