server_battlepass.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package service
  2. import (
  3. "bet24.com/log"
  4. "bet24.com/servers/coreservice/battlepass"
  5. "bet24.com/servers/coreservice/client"
  6. "context"
  7. "encoding/json"
  8. "errors"
  9. )
  10. // 成长礼包
  11. func (s *Server) GetBattlePassPacks(ctx context.Context, args *client.Request, reply *client.Reply) error {
  12. packs := battlepass.GetBattlePassPacks()
  13. if len(packs) > 0 {
  14. reply.Resp.RetCode = 1
  15. d, _ := json.Marshal(packs)
  16. reply.Resp.Data = string(d)
  17. }
  18. return nil
  19. }
  20. func (s *Server) GetUserBattlePass(ctx context.Context, args *client.Request, reply *client.Reply) error {
  21. var req client.Request_base
  22. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  23. log.Debug("Server.GetUserBattlePass unmarshal fail %v", err)
  24. return errors.New("unmarshal error")
  25. }
  26. terms := battlepass.GetUserBattlePass(req.UserId)
  27. reply.Resp.RetCode = 1
  28. d, _ := json.Marshal(terms)
  29. reply.Resp.Data = string(d)
  30. return nil
  31. }
  32. func (s *Server) UserAwardBattlePass(ctx context.Context, args *client.Request, reply *client.Reply) error {
  33. var req client.GrowthPackAward_req
  34. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  35. log.Debug("Server.UserAwardBattlePass unmarshal fail %v", err)
  36. return errors.New("unmarshal error")
  37. }
  38. var resp client.GrowthPackAward_resp
  39. resp.Succeeded, resp.ErrMsg = battlepass.UserAwardBattlePass(req.UserId, req.GrowthPackId, req.Index)
  40. if resp.Succeeded {
  41. reply.Resp.RetCode = 1
  42. }
  43. d, _ := json.Marshal(resp)
  44. reply.Resp.Data = string(d)
  45. return nil
  46. }
  47. func (s *Server) AddUserBattlePassExp(ctx context.Context, args *client.Request, reply *client.Reply) error {
  48. var req client.BattlePassAddExp_req
  49. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  50. log.Debug("Server.AddUserBattlePassExp unmarshal fail %v", err)
  51. return errors.New("unmarshal error")
  52. }
  53. battlepass.AddUserExp(req.UserId, req.Exp)
  54. return nil
  55. }