vipdefs.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. package proto
  2. import (
  3. "bet24.com/servers/common"
  4. _ "bet24.com/servers/common"
  5. item "bet24.com/servers/micros/item_inventory/proto"
  6. )
  7. // 获取日期或者星期Index,用于每日礼包领取,或者其他礼包购买限制
  8. // common.GetDayIndex()
  9. // common.GetWeekIndex()
  10. // 用户vip信息,信息存入数据库
  11. type UserVip struct {
  12. Level int // 等级
  13. Point int // 当前累积点数
  14. Expire int // 结束时间Time.Unix() 0表示不生效
  15. DailyPackageClaimDay int // 上一次领取每日礼包的日期Index
  16. }
  17. func (uv *UserVip) IsVip() bool {
  18. return uv.Expire > common.GetTimeStamp()
  19. }
  20. // 系统vip配置,由json配置提供,进入platformconfig
  21. type VipInfo struct {
  22. Level int // 等级
  23. Point int // 所需点数
  24. Privileges []VipPrivilege // 特权配置,可多项
  25. DailyPackage []item.ItemPack // 每日礼包
  26. UpgragePackage []item.ItemPack // 升级礼包,礼包内容为时效道具,需要遍历所有低等级赠送一次
  27. }
  28. // VIP特权列表
  29. const (
  30. VipPrivilege_Invalid = iota // 0 无效值
  31. VipPrivilege_ExtraBankruptcy // 1 额外破产补助(百分比)
  32. VipPrivilege_ExtraExperience // 2 额外经验获取(百分比)
  33. VipPrivilege_ExtraFriend // 3 额外好友上限
  34. VipPrivilege_EntranceRemind // 4 入场提醒
  35. VipPrivilege_PrivateRoomKick // 5 私人场踢人权限
  36. VipPrivilege_ExtraGoldTransferCount // 6 额外金币转账次数
  37. VipPrivilege_ExtraDiamondTransferCount // 7 额外钻石转账次数
  38. )
  39. const (
  40. VipAward_Success = iota // 0 可以领取
  41. VipAward_Nonmember // 1 您不是vip
  42. VipAward_ReceivedAward // 2 今日已领取奖励
  43. VipAward_ConfigNotExist // 3 当前级别配置不存在
  44. VipAward_NoReward // 4 当前配置没有奖励
  45. )
  46. // 获取特权的参数
  47. func (vi *VipInfo) GetPrivilegeParam(privilegeType int) int {
  48. for k, v := range vi.Privileges {
  49. if v.Privilege == privilegeType {
  50. return vi.Privileges[k].Param
  51. }
  52. }
  53. return VipPrivilege_Invalid
  54. }
  55. type VipPrivilege struct {
  56. Privilege int `json:"pid"`
  57. Param int `json:"p"`
  58. }
  59. // 可购买礼包
  60. // 礼包购买历史
  61. type PurchaseHistory struct {
  62. ProductId string // 产品id
  63. PurchaseTime int64 // 时间戳
  64. }
  65. const (
  66. PurchaseLimit_none = iota // 0不限购
  67. PurchaseLimit_daily // 1每日限购
  68. PurchaseLimit_weekly // 2每周限购
  69. PurchaseLimit_monthly // 3每月限购
  70. )
  71. type PurchaseLimit struct {
  72. PurchaseLimitType int `json:",omitempty"` // 限购类型
  73. PurchaseLimitCount int `json:",omitempty"` // 限购数量
  74. }
  75. type PurchasePackage struct {
  76. PackageId int // 礼包ID
  77. Name string // 礼包名称
  78. Desc string // 描述
  79. ProductId string // 商品ID,需要同步商城配置
  80. Price float64 // 价格
  81. Items []item.ItemPack // 礼包内容
  82. PurchaseLimit
  83. BuyAble bool // 是否可购买,发给前端用
  84. }
  85. type VipInterface interface {
  86. Run() // 创建对象,加载vip配置信息,开启定时器刷新配置
  87. Dump(cmd, param string) // dump系统信息,用户信息
  88. OnUserEnter(userId int) // 用户进入,创建用户信息,读取用户礼包购买历史,如果是vip,判断是否领取VIP奖励
  89. OnUserExit(userId int) // 将用户标记为离线,等待10分钟后删除数据
  90. AddVipPoint(userId int, point int) // 添加vip点数,可能触发升级,升级如果当前是vip,则需要发放登录道具和升级道具
  91. /*
  92. 添加vip时长(已完成支付),如果当前Expire==0,则expire=time.Now().Unix()+purchaseSeconds
  93. 否则Expire+=purchaseSeconds
  94. 需要处理:判断并领取每日礼包,发放道具,如果为时效道具则设置道具时效(交由item_inventory模块处理)
  95. */
  96. AddVipSeconds(userId int, purchaseSeconds int64)
  97. GetExtraSubsidy(userId int) int // 获取额外每日补助百分比
  98. GetExtraExperience(userId int) int // 获取额外经验百分比
  99. GetExtraFriendCount(userId int) int // 获取额外好友上限数量
  100. CanBuyPackage(userId int, packageId int) bool // 判断是否能购买礼包
  101. // 实际购买礼包(已完成支付),发放道具,添加购买历史记录
  102. BuyPackage(userId int, packageId int)
  103. GetVipList() []VipInfo // 获取vip列表,前端展现用
  104. GetVipByLevel(level int) *VipInfo // 根据等级获取vip配置信息
  105. GetUserVip(userId int) UserVip // 根据用户ID查询用户vip状态
  106. }
  107. /*
  108. VIP失效检查
  109. 1、登录时,判断time.Now.Unix() > Expire ,触发OnVipExpired
  110. 2、登录后,如果vip时效还在,启动定时器,time.AfterFunc((Expire-time.Now.Unix()) * time.Second,OnVipExpired)
  111. 失效后,updateUserVip设置Expire为0,发通知(notification)
  112. */
  113. /*
  114. 数据库表:
  115. UserVip表: UserId,Level,Point,Expire,DailyPackageClaimDay
  116. VipPackagePurchaseHistory表: UserId,PackageId,PurchaseTime
  117. 提供操作:
  118. getUserVip(userId int) UserVip
  119. updateUserVip(userId int,vipInfo UserVip)
  120. getPackagePurchaseHistory(userId int) []PurchaseHistory
  121. addPackagePurchaseHistory(userId int,packageId int,time.Now().Unix())
  122. */
  123. /*
  124. vip配置
  125. {
  126. "VipList":[
  127. {
  128. "Level":1,
  129. "Point":10,
  130. "Privileges":[{"pid":1,"p":10},{"pid":2,"p":5}],
  131. "DailyPackage":[
  132. {
  133. "ItemId":1,
  134. "Count":20000
  135. },
  136. {
  137. "ItemId":2,
  138. "Count":30
  139. }
  140. ],
  141. "UpgragePackage":[
  142. {
  143. "ItemId":40003,
  144. "Count":1
  145. },
  146. {
  147. "ItemId":40013,
  148. "Count":1
  149. }
  150. ]
  151. }
  152. ],
  153. "PurchasePackages":[
  154. {
  155. "PackageId":1,
  156. "Name":"vip礼包1",
  157. "Desc":"vip礼包1",
  158. "ProductId":70001,
  159. "Price":29.99,
  160. "Items":[
  161. {
  162. "ItemId":1,
  163. "Count":20000
  164. },
  165. {
  166. "ItemId":2,
  167. "Count":30
  168. }
  169. ]
  170. }
  171. ]
  172. }
  173. */