user_badge.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package gatesink
  2. import (
  3. "bet24.com/log"
  4. badge "bet24.com/servers/micros/badge/proto"
  5. "encoding/json"
  6. )
  7. // 处理徽章指令
  8. func (this *user) onBadgeMsg(msg, data string) {
  9. switch msg {
  10. case "getBadgeWearList": // 获取用户佩戴的徽章的列表
  11. this.getBadgeWearList(msg, data)
  12. case "getSysBadgeList": // 获取系统成就的徽章列表
  13. this.getSysBadgeList(msg)
  14. case "wearBadge": // 佩戴成就徽章
  15. this.wearBadge(msg, data)
  16. case "getUserBadgeList": // 获取用户徽章列表
  17. this.getUserBadgeList(msg)
  18. default:
  19. log.Release("user.onBadgeMsg unhandled msg %s", msg)
  20. }
  21. }
  22. // 获取用户佩戴的徽章的列表
  23. func (this *user) getBadgeWearList(msg, data string) {
  24. var req badge.Request
  25. if err := json.Unmarshal([]byte(data), &req); err != nil {
  26. log.Error("user.getBadgeWearList unmarshal fail %v", err)
  27. this.WriteMsg(msg, "[]")
  28. return
  29. }
  30. resp := badge.GetBadgeWearAndShow(req.UserId)
  31. d, _ := json.Marshal(resp)
  32. this.WriteMsg(msg, string(d))
  33. return
  34. }
  35. // 获取系统成就的徽章列表
  36. func (this *user) getSysBadgeList(msg string) {
  37. resp := badge.GetSysBadgeList()
  38. this.WriteMsg(msg, resp)
  39. return
  40. }
  41. // 佩戴成就徽章
  42. func (this *user) wearBadge(msg, data string) {
  43. var req badge.Request
  44. if err := json.Unmarshal([]byte(data), &req); err != nil {
  45. log.Error("user.wearBadge unmarshal fail %v", err)
  46. this.WriteMsg(msg, "[]")
  47. return
  48. }
  49. resp := badge.WearBadge(this.getUserId(), req.BadgeId, req.Position)
  50. this.WriteMsg(msg, resp)
  51. return
  52. }
  53. // 获取用户徽章信息
  54. func (this *user) getUserBadgeList(msg string) {
  55. resp := badge.GetUserBadgeList(this.getUserId())
  56. this.WriteMsg(msg, resp)
  57. return
  58. }