dao.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package shop
  2. import (
  3. "context"
  4. "net/url"
  5. "strconv"
  6. "go-common/app/interface/main/app-interface/conf"
  7. "go-common/app/interface/main/app-interface/model/shop"
  8. "go-common/library/ecode"
  9. httpx "go-common/library/net/http/blademaster"
  10. "go-common/library/net/metadata"
  11. "github.com/pkg/errors"
  12. )
  13. const _info = "/api/merchants/shop/info"
  14. type Dao struct {
  15. client *httpx.Client
  16. info string
  17. }
  18. func New(c *conf.Config) (d *Dao) {
  19. d = &Dao{
  20. client: httpx.NewClient(c.HTTPClient),
  21. info: c.Host.Show + _info,
  22. }
  23. return
  24. }
  25. func (d *Dao) Info(c context.Context, mid int64, mobiApp, device string, build int) (info *shop.Info, err error) {
  26. ip := metadata.String(c, metadata.RemoteIP)
  27. params := url.Values{}
  28. params.Set("mid", strconv.FormatInt(mid, 10))
  29. params.Set("mobi_app", mobiApp)
  30. params.Set("device", device)
  31. params.Set("build", strconv.Itoa(build))
  32. var res struct {
  33. Code int `json:"errno"`
  34. Data *shop.Info `json:"data"`
  35. }
  36. if err = d.client.Get(c, d.info, ip, params, &res); err != nil {
  37. return
  38. }
  39. if res.Code != ecode.OK.Code() {
  40. if res.Code == 130000 {
  41. return
  42. }
  43. err = errors.Wrap(ecode.Int(res.Code), d.info+"?"+params.Encode())
  44. return
  45. }
  46. info = res.Data
  47. return
  48. }