wx_account_apply_info.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package company
  4. import (
  5. "context"
  6. "encoding/json"
  7. "fmt"
  8. "git.getensh.com/common/gopkgs/database"
  9. "git.getensh.com/common/gopkgs/logger"
  10. "go.uber.org/zap"
  11. "google.golang.org/grpc/status"
  12. "gorm.io/gorm"
  13. "property-company/errors"
  14. dbmodel "property-company/model"
  15. pb_v1 "property-company/pb/v1"
  16. )
  17. func checkCompanyWxAccountApplyInfoParam(req *pb_v1.CompanyWxAccountApplyInfoRequest) error {
  18. if (req.Cid == 0 && !req.Management) || req.Id == 0 {
  19. return errors.ParamsError
  20. }
  21. return nil
  22. }
  23. //
  24. func CompanyWxAccountApplyInfo(ctx context.Context, req *pb_v1.CompanyWxAccountApplyInfoRequest) (reply *pb_v1.CompanyWxAccountApplyInfoReply, err error) {
  25. reply = &pb_v1.CompanyWxAccountApplyInfoReply{}
  26. // 捕获各个task中的异常并返回给调用者
  27. defer func() {
  28. if r := recover(); r != nil {
  29. err = fmt.Errorf("%+v", r)
  30. e := &status.Status{}
  31. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  32. logger.Error("err",
  33. zap.String("system_err", err.Error()),
  34. zap.Stack("stacktrace"))
  35. }
  36. }
  37. }()
  38. err = checkCompanyWxAccountApplyInfoParam(req)
  39. if err != nil {
  40. return nil, err
  41. }
  42. merchant := dbmodel.TWxMerchantInfo{}
  43. where := map[string]interface{}{
  44. "id": req.Id,
  45. }
  46. if req.Cid > 0 {
  47. where["cid"] = req.Cid
  48. }
  49. err = merchant.Find(database.DB(), where)
  50. if err != nil && err != gorm.ErrRecordNotFound {
  51. return nil, errors.DataBaseError
  52. }
  53. if merchant.ID == 0 {
  54. return nil, errors.ErrRecordNotFound
  55. }
  56. reply.Id = merchant.ID
  57. subjectInfo := pb_v1.CompanyWxSubjectInfo{}
  58. businessInfo := pb_v1.CompanyWxBusinessInfo{}
  59. bankInfo := pb_v1.CompanyWxBankAccountInfo{}
  60. contactInfo := pb_v1.CompanyWxContactInfo{}
  61. _ = json.Unmarshal([]byte(merchant.SubjectInfo), &subjectInfo)
  62. _ = json.Unmarshal([]byte(merchant.BusinessInfo), &businessInfo)
  63. _ = json.Unmarshal([]byte(merchant.BankAccountInfo), &bankInfo)
  64. _ = json.Unmarshal([]byte(merchant.ContactInfo), &contactInfo)
  65. reply.ContactInfo = &contactInfo
  66. reply.BusinessInfo = &businessInfo
  67. reply.SubjectInfo = &subjectInfo
  68. reply.BankAccountInfo = &bankInfo
  69. if reply.SubjectInfo.CertInfo == nil {
  70. reply.SubjectInfo.CertInfo = &pb_v1.CompanyWxCertificateInfo{}
  71. }
  72. if reply.SubjectInfo.IdentityInfo.IdDocInfo == nil {
  73. reply.SubjectInfo.IdentityInfo.IdDocInfo = &pb_v1.CompanyWxIdDocInfo{}
  74. }
  75. return reply, nil
  76. }