user_levelRewards.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package gatesink
  2. import (
  3. "bet24.com/log"
  4. activityservice "bet24.com/servers/micros/activityservice/proto"
  5. item "bet24.com/servers/micros/item_inventory/proto"
  6. "encoding/json"
  7. )
  8. // 处理等级礼包指令
  9. func (this *user) onLevelRewardsMsg(msg, data string) {
  10. switch msg {
  11. case "getLevelRewards": // 获取等级礼包
  12. this.getLevelRewards(msg)
  13. case "claimLevelRewards": // 领取等级奖励
  14. this.claimLevelRewards(msg, data)
  15. default:
  16. log.Release("user.onLevelRewardsMsg unhandled msg %s", msg)
  17. }
  18. }
  19. // 获取等级礼包
  20. func (this *user) getLevelRewards(msg string) {
  21. respStr := activityservice.GetLevelRewards(this.getUserId())
  22. this.WriteMsg(msg, respStr)
  23. return
  24. }
  25. // 领取等级奖励
  26. func (this *user) claimLevelRewards(msg, data string) {
  27. var req activityservice.Request
  28. var ret struct {
  29. Success bool
  30. Data []item.ItemPack
  31. }
  32. if err := json.Unmarshal([]byte(data), &req); err != nil {
  33. log.Error("user.claimLevelRewards unmarshal fail %s", data)
  34. d, _ := json.Marshal(ret)
  35. this.WriteMsg(msg, string(d))
  36. return
  37. }
  38. ret.Success, ret.Data = activityservice.ClaimLevelRewards(this.getUserId(), req.Level, req.IsAll)
  39. d, _ := json.Marshal(ret)
  40. this.WriteMsg(msg, string(d))
  41. return
  42. }