vip.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. package vip
  2. import (
  3. "context"
  4. "strconv"
  5. "go-common/app/interface/main/account/conf"
  6. "go-common/app/interface/main/account/dao/vip"
  7. "go-common/app/interface/main/account/model"
  8. mrl "go-common/app/service/main/relation/model"
  9. rlrpc "go-common/app/service/main/relation/rpc/client"
  10. resmdl "go-common/app/service/main/resource/model"
  11. rscrpc "go-common/app/service/main/resource/rpc/client"
  12. v1 "go-common/app/service/main/vip/api"
  13. vipmod "go-common/app/service/main/vip/model"
  14. viprpc "go-common/app/service/main/vip/rpc/client"
  15. "go-common/library/log"
  16. "go-common/library/net/metadata"
  17. "github.com/pkg/errors"
  18. )
  19. // Service .
  20. type Service struct {
  21. // conf
  22. c *conf.Config
  23. // http
  24. vipDao *vip.Dao
  25. // vip rpc
  26. vipRPC *viprpc.Service
  27. relationRPC *rlrpc.Service
  28. resourceRPC *rscrpc.Service
  29. // vip service
  30. vipgRPC v1.VipClient
  31. }
  32. // New create service instance and return.
  33. func New(c *conf.Config) (s *Service) {
  34. s = &Service{
  35. c: c,
  36. vipDao: vip.New(c),
  37. vipRPC: viprpc.New(c.RPCClient2.Vip),
  38. relationRPC: rlrpc.New(c.RPCClient2.Relation),
  39. resourceRPC: rscrpc.New(c.RPCClient2.Resource),
  40. }
  41. vipgRPC, err := v1.NewClient(c.VipClient)
  42. if err != nil {
  43. panic(err)
  44. }
  45. s.vipgRPC = vipgRPC
  46. return
  47. }
  48. // OrderStatus .
  49. func (s *Service) OrderStatus(c context.Context, arg *vipmod.ArgDialog) (res *vipmod.OrderResult, err error) {
  50. if res, err = s.vipRPC.OrderPayResult(c, arg); err != nil {
  51. return
  52. }
  53. if res == nil || res.Dialog == nil {
  54. log.Warn("s.vipRPC.OrderPayResult(%+v) get nil", arg)
  55. return
  56. }
  57. if res.Dialog.Follow {
  58. var (
  59. f *mrl.Following
  60. ferr error
  61. ip = metadata.String(c, metadata.RemoteIP)
  62. ar = &mrl.ArgRelation{Mid: arg.Mid, Fid: s.c.Vipproperty.OfficialMid, RealIP: ip}
  63. )
  64. if f, ferr = s.relationRPC.Relation(c, ar); ferr != nil {
  65. log.Error("s.Relation(%+v) err(%v)", ar, ferr)
  66. return
  67. }
  68. if f == nil {
  69. return
  70. }
  71. // 如果已经关注就隐藏关注模块
  72. res.Dialog.Follow = !f.Following()
  73. }
  74. return
  75. }
  76. //Unfrozen user unfrozen vip
  77. func (s *Service) Unfrozen(c context.Context, mid int64) (err error) {
  78. if err = s.vipRPC.Unfrozen(c, mid); err != nil {
  79. err = errors.WithStack(err)
  80. return
  81. }
  82. return
  83. }
  84. //FrozenTime get frozen time
  85. func (s *Service) FrozenTime(c context.Context, mid int64) (stime int64, err error) {
  86. if stime, err = s.vipRPC.SurplusFrozenTime(c, mid); err != nil {
  87. err = errors.WithStack(err)
  88. return
  89. }
  90. return
  91. }
  92. // ResourceBanner .
  93. func (s *Service) ResourceBanner(c context.Context, arg *model.ArgResource) (res []*resmdl.Banner, err error) {
  94. resID := ""
  95. if model.IsIPhone(arg.Plat) {
  96. resID = model.ResourceBannerIPhone
  97. }
  98. if model.IsAndroid(arg.Plat) {
  99. resID = model.ResourceBannerAndroid
  100. }
  101. if model.IsIPad(arg.Plat) {
  102. resID = model.ResourceBannerIPad
  103. }
  104. var argb = &resmdl.ArgBanner{
  105. Plat: arg.Plat,
  106. Build: arg.Build,
  107. MID: arg.MID,
  108. ResIDs: resID,
  109. Channel: "master",
  110. IP: metadata.String(c, metadata.RemoteIP),
  111. Buvid: arg.Buvid,
  112. Network: arg.Network,
  113. MobiApp: arg.MobiApp,
  114. Device: arg.Device,
  115. }
  116. bs, err := s.resourceRPC.Banners(c, argb)
  117. if err != nil || bs == nil {
  118. log.Error("s.resourceRPC.Banners(%v) error(%+v) or bs is nil", argb, err)
  119. return
  120. }
  121. if len(bs.Banner) > 0 {
  122. var rid int
  123. rid, err = strconv.Atoi(resID)
  124. if err != nil {
  125. err = errors.WithStack(err)
  126. return
  127. }
  128. res = bs.Banner[rid]
  129. }
  130. return
  131. }
  132. // ResourceBuy .
  133. func (s *Service) ResourceBuy(c context.Context, arg *model.ArgResource) (res []*resmdl.Banner, err error) {
  134. resID := ""
  135. if model.IsIPhone(arg.Plat) {
  136. resID = model.ResourceBuyIPhone
  137. }
  138. if model.IsAndroid(arg.Plat) {
  139. resID = model.ResourceBuyAndroid
  140. }
  141. if model.IsIPad(arg.Plat) {
  142. resID = model.ResourceBuyIPad
  143. }
  144. log.Info("ResourceBuy resID(%s) arg(%+v)", resID, arg)
  145. var argb = &resmdl.ArgBanner{
  146. Plat: arg.Plat,
  147. Build: arg.Build,
  148. MID: arg.MID,
  149. ResIDs: resID,
  150. Channel: "master",
  151. IP: metadata.String(c, metadata.RemoteIP),
  152. Buvid: arg.Buvid,
  153. Network: arg.Network,
  154. MobiApp: arg.MobiApp,
  155. Device: arg.Device,
  156. }
  157. bs, err := s.resourceRPC.Banners(c, argb)
  158. if err != nil || bs == nil {
  159. log.Error("s.resourceRPC.Banners(%v) error(%+v) or bs is nil", argb, err)
  160. return
  161. }
  162. log.Info("s.resourceRPC.Banners(%+v)", bs.Banner)
  163. if len(bs.Banner) > 0 {
  164. var rid int
  165. rid, err = strconv.Atoi(resID)
  166. if err != nil {
  167. err = errors.WithStack(err)
  168. return
  169. }
  170. res = bs.Banner[rid]
  171. }
  172. return
  173. }