passport.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "net/url"
  6. "strconv"
  7. "go-common/app/job/main/account-summary/model"
  8. "go-common/library/ecode"
  9. "go-common/library/log"
  10. )
  11. const (
  12. queryByMidURI = "/intranet/acc/queryByMid"
  13. // _AsoAccountByMid = `SELECT mid,email FROM aso_account WHERE mid=?`
  14. // _AsoAccountInfoByMid = `SELECT mid,join_ip,join_time FROM aso_account_info%d WHERE mid=?`
  15. _AsoAccountRegOriginByMid = `SELECT mid,origintype,regtype FROM aso_account_reg_origin_%d WHERE mid=?`
  16. // _AllCountryID = `SELECT id,code FROM aso_country_code`
  17. )
  18. // PassportProfile is
  19. func (d *Dao) PassportProfile(ctx context.Context, mid int64) (*model.PassportProfile, error) {
  20. params := url.Values{}
  21. params.Set("mid", strconv.FormatInt(mid, 10))
  22. var res struct {
  23. Code int `json:"code"`
  24. Data *model.PassportProfile `json:"data"`
  25. }
  26. if err := d.httpClient.Get(ctx, d.c.Host.Passport+queryByMidURI, "", params, &res); err != nil {
  27. log.Error("Failed to query by mid: %+v: %+v", params, err)
  28. return nil, err
  29. }
  30. if res.Code != 0 {
  31. log.Error("Failed to query by mid with code: %+v: %d", params, res.Code)
  32. return nil, ecode.Int(res.Code)
  33. }
  34. return res.Data, nil
  35. }
  36. // AsoAccountRegOrigin is
  37. func (d *Dao) AsoAccountRegOrigin(ctx context.Context, mid int64) (*model.AsoAccountRegOrigin, error) {
  38. row := d.PassportDB.QueryRow(ctx, fmt.Sprintf(_AsoAccountRegOriginByMid, mid%20), mid)
  39. origin := new(model.AsoAccountRegOrigin)
  40. if err := row.Scan(&origin.Mid, &origin.OriginType, &origin.RegType); err != nil {
  41. return nil, err
  42. }
  43. return origin, nil
  44. }