handler.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package handler
  2. import (
  3. "bet24.com/log"
  4. "bet24.com/servers/micros/activityservice/handler/dailywheel"
  5. "bet24.com/servers/micros/activityservice/handler/giftpack"
  6. "bet24.com/servers/micros/activityservice/handler/levelrewards"
  7. "bet24.com/servers/micros/activityservice/handler/novicewelfare"
  8. "bet24.com/servers/micros/activityservice/handler/savingpot"
  9. "bet24.com/servers/micros/activityservice/handler/signin"
  10. pb "bet24.com/servers/micros/activityservice/proto"
  11. robot "bet24.com/servers/micros/userservices/proto"
  12. "context"
  13. "fmt"
  14. )
  15. var instance *activityservice
  16. type activityservice struct {
  17. }
  18. func GetInstance() *activityservice {
  19. if instance == nil {
  20. instance = newHandler()
  21. }
  22. return instance
  23. }
  24. func newHandler() *activityservice {
  25. ret := new(activityservice)
  26. ret.ctor()
  27. return ret
  28. }
  29. func (h *activityservice) ctor() {
  30. novicewelfare.Run()
  31. dailywheel.Run()
  32. levelrewards.Run()
  33. signin.Run()
  34. savingpot.Run()
  35. }
  36. func Dump(cmd, param1, param2 string) {
  37. GetInstance().dump(cmd, param1, param2)
  38. }
  39. func (h *activityservice) dump(cmd, param1, param2 string) {
  40. switch cmd {
  41. case "novicewelfare":
  42. novicewelfare.Dump(param1, param2)
  43. case "giftpack":
  44. giftpack.Dump(param1, param2)
  45. case "dailywheel":
  46. dailywheel.Dump(param1, param2)
  47. case "levelrewards":
  48. levelrewards.Dump(param1, param2)
  49. case "signin":
  50. signin.Dump(param1, param2)
  51. case "savingpot":
  52. savingpot.Dump(param1, param2)
  53. default:
  54. log.Release("activityservice.Dump unhandled cmd %s", cmd)
  55. }
  56. }
  57. func (h *activityservice) SayHello(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
  58. rsp.Data = fmt.Sprintf("Hello from %s:%s", pb.ServiceName, req.Name)
  59. return nil
  60. }
  61. func (h *activityservice) AddUser(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
  62. if robot.IsRobot(req.UserId) {
  63. return nil
  64. }
  65. novicewelfare.OnUserEnter(req.UserId)
  66. giftpack.OnUserEnter(req.UserId)
  67. dailywheel.OnUserEnter(req.UserId)
  68. signin.OnUserEnter(req.UserId)
  69. return nil
  70. }
  71. func (h *activityservice) RemoveUser(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
  72. novicewelfare.OnUserExit(req.UserId)
  73. signin.OnUserExit(req.UserId)
  74. return nil
  75. }