user_redpoint.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. package redpoint
  2. import (
  3. "bet24.com/log"
  4. "bet24.com/servers/coreservice/friend"
  5. "bet24.com/servers/coreservice/monthlycard"
  6. "bet24.com/servers/coreservice/prizewheel"
  7. "bet24.com/servers/coreservice/purchase"
  8. _ "bet24.com/servers/coreservice/signin"
  9. "bet24.com/servers/coreservice/video"
  10. activityservice "bet24.com/servers/micros/activityservice/proto"
  11. notification "bet24.com/servers/micros/notification/proto"
  12. task "bet24.com/servers/micros/task/proto"
  13. userservice "bet24.com/servers/micros/userservices/proto"
  14. "encoding/json"
  15. "time"
  16. )
  17. type user_redPoint struct {
  18. userId int
  19. counter int //计数器
  20. isNotify bool // 是否发送通知
  21. endChan chan int
  22. redPoint //小红点提醒
  23. }
  24. func newUserRedpoint(userId int) *user_redPoint {
  25. if userservice.IsRobot(userId) {
  26. log.Release("newUserRedpoint %d is IsRobot", userId)
  27. return nil
  28. }
  29. ret := new(user_redPoint)
  30. ret.userId = userId
  31. ret.endChan = make(chan int)
  32. go func() {
  33. time.AfterFunc(time.Second*1, ret.doCheck)
  34. }()
  35. go func() {
  36. for {
  37. select {
  38. case <-ret.endChan:
  39. log.Debug("user_redPoint doCheck for stop userId=%d", ret.userId)
  40. return
  41. case <-time.After(time.Second * 5): //每5秒钟
  42. ret.doCheck()
  43. }
  44. }
  45. }()
  46. return ret
  47. }
  48. func (this *user_redPoint) check() *redPoint {
  49. info := load(this.userId)
  50. return &redPoint{
  51. pointInfo: *info,
  52. }
  53. }
  54. func (this *user_redPoint) doCheck() {
  55. this.checkTask() // 任务
  56. this.checkSign() // 签到
  57. this.checkVideoSign() // 视频广告
  58. this.checkPrizeWheel() // 彩票
  59. this.checkPurchase() // 100K购
  60. this.checkNoviceWelfare() // 新手福利
  61. this.checkLevelRewards() // 等级礼包
  62. this.checkDailyWheelFree() // 免费转盘
  63. // 频率较低的数据,计数器 24 * 5 = 120(1分钟)
  64. if this.counter%24 == 0 {
  65. // log.Debug("user_redPoint doCheckDB userId=%d counter=%d", this.userId, this.counter)
  66. this.checkMonth() // 月卡
  67. this.checkFriend() // 好友
  68. this.checkGameSettleVideo() // 游戏返还视频
  69. // 从数据库取数据
  70. info := load(this.userId)
  71. // 邮件(含附件)
  72. if this.MailTip != info.MailTip {
  73. this.MailTip = info.MailTip
  74. this.isNotify = this.isNotify || this.MailTip
  75. }
  76. // 重要邮件(含附件)
  77. if this.MailVipTip != info.MailVipTip {
  78. this.MailVipTip = info.MailVipTip
  79. this.isNotify = this.isNotify || this.MailVipTip
  80. }
  81. // 客服留言
  82. if this.MsgTip != info.MsgTip {
  83. this.MsgTip = info.MsgTip
  84. this.isNotify = this.isNotify || this.MsgTip
  85. }
  86. // 邀请(推广)
  87. if this.SpreadTip != info.SpreadTip {
  88. this.SpreadTip = info.SpreadTip
  89. this.isNotify = this.isNotify || this.SpreadTip
  90. }
  91. // 五星好评
  92. if this.ReviewTip != info.ReviewTip {
  93. this.ReviewTip = info.ReviewTip
  94. this.isNotify = this.isNotify || this.ReviewTip
  95. }
  96. // 代理升级提醒
  97. if this.AgentUpTip != info.AgentUpTip {
  98. this.AgentUpTip = info.AgentUpTip
  99. this.isNotify = this.isNotify || this.AgentUpTip
  100. }
  101. }
  102. // 计数器+1
  103. this.counter++
  104. // 发送通知
  105. this.notify()
  106. }
  107. // 游戏返还视频
  108. func (this *user_redPoint) checkGameSettleVideo() {
  109. gameVideoTip := video.CheckTip(this.userId)
  110. if this.GameVideoTip != gameVideoTip {
  111. this.GameVideoTip = gameVideoTip
  112. this.isNotify = this.isNotify || this.GameVideoTip
  113. }
  114. }
  115. // 彩票
  116. func (this *user_redPoint) checkPrizeWheel() {
  117. var prizeWheelTip bool // 彩票
  118. if times, maxTimes, _ := prizewheel.GetWheelTimes(this.userId); times < maxTimes {
  119. prizeWheelTip = true
  120. }
  121. if this.PrizeWheelTip != prizeWheelTip {
  122. this.PrizeWheelTip = prizeWheelTip
  123. this.isNotify = this.isNotify || this.PrizeWheelTip
  124. }
  125. }
  126. // 视频广告签到
  127. func (this *user_redPoint) checkVideoSign() {
  128. var videoSignTip bool //签到视频提示
  129. videoSignTip, _, _, _ = video.GetInfo(this.userId, video.Video_Sign)
  130. if this.VideoSignTip != videoSignTip {
  131. this.VideoSignTip = videoSignTip
  132. this.isNotify = this.isNotify || this.VideoSignTip
  133. }
  134. }
  135. // 任务
  136. func (this *user_redPoint) checkTask() {
  137. scenes := task.GetTaskTipScene(this.userId)
  138. taskTip := scenes > 0 && scenes != this.TaskScenes
  139. log.Debug("user_redpoint.checkTask userId=%d scenes=%d this.TaskScenes=%d taskTip=%v this.TaskTip=%v this.isNotify=%v",
  140. this.userId, scenes, this.TaskScenes, taskTip, this.TaskTip, this.isNotify)
  141. if this.TaskTip != taskTip {
  142. this.TaskTip = taskTip
  143. this.isNotify = this.isNotify || this.TaskTip
  144. }
  145. if scenes != this.TaskScenes {
  146. this.TaskScenes = scenes
  147. }
  148. }
  149. // 签到
  150. func (this *user_redPoint) checkSign() {
  151. signTip := activityservice.CheckUserSignTip(this.userId)
  152. if this.SignTip != signTip {
  153. this.SignTip = signTip
  154. this.isNotify = this.isNotify || this.SignTip
  155. }
  156. }
  157. // 月卡
  158. func (this *user_redPoint) checkMonth() {
  159. monthTip := monthlycard.CheckMonthTip(this.userId)
  160. if this.MonthTip != monthTip {
  161. this.MonthTip = monthTip
  162. this.isNotify = this.isNotify || this.MonthTip
  163. }
  164. }
  165. // 好友
  166. func (this *user_redPoint) checkFriend() {
  167. friendTip := false
  168. list := friend.FriendVerifyList(this.userId)
  169. if len(list) > 0 {
  170. friendTip = true
  171. }
  172. if !friendTip {
  173. fs := friend.GetFriendList(this.userId)
  174. for _, v := range fs {
  175. if v.IsGift == friend.GIFT_STATUS_HAVE {
  176. friendTip = true
  177. break
  178. }
  179. }
  180. }
  181. if this.FriendTip != friendTip {
  182. this.FriendTip = friendTip
  183. this.isNotify = this.isNotify || this.FriendTip
  184. }
  185. }
  186. // 100K购
  187. func (this *user_redPoint) checkPurchase() {
  188. purchaseTip := purchase.CheckTip()
  189. if this.PurchaseTip != purchaseTip {
  190. this.PurchaseTip = purchaseTip
  191. this.isNotify = this.isNotify || this.PurchaseTip
  192. }
  193. }
  194. // 新手福利
  195. func (this *user_redPoint) checkNoviceWelfare() {
  196. noviceWelfareTip := activityservice.IsNoviceWelfareTip(this.userId)
  197. if this.NoviceWelfareTip != noviceWelfareTip {
  198. this.NoviceWelfareTip = noviceWelfareTip
  199. this.isNotify = this.isNotify || this.NoviceWelfareTip
  200. }
  201. }
  202. // 等级礼包
  203. func (this *user_redPoint) checkLevelRewards() {
  204. levelRewardsTip := activityservice.IsLevelRewardsTip(this.userId)
  205. if this.LevelRewardsTip != levelRewardsTip {
  206. this.LevelRewardsTip = levelRewardsTip
  207. this.isNotify = this.isNotify || this.LevelRewardsTip
  208. }
  209. }
  210. // 等级礼包
  211. func (this *user_redPoint) checkDailyWheelFree() {
  212. tip := activityservice.IsDailyWheelFree(this.userId)
  213. if this.DailyWheelFreeTip != tip {
  214. this.DailyWheelFreeTip = tip
  215. this.isNotify = this.isNotify || this.DailyWheelFreeTip
  216. }
  217. }
  218. func (this *user_redPoint) notify() {
  219. if !this.isNotify {
  220. return
  221. }
  222. this.isNotify = false
  223. // 有通知需要发送
  224. d, _ := json.Marshal(this)
  225. //log.Debug("user_redpoint.notify userId=%d ==> %s", this.userId, string(d))
  226. go notification.AddNotification(this.userId, notification.Notification_Redpoint, string(d))
  227. }
  228. func (this *user_redPoint) destructor() {
  229. log.Debug("user_redPoint.destructor %d", this.userId)
  230. close(this.endChan)
  231. }