shop.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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/log"
  9. "go-common/library/net/metadata"
  10. )
  11. const (
  12. _shopURI = "/mall-shop/merchant/enter/service/shop/info"
  13. _shopLinkURI = "/mall-shop/merchant/enter/service/shop/get"
  14. )
  15. // ShopInfo get shop info data for pc.
  16. func (d *Dao) ShopInfo(c context.Context, mid int64) (data *model.ShopInfo, err error) {
  17. params := url.Values{}
  18. params.Set("mid", strconv.FormatInt(mid, 10))
  19. var res struct {
  20. Code int `json:"code"`
  21. Data struct {
  22. Shop *model.ShopInfo `json:"shop"`
  23. } `json:"data"`
  24. }
  25. if err = d.httpR.Get(c, d.shopURL, metadata.String(c, metadata.RemoteIP), params, &res); err != nil {
  26. log.Error("ShopInfo(%s) mid(%d) error(%v)", d.shopURL+params.Encode(), mid, err)
  27. return
  28. }
  29. if res.Code != ecode.OK.Code() {
  30. log.Error("ShopInfo(%s) mid(%d) code(%d) error", d.shopURL+params.Encode(), mid, res.Code)
  31. err = ecode.SpaceNoShop
  32. return
  33. }
  34. data = res.Data.Shop
  35. return
  36. }
  37. // ShopLink only get simply data for h5.
  38. func (d *Dao) ShopLink(c context.Context, mid int64, platform int) (data *model.ShopLinkInfo, err error) {
  39. params := url.Values{}
  40. params.Set("mid", strconv.FormatInt(mid, 10))
  41. params.Set("type", strconv.Itoa(platform))
  42. var res struct {
  43. Code int `json:"code"`
  44. Data *model.ShopLinkInfo `json:"data"`
  45. }
  46. if err = d.httpR.Get(c, d.shopLinkURL, metadata.String(c, metadata.RemoteIP), params, &res); err != nil {
  47. log.Error("ShopLink(%s) mid(%d) error(%v)", d.shopLinkURL+params.Encode(), mid, err)
  48. return
  49. }
  50. if res.Code != ecode.OK.Code() {
  51. log.Error("ShopLink(%s) mid(%d) code(%d) error", d.shopLinkURL+params.Encode(), mid, res.Code)
  52. err = ecode.SpaceNoShop
  53. return
  54. }
  55. data = res.Data
  56. return
  57. }