giftpack.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package giftpack
  2. import (
  3. "bet24.com/log"
  4. item "bet24.com/servers/micros/item_inventory/proto"
  5. )
  6. const (
  7. GiftPackLimit_None = iota // 无限制
  8. GiftPackLimit_Once // 只能购买一次
  9. GiftPackLimit_EveryDay // 每天购买一次
  10. )
  11. const (
  12. GiftPackType_First = iota // 首充礼包
  13. GiftPackType_TimeLimited // 限时礼包
  14. GiftPackType_EveryDay // 每日特惠
  15. )
  16. type GiftPack struct {
  17. Id int //礼包ID
  18. Name string //礼包名称
  19. ProductId string // 商城产品ID
  20. Price int
  21. Limit int
  22. Items []item.ItemPack
  23. //PreGiftPack int `json:",omitempty"` // 前置礼包,必须购买前置礼包才能购买本礼包,这里默认要求连续购买
  24. Type int // 礼包类型
  25. Duration int `json:",omitempty"`
  26. Group int `json:",omitempty"` // 每日特惠中,不同价格用不同Group区分
  27. GroupIndex int `json:",omitempty"` // 同组顺序
  28. }
  29. type UserGiftPackHistory struct {
  30. GiftPackId int
  31. LastPhaseTime int
  32. group int
  33. groupIndex int
  34. }
  35. type UserBuyable struct {
  36. GiftPackId int // 礼包ID
  37. Buyable bool // 是否可购买
  38. TimeLeft int // 剩余时间
  39. }
  40. var mgr *giftpackmgr
  41. func Run() {
  42. mgr = newGiftPackManager()
  43. gmgr = newGrowthPackManager()
  44. }
  45. func GetGiftPacks() map[int]*GiftPack {
  46. return mgr.getGiftPackList()
  47. }
  48. func GetBuyable(userId int) []UserBuyable {
  49. return mgr.getUserGiftPack(userId)
  50. }
  51. func BuyGiftPack(userId int, productId string) []item.ItemPack {
  52. return mgr.buyGiftPack(userId, productId)
  53. }
  54. func Dump(param1, param2 string) {
  55. switch param1 {
  56. case "sys":
  57. mgr.dumpSys(param2)
  58. case "user":
  59. mgr.dumpUser(param2)
  60. case "gsys":
  61. gmgr.dumpSys(param2)
  62. case "guser":
  63. gmgr.dumpUser(param2)
  64. default:
  65. log.Debug("giftpack.Dump unhandled %s:%s", param1, param2)
  66. }
  67. }