jackpotmgr.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. package jackpot
  2. import (
  3. "bet24.com/log"
  4. "bet24.com/servers/coreservice/serviceconfig"
  5. "strconv"
  6. "sync"
  7. )
  8. const (
  9. gold_min_default = 1000000000
  10. gold_max_default = 6000000000
  11. chip_min_default = 1000000000
  12. chip_max_default = 6000000000
  13. )
  14. type jackpot struct {
  15. lock *sync.RWMutex
  16. amountsGold map[int]int
  17. amountsChip map[int]int
  18. minGold int
  19. maxGold int
  20. minChip int
  21. maxChip int
  22. }
  23. func (j *jackpot) loadData() {
  24. j.amountsGold = make(map[int]int)
  25. j.amountsChip = make(map[int]int)
  26. j.minGold, j.maxGold = serviceconfig.SpecialCfg.MinGoldPool, serviceconfig.SpecialCfg.MaxGoldPool
  27. j.minChip, j.maxChip = serviceconfig.SpecialCfg.MinChipPool, serviceconfig.SpecialCfg.MaxChipPool
  28. if j.minChip == 0 {
  29. j.minChip = chip_min_default
  30. }
  31. if j.maxChip == 0 {
  32. j.maxChip = chip_max_default
  33. }
  34. if j.minGold == 0 {
  35. j.minGold = gold_min_default
  36. }
  37. if j.maxGold == 0 {
  38. j.maxGold = gold_max_default
  39. }
  40. }
  41. func (j *jackpot) getAmount(gameId int, isChipRoom bool) int {
  42. j.lock.Lock()
  43. defer j.lock.Unlock()
  44. var amount int
  45. if isChipRoom {
  46. ret, ok := j.amountsChip[gameId]
  47. if !ok {
  48. ret = getJackpotAmount(gameId, isChipRoom)
  49. j.amountsChip[gameId] = ret
  50. }
  51. amount = ret
  52. } else {
  53. ret, ok := j.amountsGold[gameId]
  54. if !ok {
  55. ret = getJackpotAmount(gameId, isChipRoom)
  56. j.amountsGold[gameId] = ret
  57. }
  58. amount = ret
  59. }
  60. modify := 0
  61. amount, modify = j.adjustAmount(amount, isChipRoom)
  62. if modify != 0 {
  63. go modifyAction(0, gameId, modify, isChipRoom)
  64. if isChipRoom {
  65. j.amountsChip[gameId] = amount
  66. } else {
  67. j.amountsGold[gameId] = amount
  68. }
  69. }
  70. return amount
  71. }
  72. // 用户从奖池中获取到的金币什么时候加?
  73. func (j *jackpot) modifyAmount(gameId int, amount int, userId int, desc string, isChipRoom bool) int {
  74. preAmount := j.getAmount(gameId, isChipRoom)
  75. preAmount += amount
  76. go modifyAction(userId, gameId, amount, isChipRoom)
  77. modify := 0
  78. preAmount, modify = j.adjustAmount(preAmount, isChipRoom)
  79. if modify != 0 {
  80. go modifyAction(0, gameId, modify, isChipRoom)
  81. }
  82. j.lock.Lock()
  83. if isChipRoom {
  84. j.amountsChip[gameId] = preAmount
  85. } else {
  86. j.amountsGold[gameId] = preAmount
  87. }
  88. j.lock.Unlock()
  89. return preAmount
  90. }
  91. func (j *jackpot) adjustAmount(amount int, isChipRoom bool) (int, int) {
  92. min, max := j.getMinMax(isChipRoom)
  93. if amount < min {
  94. return min, min - amount
  95. }
  96. if max > 0 && amount > max {
  97. return max, max - amount
  98. }
  99. return amount, 0
  100. }
  101. func (j *jackpot) getMinMax(isChipRoom bool) (int, int) {
  102. if isChipRoom {
  103. return j.minChip, j.maxChip
  104. } else {
  105. return j.minGold, j.maxGold
  106. }
  107. }
  108. func (j *jackpot) dumpSys() {
  109. log.Release("-------------------------------")
  110. log.Release("jackpot.dumpSys")
  111. defer func() {
  112. log.Release("+++++++++++++++++++++++++++++++")
  113. log.Release("")
  114. }()
  115. log.Release(" gold[%d,%d],chip[%d,%d]", j.minGold, j.maxGold, j.minChip, j.maxChip)
  116. }
  117. func (j *jackpot) dumpGame(param1 string) {
  118. log.Release("-------------------------------")
  119. log.Release("jackpot.dumpGame %s", param1)
  120. defer func() {
  121. log.Release("+++++++++++++++++++++++++++++++")
  122. log.Release("")
  123. }()
  124. var gameId int
  125. var err error
  126. if gameId, err = strconv.Atoi(param1); err != nil {
  127. log.Release(" atoi error %v", err)
  128. return
  129. }
  130. log.Release(" gold[%d],chip[%d]", j.getAmount(gameId, false), j.getAmount(gameId, true))
  131. }