main.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. package savingpot
  2. import (
  3. "encoding/json"
  4. "bet24.com/log"
  5. "bet24.com/servers/common"
  6. )
  7. func Run() {
  8. getManager()
  9. }
  10. func Dump(cmd, param1 string) {
  11. switch cmd {
  12. case "sys":
  13. getManager().dumpSys()
  14. case "user":
  15. getManager().dumpUser(param1)
  16. default:
  17. log.Debug("savingPot.Dump unhandled cmd %s", cmd)
  18. }
  19. }
  20. // 获取存钱罐
  21. func GetBuyAmount(userId int, isOld bool) int {
  22. // 存钱罐信息
  23. return getManager().getBuyAmount(userId, isOld)
  24. }
  25. // 获取存钱罐
  26. func GetUserSavingPot(userId int) string {
  27. var ret struct {
  28. BuyAmount int // 存钱罐额度
  29. Level int // 当前等级
  30. IsMultiplyStatus int // 是否购买翻三倍
  31. LeftTimeSec int // 限时购买剩余时间(S)
  32. AccumulateLimit int // 满额限制
  33. BuyLimit int // 每天购买上限
  34. BuyCount int // 已购买次数
  35. }
  36. var retOld struct {
  37. BuyTimesLimit int // 购买次数上限
  38. BuyTimes int // 已购买次数
  39. AccumulateLimit int // 累计上限
  40. }
  41. u := getManager().getUser(userId)
  42. if u.isOld {
  43. retOld.BuyTimesLimit = getManager().MaxCount
  44. retOld.BuyTimes = getManager().getUserBuyCount(userId)
  45. retOld.AccumulateLimit = 150000
  46. buf, _ := json.Marshal(retOld)
  47. return string(buf)
  48. }
  49. // 获取用户存钱罐信息
  50. info := getManager().getUserSavingPot(userId)
  51. ret.BuyAmount = info.BuyAmount
  52. ret.Level = info.CurrentLevel
  53. ret.IsMultiplyStatus = info.IsMultiplyStatus
  54. ret.LeftTimeSec = 0
  55. if info.IsMultiplyStatus != 0 {
  56. sec := info.DuringTimeSec - common.GetDifferSec(info.UpdateTime)
  57. if sec < 0 {
  58. sec = 0
  59. }
  60. ret.LeftTimeSec = sec
  61. }
  62. ret.AccumulateLimit = getManager().getConfigInfo(info.CurrentLevel).AccumulateLimit
  63. ret.BuyLimit = getManager().MaxCount
  64. ret.BuyCount = getManager().getUserBuyCount(userId)
  65. buf, _ := json.Marshal(ret)
  66. return string(buf)
  67. }
  68. func GetUserNewSavingPot(userId int) string {
  69. var ret struct {
  70. BuyAmount int // 存钱罐额度
  71. Level int // 当前等级
  72. IsMultiplyStatus int // 是否购买翻三倍
  73. LeftTimeSec int // 限时购买剩余时间(S)
  74. AccumulateLimit int // 满额限制
  75. BuyLimit int // 每天购买上限
  76. BuyCount int // 已购买次数
  77. }
  78. // 获取用户存钱罐信息
  79. info := getManager().getUserSavingPot(userId)
  80. ret.BuyAmount = info.BuyAmount
  81. ret.Level = info.CurrentLevel
  82. ret.IsMultiplyStatus = info.IsMultiplyStatus
  83. ret.LeftTimeSec = 0
  84. if info.IsMultiplyStatus != 0 {
  85. sec := info.DuringTimeSec - common.GetDifferSec(info.UpdateTime)
  86. if sec < 0 {
  87. sec = 0
  88. }
  89. ret.LeftTimeSec = sec
  90. }
  91. ret.AccumulateLimit = getManager().getConfigInfo(info.CurrentLevel).AccumulateLimit
  92. ret.BuyLimit = getManager().MaxCount
  93. ret.BuyCount = getManager().getUserBuyCount(userId)
  94. buf, _ := json.Marshal(ret)
  95. return string(buf)
  96. }
  97. // 触发存钱罐
  98. func TriggerSavingPot(userId, gameId, winAmount int) {
  99. getManager().addAccumulateAmount(userId, gameId, winAmount)
  100. return
  101. }
  102. // 存钱罐购买
  103. func SavingPotBuy(userId int, isOld bool) bool {
  104. return getManager().buy(userId, isOld)
  105. }
  106. // 检查触发多倍领取
  107. func CheckMultiplyReceive(userId int) {
  108. getManager().checkUserMultiplyReceive(userId)
  109. }
  110. func SetIsOldSavingPot(userId int) {
  111. getManager().setIsOldSavingPot(userId)
  112. }