top_photo.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. _webTopPhotoURI = "/api/member/getTopPhoto"
  13. _topPhotoURI = "/api/member/getUploadTopPhoto"
  14. )
  15. // WebTopPhoto getTopPhoto from space
  16. func (d *Dao) WebTopPhoto(c context.Context, mid int64) (space *model.TopPhoto, err error) {
  17. var (
  18. params = url.Values{}
  19. remoteIP = metadata.String(c, metadata.RemoteIP)
  20. )
  21. params.Set("mid", strconv.FormatInt(mid, 10))
  22. var res struct {
  23. Code int `json:"code"`
  24. model.TopPhoto
  25. }
  26. if err = d.httpR.Get(c, d.webTopPhotoURL, remoteIP, params, &res); err != nil {
  27. log.Error("d.httpR.Get(%s,%d) error(%v)", d.webTopPhotoURL, mid, err)
  28. return
  29. }
  30. if res.Code != ecode.OK.Code() {
  31. log.Error("d.httpR.Get(%s,%d) code error(%d)", d.webTopPhotoURL, mid, res.Code)
  32. err = ecode.Int(res.Code)
  33. return
  34. }
  35. space = &res.TopPhoto
  36. return
  37. }
  38. // TopPhoto getTopPhoto from space php.
  39. func (d *Dao) TopPhoto(c context.Context, mid, vmid int64, platform, device string) (imgURL string, err error) {
  40. var (
  41. params = url.Values{}
  42. remoteIP = metadata.String(c, metadata.RemoteIP)
  43. )
  44. if mid > 0 {
  45. params.Set("mid", strconv.FormatInt(mid, 10))
  46. }
  47. params.Set("vmid", strconv.FormatInt(vmid, 10))
  48. params.Set("platform", platform)
  49. if device != "" {
  50. params.Set("device", device)
  51. }
  52. var res struct {
  53. Code int `json:"code"`
  54. Data struct {
  55. ImgURL string `json:"imgUrl"`
  56. }
  57. }
  58. if err = d.httpR.Get(c, d.topPhotoURL, remoteIP, params, &res); err != nil {
  59. log.Error("d.httpR.Get(%s,%d) error(%v)", d.topPhotoURL, mid, err)
  60. return
  61. }
  62. if res.Code != ecode.OK.Code() {
  63. log.Error("d.httpR.Get(%s,%d) code error(%d)", d.topPhotoURL, mid, res.Code)
  64. err = ecode.Int(res.Code)
  65. return
  66. }
  67. imgURL = res.Data.ImgURL
  68. return
  69. }