pb.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. package proto
  2. import (
  3. "context"
  4. "bet24.com/log"
  5. "bet24.com/servers/micros/common"
  6. "github.com/smallnest/rpcx/client"
  7. )
  8. const ServiceName = "badgeservice"
  9. var consulAddr = common.Default_Consul_Addr
  10. func getClient() client.XClient {
  11. return common.GetClientPool().GetClient(ServiceName, consulAddr)
  12. }
  13. type Request struct {
  14. UserId int `json:",omitempty"`
  15. Model int `json:",omitempty"`
  16. BadgeId int `json:",omitempty"`
  17. Position int `json:",omitempty"`
  18. Name string `json:",omitempty"`
  19. IpAddress string `json:",omitempty"`
  20. Action int `json:",omitempty"`
  21. Progress int `json:",omitempty"`
  22. Param Scope `json:",omitempty"`
  23. }
  24. type Response struct {
  25. RetCode int
  26. Data string
  27. Badges []BadgePosition
  28. }
  29. func SetConsulAddr(addr string) {
  30. consulAddr = addr
  31. }
  32. func SayHello(name string) string {
  33. xclient := getClient()
  34. //defer xclient.Close()
  35. args := &Request{
  36. Name: name,
  37. }
  38. reply := &Response{}
  39. err := xclient.Call(context.Background(), "SayHello", args, reply)
  40. if err != nil {
  41. log.Debug("%s failed to call: %v", ServiceName, err)
  42. common.GetClientPool().RemoveClient(ServiceName)
  43. return ""
  44. }
  45. log.Debug("userLabel return %s", reply.Data)
  46. return reply.Data
  47. }
  48. // 获取系统成就的徽章列表
  49. func GetSysBadgeList() string {
  50. xclient := getClient()
  51. //defer xclient.Close()
  52. args := &Request{}
  53. reply := &Response{}
  54. err := xclient.Call(context.Background(), "GetSysBadgeList", args, reply)
  55. if err != nil {
  56. log.Debug("%s failed to call: %v", ServiceName, err)
  57. common.GetClientPool().RemoveClient(ServiceName)
  58. return "[]"
  59. }
  60. return reply.Data
  61. }
  62. // 获取用户徽章佩戴与展示
  63. func GetBadgeWearAndShow(userId int) []BadgePosition {
  64. xclient := getClient()
  65. //defer xclient.Close()
  66. args := &Request{
  67. UserId: userId,
  68. }
  69. reply := &Response{}
  70. err := xclient.Call(context.Background(), "GetBadgeWearAndShow", args, reply)
  71. if err != nil {
  72. log.Debug("%s failed to call: %v", ServiceName, err)
  73. common.GetClientPool().RemoveClient(ServiceName)
  74. return nil
  75. }
  76. return reply.Badges
  77. }
  78. // 获取用户徽章列表
  79. func GetUserBadgeList(userId int) string {
  80. xclient := getClient()
  81. //defer xclient.Close()
  82. args := &Request{
  83. UserId: userId,
  84. }
  85. reply := &Response{}
  86. err := xclient.Call(context.Background(), "GetUserBadgeList", args, reply)
  87. if err != nil {
  88. log.Debug("%s failed to call: %v", ServiceName, err)
  89. common.GetClientPool().RemoveClient(ServiceName)
  90. return "[]"
  91. }
  92. if reply.Data == "" {
  93. return "[]"
  94. }
  95. return reply.Data
  96. }
  97. // 佩戴成就徽章
  98. func WearBadge(userId, badgeId, position int) string {
  99. xclient := getClient()
  100. //defer xclient.Close()
  101. args := &Request{
  102. UserId: userId,
  103. BadgeId: badgeId,
  104. Position: position,
  105. }
  106. reply := &Response{}
  107. err := xclient.Call(context.Background(), "WearBadge", args, reply)
  108. if err != nil {
  109. log.Debug("%s failed to call: %v", ServiceName, err)
  110. common.GetClientPool().RemoveClient(ServiceName)
  111. return "[]"
  112. }
  113. if reply.Data == "" {
  114. return "[]"
  115. }
  116. return reply.Data
  117. }
  118. // 触发动作(徽章进度)
  119. func DoAction(userId, action, progress int, param Scope) {
  120. xclient := getClient()
  121. //defer xclient.Close()
  122. args := &Request{
  123. UserId: userId,
  124. Action: action,
  125. Progress: progress,
  126. Param: param,
  127. }
  128. reply := &Response{}
  129. err := xclient.Call(context.Background(), "DoAction", args, reply)
  130. if err != nil {
  131. log.Debug("%s failed to call: %v", ServiceName, err)
  132. common.GetClientPool().RemoveClient(ServiceName)
  133. }
  134. return
  135. }