phone_check.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package user
  4. import (
  5. "context"
  6. "encoding/json"
  7. "fmt"
  8. "property-system/errors"
  9. dbmodel "property-system/model"
  10. pb_v1 "property-system/pb/v1"
  11. "git.getensh.com/common/gopkgs/database"
  12. "git.getensh.com/common/gopkgs/logger"
  13. "go.uber.org/zap"
  14. "google.golang.org/grpc/status"
  15. )
  16. // 检查手机是否存在
  17. func CheckPhone(ctx context.Context, req *pb_v1.CheckPhoneRequest) (reply *pb_v1.CheckPhoneReply, err error) {
  18. reply = &pb_v1.CheckPhoneReply{}
  19. // 捕获各个task中的异常并返回给调用者
  20. defer func() {
  21. if r := recover(); r != nil {
  22. err = fmt.Errorf("%+v", r)
  23. e := &status.Status{}
  24. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  25. logger.Error("err",
  26. zap.String("system_err", err.Error()),
  27. zap.Stack("stacktrace"))
  28. }
  29. }
  30. }()
  31. if req.Phone == ""{
  32. return nil, errors.ParamsError
  33. }
  34. p := &dbmodel.TUser{}
  35. where := map[string]interface{}{
  36. "phone":req.Phone,
  37. }
  38. count, err := p.Count(database.DB(), where, nil)
  39. if err != nil {
  40. return nil, errors.DataBaseError
  41. }
  42. if count == 0 {
  43. return reply, errors.ErrRecordNotFound
  44. }
  45. return reply, nil
  46. }