exp.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package http
  2. import (
  3. "go-common/app/service/live/userexp/conf"
  4. "go-common/app/service/live/userexp/model"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/xstr"
  9. "strconv"
  10. )
  11. func level(c *bm.Context) {
  12. uidStr := c.Request.Form.Get("uid")
  13. // check params
  14. uid, err := strconv.ParseInt(uidStr, 10, 64)
  15. if err != nil || uid <= 0 {
  16. c.JSON(nil, ecode.RequestErr)
  17. return
  18. }
  19. c.JSON(expSvr.Level(c, uid))
  20. }
  21. func multiGetLevel(c *bm.Context) {
  22. uidsStr := c.Request.Form.Get("uids")
  23. // check params
  24. uids, err := xstr.SplitInts(uidsStr)
  25. if err != nil {
  26. c.JSON(nil, ecode.RequestErr)
  27. return
  28. }
  29. levels, err := expSvr.MultiGetLevel(c, uids)
  30. if err != nil {
  31. log.Error("[http.exp|multiGetLevel] expSvr.MultiGetLevel(%v) error(%v)", uids, err)
  32. c.JSON(nil, err)
  33. return
  34. }
  35. levelInfo := make(map[string]*model.Level, len(levels))
  36. for _, v := range levels {
  37. levelInfo[strconv.FormatInt(v.Uid, 10)] = v
  38. }
  39. c.JSON(levelInfo, nil)
  40. }
  41. func addUexp(c *bm.Context) {
  42. uidStr := c.Request.Form.Get("uid")
  43. uexpStr := c.Request.Form.Get("uexp")
  44. var exp *model.Exp
  45. // check params
  46. uid, err := strconv.ParseInt(uidStr, 10, 64)
  47. if err != nil || uid <= 0 {
  48. c.JSON(nil, ecode.RequestErr)
  49. return
  50. }
  51. uexp, err := strconv.ParseInt(uexpStr, 10, 64)
  52. if err != nil || uexp <= 0 {
  53. c.JSON(nil, ecode.RequestErr)
  54. return
  55. }
  56. ric := infocArg(c)
  57. err = expSvr.AddUexp(c, uid, uexp, ric)
  58. if err != nil {
  59. log.Error("[http.exp|addUexp] expSvr.AddUexp1(%u) error(%v)", uid, err)
  60. }
  61. LogSwitch := conf.Conf.Switch
  62. if LogSwitch != nil {
  63. var QueryConfig = conf.Conf.Switch.QueryExp
  64. if QueryConfig == 1 {
  65. exp, err = expSvr.Exp(c, uid)
  66. log.Info("addUexpUpdate uid:%d,Uexp:%d,Uexp:%d,delta:%d", exp.Uid, exp.Uexp, exp.Rexp, uexp)
  67. }
  68. }
  69. err = expSvr.AddUExpLog(c, uid, uexp, exp.Uexp, exp.Rexp, ric)
  70. c.JSON(nil, err)
  71. }
  72. func addRexp(c *bm.Context) {
  73. uidStr := c.Request.Form.Get("uid")
  74. rexpStr := c.Request.Form.Get("rexp")
  75. var exp *model.Exp
  76. // check params
  77. uid, err := strconv.ParseInt(uidStr, 10, 64)
  78. if err != nil || uid <= 0 {
  79. c.JSON(nil, ecode.RequestErr)
  80. return
  81. }
  82. rexp, err := strconv.ParseInt(rexpStr, 10, 64)
  83. if err != nil || rexp <= 0 {
  84. c.JSON(nil, ecode.RequestErr)
  85. return
  86. }
  87. ric := infocArg(c)
  88. err = expSvr.AddRexp(c, uid, rexp, ric)
  89. if err != nil {
  90. log.Error("[http.exp|addRexp] expSvr.AddRexp(%u) error(%v)", uid, err)
  91. }
  92. LogSwitch := conf.Conf.Switch
  93. if LogSwitch != nil {
  94. var QueryConfig = conf.Conf.Switch.QueryExp
  95. if QueryConfig == 1 {
  96. exp, err = expSvr.Exp(c, uid)
  97. log.Info("addRexpUpdate uid:%d,Uexp:%d,Rexp:%d,delta:%d", exp.Uid, exp.Uexp, exp.Rexp, rexp)
  98. }
  99. }
  100. err = expSvr.AddRExpLog(c, uid, rexp, exp.Uexp, exp.Rexp, ric)
  101. c.JSON(nil, err)
  102. }