phone_check.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. "gorm.io/gorm"
  9. "property-company/consts"
  10. "property-company/errors"
  11. dbmodel "property-company/model"
  12. pb_v1 "property-company/pb/v1"
  13. "git.getensh.com/common/gopkgs/database"
  14. "git.getensh.com/common/gopkgs/logger"
  15. "go.uber.org/zap"
  16. "google.golang.org/grpc/status"
  17. )
  18. // 检查手机是否存在
  19. func CheckPhone(ctx context.Context, req *pb_v1.CheckPhoneRequest) (reply *pb_v1.CheckPhoneReply, err error) {
  20. reply = &pb_v1.CheckPhoneReply{}
  21. // 捕获各个task中的异常并返回给调用者
  22. defer func() {
  23. if r := recover(); r != nil {
  24. err = fmt.Errorf("%+v", r)
  25. e := &status.Status{}
  26. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  27. logger.Error("err",
  28. zap.String("system_err", err.Error()),
  29. zap.Stack("stacktrace"))
  30. }
  31. }
  32. }()
  33. if req.Phone == ""{
  34. return nil, errors.ParamsError
  35. }
  36. p := &dbmodel.TUser{}
  37. where := map[string]interface{}{
  38. "phone":req.Phone,
  39. }
  40. err = p.Find(database.DB(), where)
  41. if err != nil && err != gorm.ErrRecordNotFound{
  42. return nil, errors.DataBaseError
  43. }
  44. if p.ID == 0 {
  45. return reply, errors.ErrRecordNotFound
  46. }
  47. company := &dbmodel.TCompany{}
  48. where = map[string]interface{}{
  49. "id":p.Cid,
  50. }
  51. err = company.Find(database.DB(), where)
  52. if err != nil && err != gorm.ErrRecordNotFound{
  53. return nil, errors.DataBaseError
  54. }
  55. if company.ID == 0 {
  56. return reply, errors.ErrRecordNotFound
  57. }
  58. if company.ApproveStatus != consts.ApproveStatusSuccess {
  59. return nil, errors.UserStatusError
  60. }
  61. return reply, nil
  62. }