individualuserwaterpool.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package individualwaterpool
  2. import (
  3. pb "bet24.com/servers/micros/waterpool/proto"
  4. )
  5. const (
  6. PoolControl_NormalValue = 0
  7. )
  8. type userWaterPool struct {
  9. userId int // 用户ID
  10. poolType int // 调控模式
  11. poolValue int // 奖池数据
  12. }
  13. func newUserWaterPool(userId int) *userWaterPool {
  14. user := new(userWaterPool)
  15. user.userId = userId
  16. user.loadDataFromDB()
  17. return user
  18. }
  19. func (u *userWaterPool) loadDataFromDB() {
  20. usr := trans_getUserWaterPoolInfo(u.userId)
  21. u.poolType = usr.PoolType
  22. u.poolValue = usr.PoolValue
  23. }
  24. func (u *userWaterPool) grantNewWaterPool(value int, genType string) {
  25. u.poolValue += value
  26. if u.poolValue == PoolControl_NormalValue {
  27. u.poolType = pb.PoolControl_Normal
  28. } else if u.poolValue < PoolControl_NormalValue {
  29. u.poolType = pb.PoolControl_Lose
  30. } else {
  31. u.poolType = pb.PoolControl_Win
  32. }
  33. go trans_grantIndividualWaterPoolRecord(u.userId, u.poolValue, value, genType, 0, 0)
  34. go trans_updataUserWaterPoolInfo(u.userId, u.poolType, u.poolValue)
  35. }
  36. func (u *userWaterPool) updataWaterPool(amount int, genType string, roomType, roomID int) {
  37. execAmount := amount
  38. if u.poolType == pb.PoolControl_Win {
  39. if execAmount < 0 {
  40. execAmount = 0
  41. }
  42. u.poolValue -= amount
  43. go trans_updataTotalWaterPoolInfo(0, execAmount, 0, 0, 0)
  44. } else {
  45. if execAmount > 0 {
  46. execAmount = 0
  47. } else {
  48. execAmount = -execAmount
  49. }
  50. u.poolValue -= amount
  51. go trans_updataTotalWaterPoolInfo(0, 0, 0, execAmount, 0)
  52. }
  53. if u.poolType == pb.PoolControl_Lose && u.poolValue >= PoolControl_NormalValue {
  54. u.poolType = pb.PoolControl_Normal
  55. if u.poolValue > PoolControl_NormalValue {
  56. u.poolType = pb.PoolControl_Win
  57. }
  58. }
  59. if u.poolType == pb.PoolControl_Win && u.poolValue <= PoolControl_NormalValue {
  60. u.poolType = pb.PoolControl_Normal
  61. if u.poolValue < PoolControl_NormalValue {
  62. u.poolType = pb.PoolControl_Lose
  63. }
  64. }
  65. go trans_updataUserWaterPoolInfo(u.userId, u.poolType, u.poolValue)
  66. go trans_grantIndividualWaterPoolRecord(u.userId, u.poolValue, -amount, genType, roomType, roomID)
  67. }
  68. func (u *userWaterPool) getPoolTypeDesc() string {
  69. switch u.poolType {
  70. case pb.PoolControl_Lose:
  71. return "Lose"
  72. case pb.PoolControl_Win:
  73. return "Win"
  74. case pb.PoolControl_Normal:
  75. return "Normal"
  76. }
  77. return "Invild"
  78. }