elec.go 955 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package dao
  2. import (
  3. "context"
  4. "net/url"
  5. "strconv"
  6. "go-common/app/interface/main/space/model"
  7. "go-common/library/ecode"
  8. "go-common/library/net/metadata"
  9. "github.com/pkg/errors"
  10. )
  11. const (
  12. _elecURI = "/api/elec/info/query"
  13. _elecMonthRank = "1"
  14. )
  15. // ElecInfo .
  16. func (d *Dao) ElecInfo(c context.Context, mid, paymid int64) (data *model.ElecInfo, err error) {
  17. var (
  18. params = url.Values{}
  19. ip = metadata.String(c, metadata.RemoteIP)
  20. )
  21. params.Set("mid", strconv.FormatInt(mid, 10))
  22. params.Set("pay_mid", strconv.FormatInt(paymid, 10))
  23. params.Set("type", _elecMonthRank)
  24. var res struct {
  25. Code int `json:"code"`
  26. Data *model.ElecInfo `json:"data"`
  27. }
  28. if err = d.httpR.Get(c, d.elecURL, ip, params, &res); err != nil {
  29. return
  30. }
  31. if res.Code != ecode.OK.Code() {
  32. if res.Code == 500011 {
  33. return
  34. }
  35. err = errors.Wrap(ecode.Int(res.Code), d.elecURL+"?"+params.Encode())
  36. return
  37. }
  38. data = res.Data
  39. return
  40. }