server_shop.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. package service
  2. import (
  3. "context"
  4. "encoding/json"
  5. "bet24.com/log"
  6. "bet24.com/servers/coreservice/client"
  7. "bet24.com/servers/coreservice/shop"
  8. "github.com/pkg/errors"
  9. )
  10. /*
  11. func (s *Server) GetExchangeRateList(ctx context.Context, args *client.Request, reply *client.Reply) error {
  12. ret := shop.GetExchangeRateList()
  13. if len(ret) > 0 {
  14. reply.Resp.RetCode = 1
  15. d, _ := json.Marshal(ret)
  16. reply.Resp.Data = string(d)
  17. }
  18. return nil
  19. }*/
  20. func (s *Server) GetShopList(ctx context.Context, args *client.Request, reply *client.Reply) error {
  21. var req client.Shop_req
  22. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  23. log.Debug("Server.GetShopList unmarshal fail %v", err)
  24. return errors.New("unmarshal error")
  25. }
  26. ret := shop.GetShopList(req.UserId, req.ShopType, req.ProductID)
  27. if len(ret) > 0 {
  28. reply.Resp.RetCode = 1
  29. d, _ := json.Marshal(ret)
  30. reply.Resp.Data = string(d)
  31. }
  32. return nil
  33. }
  34. func (s *Server) GetShopListByUserId(ctx context.Context, args *client.Request, reply *client.Reply) error {
  35. var req client.Shop_req
  36. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  37. log.Debug("Server.GetShopList unmarshal fail %v", err)
  38. return errors.New("unmarshal error")
  39. }
  40. ret := shop.GetShopListByUserId(req.ShopType, req.UserId, req.PartnerId)
  41. if len(ret) > 0 {
  42. reply.Resp.RetCode = 1
  43. d, _ := json.Marshal(ret)
  44. reply.Resp.Data = string(d)
  45. }
  46. return nil
  47. }
  48. func (s *Server) GetProduct(ctx context.Context, args *client.Request, reply *client.Reply) error {
  49. var req client.Shop_req
  50. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  51. log.Debug("Server.GetProduct unmarshal fail %v", err)
  52. return errors.New("unmarshal error")
  53. }
  54. ret := shop.GetProduct(req.UserId, req.ShopType, req.ProductID)
  55. if ret != nil {
  56. reply.Resp.RetCode = 1
  57. d, _ := json.Marshal(ret)
  58. reply.Resp.Data = string(d)
  59. }
  60. return nil
  61. }
  62. func (s *Server) Exchange(ctx context.Context, args *client.Request, reply *client.Reply) error {
  63. var req client.Shop_req
  64. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  65. log.Debug("Server.Exchange unmarshal fail %v", err)
  66. return errors.New("unmarshal error")
  67. }
  68. retCode, msg := shop.Exchange(req.UserId, req.ProductID)
  69. if msg != "" {
  70. reply.Resp.RetCode = 1
  71. d, _ := json.Marshal(client.Shop_resp{
  72. RetCode: retCode,
  73. ErrorMsg: msg,
  74. })
  75. reply.Resp.Data = string(d)
  76. }
  77. return nil
  78. }
  79. func (s *Server) ExchangeInBulk(ctx context.Context, args *client.Request, reply *client.Reply) error {
  80. var req client.Shop_req
  81. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  82. log.Debug("Server.ExchangeInBulk unmarshal fail %v", err)
  83. return errors.New("unmarshal error")
  84. }
  85. retCode, msg := shop.ExchangeInBulk(req.UserId, req.ProductIDs)
  86. if msg != "" {
  87. reply.Resp.RetCode = 1
  88. d, _ := json.Marshal(client.Shop_resp{
  89. RetCode: retCode,
  90. ErrorMsg: msg,
  91. })
  92. reply.Resp.Data = string(d)
  93. }
  94. return nil
  95. }
  96. func (s *Server) SendFirstChargeItem(ctx context.Context, args *client.Request, reply *client.Reply) error {
  97. var req client.Shop_req
  98. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  99. log.Debug("Server.SendFirstChargeItem unmarshal fail %v", err)
  100. return errors.New("unmarshal error")
  101. }
  102. retCode, msg := shop.SendFirstChargeItem(req.UserId, req.ProductID)
  103. if msg != "" {
  104. reply.Resp.RetCode = 1
  105. d, _ := json.Marshal(client.Shop_resp{
  106. RetCode: retCode,
  107. ErrorMsg: msg,
  108. })
  109. reply.Resp.Data = string(d)
  110. }
  111. return nil
  112. }
  113. func (s *Server) Recharge(ctx context.Context, args *client.Request, reply *client.Reply) error {
  114. var req client.Shop_req
  115. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  116. log.Debug("Server.Recharge unmarshal fail %v", err)
  117. return errors.New("unmarshal error")
  118. }
  119. retCode, msg := shop.Recharge(req.UserId, req.ProductID)
  120. if msg != "" {
  121. reply.Resp.RetCode = 1
  122. d, _ := json.Marshal(client.Shop_resp{
  123. RetCode: retCode,
  124. ErrorMsg: msg,
  125. })
  126. reply.Resp.Data = string(d)
  127. }
  128. return nil
  129. }
  130. /*
  131. func (s *Server) ExchangeRateInfo(ctx context.Context, args *client.Request, reply *client.Reply) error {
  132. var req client.Shop_req
  133. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  134. log.Debug("Server.ExchangeRateInfo unmarshal fail %v", err)
  135. return errors.New("unmarshal error")
  136. }
  137. ret := shop.ExchangeRateInfo(req.Currency)
  138. reply.Resp.Action = make([]string, 2)
  139. if ret != nil {
  140. reply.Resp.Action[0] = ret.CountryName
  141. reply.Resp.Action[1] = ret.Currency
  142. }
  143. return nil
  144. }*/
  145. func (s *Server) GetUserPrice(ctx context.Context, args *client.Request, reply *client.Reply) error {
  146. var req client.Shop_req
  147. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  148. log.Debug("Server.GetUserPrice unmarshal fail %v", err)
  149. return errors.New("unmarshal error")
  150. }
  151. var resp client.Shop_resp
  152. resp.Price = shop.GetUserPrice(req.UserId, req.Price)
  153. reply.Resp.RetCode = 1
  154. d, _ := json.Marshal(resp)
  155. reply.Resp.Data = string(d)
  156. return nil
  157. }