usermonthlycard.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package monthlycard
  2. import (
  3. "bet24.com/servers/common"
  4. )
  5. const (
  6. Valid_Days = 29 * 86400 //30天减去当天领取的
  7. Week_DAYS = 6 * 86400 //7天减去当天领取的
  8. )
  9. type usermonthlycard struct {
  10. UserID int //用户id
  11. MonthlyCardInfo
  12. }
  13. func newUserMonthlyCard(userId int) *usermonthlycard {
  14. u := new(usermonthlycard)
  15. u.UserID = userId
  16. u.loadUserMonthlyCard()
  17. // log.Debug("newUserMonthlyCard userId=%d %+v", userId, u)
  18. return u
  19. }
  20. func (this *usermonthlycard) loadUserMonthlyCard() {
  21. this.MonthlyCardInfo = getInfo(this.UserID)
  22. }
  23. func (this *usermonthlycard) buyMonth() int {
  24. now := common.GetTimeStamp()
  25. day := common.GetDayIndex(now)
  26. if common.GetDayIndex(this.MonthExpire) < day {
  27. this.MonthExpire = now
  28. }
  29. this.MonthExpire = this.MonthExpire + Valid_Days
  30. return buy(this.UserID, this.MonthExpire, 0)
  31. }
  32. func (this *usermonthlycard) giftMonth() int {
  33. this.checkMonthlyStatus()
  34. if this.MonthGiftStatus != Month_GIFT_STATUS_HAVE {
  35. return this.MonthGiftStatus
  36. }
  37. this.MonthGift = common.GetTimeStamp()
  38. return gift(this.UserID, this.MonthGift, 0)
  39. }
  40. func (this *usermonthlycard) checkMonthTip() bool {
  41. this.checkMonthlyStatus()
  42. return this.MonthGiftStatus == Month_GIFT_STATUS_HAVE
  43. }
  44. func (this *usermonthlycard) checkMonthlyStatus() {
  45. //还没有月卡
  46. if this.MonthExpire <= 0 {
  47. this.MonthGiftStatus = Month_GIFT_STATUS_NOT
  48. return
  49. }
  50. now := common.GetTimeStamp()
  51. day := common.GetDayIndex(now)
  52. expireDay := common.GetDayIndex(this.MonthExpire)
  53. //判断是否有月卡
  54. if expireDay < day {
  55. this.MonthGiftStatus = Month_GIFT_STATUS_NOT
  56. return
  57. }
  58. //剩余天数
  59. this.MonthDays = expireDay - day
  60. //判断是否领取过
  61. if common.GetDayIndex(this.MonthGift) >= day {
  62. this.MonthGiftStatus = Month_GIFT_STATUS_RECEIVED
  63. return
  64. }
  65. this.MonthGiftStatus = Month_GIFT_STATUS_HAVE
  66. return
  67. }
  68. func (this *usermonthlycard) buyWeek() int {
  69. now := common.GetTimeStamp()
  70. day := common.GetDayIndex(now)
  71. if common.GetDayIndex(this.WeekExpire) < day {
  72. this.WeekExpire = now
  73. }
  74. this.WeekExpire = this.WeekExpire + Week_DAYS
  75. return buy(this.UserID, 0, this.WeekExpire)
  76. }
  77. func (this *usermonthlycard) giftWeek() int {
  78. //还没有周卡
  79. if this.WeekExpire <= 0 {
  80. return 0
  81. }
  82. now := common.GetTimeStamp()
  83. day := common.GetDayIndex(now)
  84. //判断是否有周卡
  85. if common.GetDayIndex(this.WeekExpire) < day {
  86. return 0
  87. }
  88. //判断是否领取过
  89. if common.GetDayIndex(this.WeekGift) >= day {
  90. return 0
  91. }
  92. this.WeekGift = now
  93. return gift(this.UserID, 0, this.WeekGift)
  94. }