vip.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package dao
  2. import (
  3. "context"
  4. "net/url"
  5. v1 "go-common/app/service/main/account/api"
  6. "go-common/library/ecode"
  7. "go-common/library/net/metadata"
  8. "go-common/library/xstr"
  9. "github.com/pkg/errors"
  10. )
  11. var (
  12. _emptyVipInfos3 = map[int64]*v1.VipInfo{}
  13. )
  14. // RawVip get mid's vip info from account center by vip API.
  15. func (d *Dao) RawVip(c context.Context, mid int64) (vip *v1.VipInfo, err error) {
  16. params := url.Values{}
  17. var res struct {
  18. Code int `json:"code"`
  19. Data struct {
  20. Type int32 `json:"vipType"`
  21. Status int32 `json:"vipStatus"`
  22. DueDate int64 `json:"vipDueDate"`
  23. VipPayType int32 `json:"isAutoRenew"`
  24. } `json:"data"`
  25. }
  26. err = d.httpR.RESTfulGet(c, d.vipInfoURI, metadata.String(c, metadata.RemoteIP), params, &res, mid)
  27. if err != nil {
  28. err = errors.Wrap(err, "dao vip")
  29. return
  30. }
  31. if res.Code != 0 {
  32. err = ecode.Int(res.Code)
  33. err = errors.Wrap(err, "dao vip")
  34. return
  35. }
  36. vip = &v1.VipInfo{
  37. Type: res.Data.Type,
  38. Status: res.Data.Status,
  39. DueDate: res.Data.DueDate,
  40. VipPayType: res.Data.VipPayType,
  41. }
  42. return
  43. }
  44. // RawVips get multi mid's vip info from account center by vip API.
  45. func (d *Dao) RawVips(c context.Context, mids []int64) (res map[int64]*v1.VipInfo, err error) {
  46. params := url.Values{}
  47. params.Set("idList", xstr.JoinInts(mids))
  48. var info struct {
  49. Code int `json:"code"`
  50. Data map[int64]*struct {
  51. Type int32 `json:"vipType"`
  52. Status int32 `json:"vipStatus"`
  53. DueDate int64 `json:"vipDueDate"`
  54. } `json:"data"`
  55. }
  56. err = d.httpR.Get(c, d.vipMultiInfoURI, "", params, &info)
  57. if err != nil {
  58. err = errors.Wrap(err, "dao vip")
  59. return
  60. }
  61. if info.Code != 0 {
  62. err = ecode.Int(info.Code)
  63. err = errors.Wrap(err, "dao vip")
  64. return
  65. }
  66. if len(info.Data) == 0 {
  67. res = _emptyVipInfos3
  68. return
  69. }
  70. res = make(map[int64]*v1.VipInfo, len(info.Data))
  71. for mid, v := range info.Data {
  72. if v == nil {
  73. continue
  74. }
  75. vip := &v1.VipInfo{
  76. Type: v.Type,
  77. Status: v.Status,
  78. DueDate: v.DueDate,
  79. }
  80. res[mid] = vip
  81. }
  82. return
  83. }