server_coupontask.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package service
  2. import (
  3. "bet24.com/log"
  4. "bet24.com/servers/coreservice/client"
  5. "bet24.com/servers/coreservice/coupontask"
  6. "context"
  7. "encoding/json"
  8. "errors"
  9. )
  10. // 用户券任务
  11. func (s *Server) GetUserCouponTask(ctx context.Context, args *client.Request, reply *client.Reply) error {
  12. var req client.Request_base
  13. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  14. log.Debug("Server.GetUserCouponTask unmarshal fail %v", err)
  15. return errors.New("unmarshal error")
  16. }
  17. enabled, info, list := coupontask.GetUserTask(req.UserId)
  18. reply.Resp.RetCode = 1
  19. d, _ := json.Marshal(client.UserCouponTask_resp{
  20. Enabled: enabled,
  21. Info: info,
  22. List: list,
  23. })
  24. reply.Resp.Data = string(d)
  25. return nil
  26. }
  27. // 触发任务
  28. func (s *Server) TriggerCouponTask(ctx context.Context, args *client.Request, reply *client.Reply) error {
  29. var req client.TriggerCouponTask_req
  30. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  31. log.Debug("Server.TriggerCouponTask unmarshal fail %v", err)
  32. return errors.New("unmarshal error")
  33. }
  34. log.Debug("TriggerCouponTask userId=%d gameId=%d baseScore=%d isDouble=%d players=%d",
  35. req.UserId, req.GameId, req.BaseScore, req.IsDouble, req.Players)
  36. coupontask.Trigger(req.UserId, req.GameId, req.BaseScore, req.Players, req.IsDouble)
  37. reply.Resp.RetCode = 1
  38. reply.Resp.Data = ""
  39. return nil
  40. }
  41. // 领取奖励
  42. func (s *Server) AwardCouponTask(ctx context.Context, args *client.Request, reply *client.Reply) error {
  43. var req client.AwardCouponTask_req
  44. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  45. log.Debug("Server.AwardCouponTask unmarshal fail %v", err)
  46. return errors.New("unmarshal error")
  47. }
  48. ret := coupontask.Award(req.UserId, req.UserTaskId)
  49. reply.Resp.RetCode = 1
  50. d, _ := json.Marshal(ret)
  51. reply.Resp.Data = string(d)
  52. return nil
  53. }
  54. // 修改临时上限
  55. func (s *Server) UpdateCouponTaskTmpLimit(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.UpdateCouponTaskTmpLimit unmarshal fail %v", err)
  59. return errors.New("unmarshal error")
  60. }
  61. ret := coupontask.UpdateTmpLimit(req.UserId)
  62. reply.Resp.RetCode = 1
  63. d, _ := json.Marshal(ret)
  64. reply.Resp.Data = string(d)
  65. return nil
  66. }