server_agent.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. package service
  2. import (
  3. "context"
  4. "encoding/json"
  5. "errors"
  6. "bet24.com/log"
  7. "bet24.com/servers/coreservice/agent"
  8. "bet24.com/servers/coreservice/client"
  9. )
  10. // 刷新配置
  11. func (s *Server) AgentRefreshConfig(ctx context.Context, args *client.Request, reply *client.Reply) error {
  12. agent.RefreshConfig()
  13. reply.Resp.RetCode = 1
  14. reply.Resp.Data = ""
  15. return nil
  16. }
  17. // 获取配置信息
  18. func (s *Server) AgentConfigs(ctx context.Context, args *client.Request, reply *client.Reply) error {
  19. info := agent.GetJsonConfigs()
  20. reply.Resp.RetCode = 1
  21. reply.Resp.Data = info
  22. return nil
  23. }
  24. // 代理申请
  25. func (s *Server) AgentApply(ctx context.Context, args *client.Request, reply *client.Reply) error {
  26. var req client.AgentApply_req
  27. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  28. log.Debug("Server.AgentApply unmarshal fail %v", err)
  29. return errors.New("unmarshal error")
  30. }
  31. retCode := agent.Apply(req.UserId, req.Memo)
  32. d, _ := json.Marshal(retCode)
  33. reply.Resp.RetCode = 1
  34. reply.Resp.Data = string(d)
  35. return nil
  36. }
  37. // 代理绑码
  38. func (s *Server) AgentBind(ctx context.Context, args *client.Request, reply *client.Reply) error {
  39. var req client.AgentBind_req
  40. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  41. log.Debug("Server.AgentBind unmarshal fail %v", err)
  42. return errors.New("unmarshal error")
  43. }
  44. var respData struct {
  45. RetCode int
  46. Items interface{}
  47. }
  48. respData.RetCode, respData.Items = agent.Bind(req.UserId, req.HigherUserId)
  49. d, _ := json.Marshal(respData)
  50. reply.Resp.RetCode = 1
  51. reply.Resp.Data = string(d)
  52. return nil
  53. }
  54. // 代理信息
  55. func (s *Server) AgentInfo(ctx context.Context, args *client.Request, reply *client.Reply) error {
  56. var req client.Request_base
  57. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  58. log.Debug("Server.AgentInfo unmarshal fail %v", err)
  59. return errors.New("unmarshal error")
  60. }
  61. info := agent.Info(req.UserId)
  62. d, _ := json.Marshal(info)
  63. reply.Resp.RetCode = 1
  64. reply.Resp.Data = string(d)
  65. return nil
  66. }
  67. // 会员
  68. func (s *Server) AgentMembers(ctx context.Context, args *client.Request, reply *client.Reply) error {
  69. var req client.Agent_req
  70. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  71. log.Debug("Server.AgentMembers unmarshal fail %v", err)
  72. return errors.New("unmarshal error")
  73. }
  74. info := agent.Members(req.UserId, req.PageIndex, req.PageSize)
  75. d, _ := json.Marshal(info)
  76. reply.Resp.RetCode = 1
  77. reply.Resp.Data = string(d)
  78. return nil
  79. }
  80. // 代理统计
  81. func (s *Server) AgentStat(ctx context.Context, args *client.Request, reply *client.Reply) error {
  82. var req client.Agent_req
  83. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  84. log.Debug("Server.AgentStat unmarshal fail %v", err)
  85. return errors.New("unmarshal error")
  86. }
  87. info := agent.Stat(req.UserId, req.PageIndex, req.PageSize)
  88. d, _ := json.Marshal(info)
  89. reply.Resp.RetCode = 1
  90. reply.Resp.Data = string(d)
  91. return nil
  92. }
  93. // 收益记录
  94. func (s *Server) AgentCommissionLog(ctx context.Context, args *client.Request, reply *client.Reply) error {
  95. var req client.Agent_req
  96. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  97. log.Debug("Server.AgentCommissionLog unmarshal fail %v", err)
  98. return errors.New("unmarshal error")
  99. }
  100. info := agent.CommissionLog(req.UserId, req.FromUserId, req.PageIndex, req.PageSize)
  101. d, _ := json.Marshal(info)
  102. reply.Resp.RetCode = 1
  103. reply.Resp.Data = string(d)
  104. return nil
  105. }
  106. // 提取收益
  107. func (s *Server) AgentCommissionToAmount(ctx context.Context, args *client.Request, reply *client.Reply) error {
  108. var req client.Request_base
  109. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  110. log.Debug("Server.AgentCommissionToAmount unmarshal fail %v", err)
  111. return errors.New("unmarshal error")
  112. }
  113. var info struct {
  114. RetCode int
  115. Commission int
  116. }
  117. info.RetCode, info.Commission = agent.CommissionToAmount(req.UserId, req.IpAddress)
  118. d, _ := json.Marshal(info)
  119. reply.Resp.RetCode = 1
  120. reply.Resp.Data = string(d)
  121. return nil
  122. }
  123. // 获取群组
  124. func (s *Server) AgentGetGroup(ctx context.Context, args *client.Request, reply *client.Reply) error {
  125. var req client.Request_base
  126. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  127. log.Debug("Server.AgentGroup json unmarshal fail %v", err)
  128. return errors.New("unmarshal error")
  129. }
  130. ret := agent.GetGroup(req.UserId)
  131. d, _ := json.Marshal(ret)
  132. reply.Resp.RetCode = 1
  133. reply.Resp.Data = string(d)
  134. return nil
  135. }
  136. // 修改群组
  137. func (s *Server) AgentUpdateGroup(ctx context.Context, args *client.Request, reply *client.Reply) error {
  138. var req client.AgentGroup_req
  139. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  140. log.Debug("Server.AgentUpdateGroup json unmarshal fail %v", err)
  141. return errors.New("unmarshal error")
  142. }
  143. ret := agent.UpdateGroup(req.UserId, req.Id, req.Name, req.Url)
  144. d, _ := json.Marshal(ret)
  145. reply.Resp.RetCode = 1
  146. reply.Resp.Data = string(d)
  147. return nil
  148. }