user_room_contribute.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package user
  2. import (
  3. "bet24.com/servers/common"
  4. "bet24.com/servers/micros/audioroom/handler/config"
  5. pb "bet24.com/servers/micros/audioroom/proto"
  6. "bet24.com/servers/micros/audioroom/transaction/database"
  7. )
  8. // 加载用户贡献
  9. func (this *UserRoom) loadContribute() {
  10. list := database.GetUserContribute(this.userId)
  11. for k, _ := range list {
  12. this.contributeList = append(this.contributeList, &list[k])
  13. }
  14. return
  15. }
  16. // 获取用户贡献余额
  17. func (this *UserRoom) GetContribute(roomId, action int) (bool, int) {
  18. dayLimit := 0
  19. // 获取日限额
  20. for _, d := range config.Mgr.GetRoomConfig().DayLimits {
  21. if d.Action != action {
  22. continue
  23. }
  24. dayLimit = d.Exps
  25. }
  26. // 没有配置即无限制
  27. if dayLimit == 0 {
  28. return true, dayLimit
  29. }
  30. for _, v := range this.contributeList {
  31. if v.RoomId != roomId {
  32. continue
  33. }
  34. if v.Action != action {
  35. continue
  36. }
  37. exps := v.Exps
  38. if !common.IsSameDay(v.Expire, common.GetTimeStamp()) {
  39. exps = 0
  40. }
  41. if exps >= dayLimit {
  42. return false, 0
  43. }
  44. return true, dayLimit - exps
  45. }
  46. return true, dayLimit
  47. }
  48. // 添加用户贡献
  49. func (this *UserRoom) AddContribute(roomId, action, exps int) {
  50. for _, v := range this.contributeList {
  51. if v.RoomId != roomId {
  52. continue
  53. }
  54. if v.Action != action {
  55. continue
  56. }
  57. if !common.IsSameDay(v.Exps, common.GetTimeStamp()) {
  58. v.Exps = 0
  59. }
  60. v.Exps += exps
  61. v.Expire = common.GetTimeStamp()
  62. // TODO:更新数据库
  63. database.UpdateUserContribute(this.userId, v)
  64. return
  65. }
  66. info := &pb.UserContribute{
  67. RoomId: roomId,
  68. Action: action,
  69. Exps: exps,
  70. Expire: common.GetTimeStamp(),
  71. }
  72. this.contributeList = append(this.contributeList, info)
  73. // TODO:更新数据库
  74. database.UpdateUserContribute(this.userId, info)
  75. return
  76. }
  77. // 删除贡献
  78. func (this *UserRoom) DelContribute(roomId int) {
  79. for i := 0; i < len(this.contributeList); i++ {
  80. if this.contributeList[i].RoomId != roomId {
  81. continue
  82. }
  83. this.contributeList = append(this.contributeList[:i], this.contributeList[i+1:]...)
  84. }
  85. }