user.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. package handler
  2. import (
  3. "math"
  4. "strconv"
  5. "strings"
  6. "time"
  7. waterpool "bet24.com/servers/micros/waterpool/proto"
  8. "bet24.com/log"
  9. "bet24.com/servers/common"
  10. pb "bet24.com/servers/micros/userlabel/proto"
  11. )
  12. const (
  13. seconds = 600 // 过期时长(秒)
  14. max_days = 30 // 保留X天数据
  15. )
  16. const (
  17. _ = iota // 0=无效
  18. tag_login_activeTime // 1=活跃时长(大厅模块)
  19. tag_charge_Amount // 2=付费金额(充值模块)
  20. tag_game_love_online // 3=游戏喜好时长(游戏模块:1=游戏时长、2=游戏流水、3=报名次数)
  21. tag_game_friendRoom // 4=好友房(游戏模块)
  22. tag_audioRoom_interactive // 5=互动类(语聊房模块)
  23. tag_task_award // 6=任务类(任务模块)
  24. tag_chat // 7=聊天类(聊天模块)
  25. tag_friend // 8=交际类(好友模块)
  26. tag_register_ipDanger // 9=IP危险(注册模块)
  27. tag_register_iMeiDanger // 10=IMei危险(注册模块)
  28. tag_charge_game_loseDanger // 11=输金危险(游戏模块)
  29. tag_game_cheatingDanger // 12=作弊危险(游戏模块)
  30. tag_charge_potentialCharge // 13=潜在付费(充值模块)
  31. tag_charge_passiveCharge // 14=被动付费(充值模块)
  32. tag_charge_savingsCharge // 15=储蓄付费(充值模块)
  33. tag_charge_discountCharge // 16=折扣付费(充值模块,主要用于礼包购买)
  34. tag_login_newbieBehavior // 17=新手行为(大厅模块)
  35. tag_charge_game_winDanger // 18=赚金危险(游戏模块)
  36. tag_register_utmsource // 19=注册来源渠道
  37. tag_login_return // 20=登录回归
  38. tag_bankruptcy // 21=破产
  39. tag_game_love_bet // 22=游戏喜好投注
  40. tag_game_love_match // 23=游戏喜好比赛报名
  41. tag_charge_frequency // 24=付费频率
  42. tag_time_love // 25=时间偏好
  43. )
  44. // 用户信息
  45. type userInfo struct {
  46. userId int // 用户id
  47. label_list []*pb.LabelInfo // 标签列表
  48. timeStamp int // 时间戳
  49. }
  50. func newUserInfo(userId int) *userInfo {
  51. ret := new(userInfo)
  52. ret.userId = userId
  53. ret.updateTimeStamp()
  54. ret.loadData()
  55. return ret
  56. }
  57. // 加载数据
  58. func (this *userInfo) loadData() {
  59. // TODO:数据库获取
  60. list := trans_GetInfo(this.userId)
  61. for i := 0; i < len(list); i++ {
  62. this.label_list = append(this.label_list, &list[i])
  63. }
  64. return
  65. }
  66. // 更新时间戳
  67. func (this *userInfo) updateTimeStamp() {
  68. this.timeStamp = common.GetTimeStamp() + seconds
  69. return
  70. }
  71. // 是否过期
  72. func (this *userInfo) isExpire() bool {
  73. if this.timeStamp < common.GetTimeStamp() {
  74. return true
  75. }
  76. return false
  77. }
  78. // 获取标签列表
  79. func (this *userInfo) getLabelList() []*pb.LabelInfo {
  80. var ret []*pb.LabelInfo
  81. for _, v := range this.label_list {
  82. if v.LabelId == "" {
  83. continue
  84. }
  85. ret = append(ret, v)
  86. }
  87. return ret
  88. }
  89. // 根据类型获取标签信息
  90. func (this *userInfo) getLabelInfo(typeId int) *pb.LabelInfo {
  91. for _, v := range this.label_list {
  92. if v.TypeId == typeId {
  93. return v
  94. }
  95. }
  96. return nil
  97. }
  98. // 设置标签
  99. func (this *userInfo) setLabel(typeId, days int, labelId string) {
  100. // 获取标签信息
  101. labelInfo := this.getLabelInfo(typeId)
  102. // 标签不存在
  103. if labelInfo == nil {
  104. labelInfo = &pb.LabelInfo{
  105. TypeId: typeId,
  106. }
  107. this.label_list = append(this.label_list, labelInfo)
  108. }
  109. // 更新标签
  110. labelInfo.LabelId = labelId
  111. // TODO:写入数据库
  112. go trans_Save(this.userId, days, labelInfo)
  113. }
  114. // 分配事件
  115. func (this *userInfo) dispatch(typeId int, scope pb.Scope) {
  116. switch typeId {
  117. case pb.Type_Login: // 登录
  118. dayIndex := common.GetDayIndex(common.GetTimeStamp())
  119. // 注册登录
  120. if scope.IsRegister {
  121. // 17=新手行为(大厅模块)
  122. this.handleEvent(tag_login_newbieBehavior, "", dayIndex, dayIndex)
  123. // 1=活跃时长(大厅模块)
  124. // this.handleEvent(tag_login_activeTime, "", 0, 0)
  125. // 2=付费金额(充值模块)
  126. // this.handleEvent(tag_charge_Amount, "", 0, 0)
  127. // 9=ip危险(注册模块)
  128. this.calIPAndIMei(tag_register_ipDanger, scope.IPAddress, "")
  129. // 10=IMei危险(注册模块)
  130. this.calIPAndIMei(tag_register_iMeiDanger, "", scope.IMei)
  131. // 11=注册来源渠道
  132. this.handleEvent(tag_register_utmsource, scope.UTMSource, dayIndex, dayIndex)
  133. } else { // 正常登录
  134. // 在线
  135. if scope.OnlineSeconds > 0 {
  136. // 1=活跃时长(大厅模块)
  137. this.handleEvent(tag_login_activeTime, "", scope.OnlineSeconds, 0)
  138. timeOfDay := ""
  139. timeFlag := time.Now().Hour()*100 + time.Now().Minute()
  140. if timeFlag >= 500 && timeFlag < 900 {
  141. timeOfDay = "早晨"
  142. } else if timeFlag >= 900 && timeFlag < 1200 {
  143. timeOfDay = "上午"
  144. } else if timeFlag >= 1200 && timeFlag < 1400 {
  145. timeOfDay = "中午"
  146. } else if timeFlag >= 1400 && timeFlag < 1800 {
  147. timeOfDay = "下午"
  148. } else if timeFlag >= 1800 && timeFlag < 1930 {
  149. timeOfDay = "黄昏"
  150. } else if timeFlag >= 1930 && timeFlag < 2200 {
  151. timeOfDay = "晚上"
  152. } else if timeFlag < 500 || timeFlag >= 2200 {
  153. timeOfDay = "夜间"
  154. }
  155. // 25=时间偏好(大厅模块)
  156. this.handleEvent(tag_time_love, timeOfDay, scope.OnlineSeconds, 0)
  157. }
  158. // 17=新手行为(大厅模块)
  159. this.handleEvent(tag_login_newbieBehavior, "", dayIndex, 0)
  160. // 20=登录回归
  161. this.handleEvent(tag_login_return, "", 1, 0)
  162. }
  163. case pb.Type_Charge: // 充值
  164. payNum := 0
  165. // 有实际充值才算
  166. if scope.PayPrice > 0 {
  167. payNum = scope.Num
  168. }
  169. // 2=付费金额(充值模块)
  170. this.handleEvent(tag_charge_Amount, "", int(scope.PayPrice), 0)
  171. // 11=输金危险(游戏模块、充值模块)
  172. this.handleEvent(tag_charge_game_loseDanger, "", 0, int(scope.PayPrice))
  173. // 18=赚金危险
  174. this.handleEvent(tag_charge_game_winDanger, "", 0, int(scope.PayPrice))
  175. // 13=潜在付费(充值模块)
  176. this.handleEvent(tag_charge_potentialCharge, "", scope.Num, int(scope.PayPrice))
  177. // 14=被动付费(充值模块)
  178. this.handleEvent(tag_charge_passiveCharge, "", scope.GoldAmount, payNum)
  179. // 15=储蓄付费(充值模块)
  180. this.handleEvent(tag_charge_savingsCharge, "", scope.GoldAmount, int(scope.PayPrice))
  181. // 折扣
  182. if scope.IsDiscount {
  183. // 16=折扣付费(充值模块,主要用于礼包购买)
  184. this.handleEvent(tag_charge_discountCharge, "", payNum, payNum)
  185. } else {
  186. // 16=折扣付费(充值模块,主要用于礼包购买)
  187. this.handleEvent(tag_charge_discountCharge, "", 0, payNum)
  188. }
  189. // 24=付费频率
  190. this.handleEvent(tag_charge_frequency, "", payNum, 0)
  191. case pb.Type_Game: // 游戏
  192. // 好友房
  193. if scope.IsFriendRoom {
  194. // 4=好友房(游戏模块)
  195. this.handleEvent(tag_game_friendRoom, strconv.Itoa(scope.GameId), scope.Num, 0)
  196. // 赢金币
  197. if scope.GoldAmount > 0 {
  198. // 12=作弊危险(游戏模块、充值模块)
  199. this.handleEvent(tag_game_cheatingDanger, "", scope.GoldAmount, scope.GoldAmount)
  200. }
  201. } else { // 普通游戏
  202. // 输金币
  203. if scope.GoldAmount < 0 {
  204. // 11=输金危险(游戏模块、充值模块)
  205. this.handleEvent(tag_charge_game_loseDanger, "", -scope.GoldAmount, 0)
  206. } else if scope.GoldAmount > 0 { // 赢金币
  207. // 12=作弊危险(游戏模块、充值模块)
  208. this.handleEvent(tag_game_cheatingDanger, "", 0, scope.GoldAmount)
  209. // 18=赚金危险
  210. this.handleEvent(tag_charge_game_winDanger, "", scope.GoldAmount, 0)
  211. }
  212. }
  213. // 游戏喜好(游戏模块:3=游戏时长、22=游戏流水、23=报名次数)
  214. if scope.OnlineSeconds > 0 {
  215. this.handleEvent(tag_game_love_online, strconv.Itoa(scope.GameId), scope.OnlineSeconds, 0)
  216. } else if scope.GoldAmount != 0 {
  217. gold := int(math.Abs(float64(scope.GoldAmount)))
  218. this.handleEvent(tag_game_love_bet, strconv.Itoa(scope.GameId), gold, 0)
  219. }
  220. case pb.Type_Task: // 任务
  221. // 6=任务类(任务模块)
  222. this.handleEvent(tag_task_award, "", scope.Num, 0)
  223. case pb.Type_Chat: // 聊天
  224. // 7=聊天类(聊天模块)
  225. this.handleEvent(tag_chat, "", scope.Num, 0)
  226. case pb.Type_AudioRoom: // 6=语聊房
  227. // 5=互动类(语聊房模块)
  228. this.handleEvent(tag_audioRoom_interactive, "", scope.Num, 0)
  229. case pb.Type_Friend: // 7=好友
  230. // 8=交际类(好友模块)
  231. this.handleEvent(tag_friend, "", scope.Num, 0)
  232. case pb.Type_Bankruptcy: // 8=破产
  233. // 21=破产
  234. this.handleEvent(tag_bankruptcy, "", scope.Num, 0)
  235. default:
  236. log.Error("user.dispatch userId=%d typeId=%d scope=%+v is not dealt ", this.userId, typeId, scope)
  237. }
  238. return
  239. }
  240. // 处理事件
  241. func (this *userInfo) handleEvent(typeId int, param string, value int, totalValue int) {
  242. dayIndex := common.GetDayIndex(common.GetTimeStamp())
  243. var (
  244. labelInfo *pb.LabelInfo
  245. dayInfo *pb.DayInfo
  246. )
  247. // 标签列表
  248. for _, v := range this.label_list {
  249. if v.TypeId != typeId {
  250. continue
  251. }
  252. labelInfo = v
  253. break
  254. }
  255. // 标签不存在
  256. if labelInfo == nil {
  257. labelInfo = &pb.LabelInfo{
  258. TypeId: typeId,
  259. }
  260. this.label_list = append(this.label_list, labelInfo)
  261. }
  262. // 累计类(如:充值、输金风险、被动付费、储蓄付费、折扣付费、交际类、登录回归)
  263. if typeId == tag_charge_game_loseDanger || typeId == tag_charge_game_winDanger || typeId == tag_charge_passiveCharge ||
  264. typeId == tag_charge_savingsCharge || typeId == tag_charge_discountCharge ||
  265. typeId == tag_friend || typeId == tag_login_return {
  266. labelInfo.TotalValue += totalValue
  267. } else if typeId == tag_login_newbieBehavior { // 新手行为
  268. if totalValue > 0 {
  269. labelInfo.TotalValue = totalValue
  270. }
  271. }
  272. // 每天数据
  273. for _, v := range labelInfo.Days {
  274. // 判断日期
  275. if v.Index != dayIndex {
  276. continue
  277. }
  278. // 判断游戏ID
  279. if v.Param != param {
  280. continue
  281. }
  282. dayInfo = v
  283. }
  284. // 每天数据不存在
  285. if dayInfo == nil {
  286. dayInfo = &pb.DayInfo{
  287. Index: dayIndex,
  288. Param: param,
  289. Value: 0,
  290. }
  291. labelInfo.Days = append(labelInfo.Days, dayInfo)
  292. }
  293. // 保留 max_days 天数据
  294. if count := len(labelInfo.Days); count > max_days {
  295. labelInfo.Days = labelInfo.Days[count-max_days:]
  296. }
  297. // 作弊危险
  298. if typeId == tag_game_cheatingDanger {
  299. // 获取配置信息
  300. cfg := mgr.getConfigInfo(labelInfo.TypeId)
  301. if cfg == nil {
  302. log.Error("user.triggerCounter userId=%d typeId=%d", this.userId, typeId)
  303. return
  304. }
  305. for _, v := range cfg.Content {
  306. if value < v.Min && totalValue < v.Min {
  307. return
  308. }
  309. }
  310. labelInfo.TotalValue += totalValue
  311. } else if typeId == tag_charge_potentialCharge { // 潜在付费
  312. dayInfo.ExtValue = totalValue
  313. }
  314. // 储蓄付费、交际类、新手行为、登录回归,不累计
  315. if typeId == tag_charge_savingsCharge || typeId == tag_friend || typeId == tag_login_newbieBehavior || typeId == tag_login_return {
  316. dayInfo.Value = value
  317. } else if typeId == tag_charge_passiveCharge { // 被动付费
  318. // 获取配置信息
  319. cfg := mgr.getConfigInfo(labelInfo.TypeId)
  320. if cfg == nil {
  321. log.Error("user.triggerCounter userId=%d typeId=%d", this.userId, typeId)
  322. return
  323. }
  324. for _, v := range cfg.Content {
  325. if value <= v.Min {
  326. dayInfo.Value += totalValue
  327. break
  328. }
  329. }
  330. } else { // 累计
  331. dayInfo.Value += value
  332. }
  333. go func() {
  334. var ret pb.CalResult
  335. // 计算用户标签
  336. if ret = this.cal(labelInfo, value); ret.Success && labelInfo.LabelId != ret.LabelId {
  337. // log.Debug("handleEvent userId=%d ret=%+v", this.userId, ret)
  338. labelInfo.LabelId = ret.LabelId
  339. if ret.PoolValue != 0 {
  340. // 触发水池
  341. go waterpool.GrantUserNewWaterPool(this.userId, ret.PoolValue, ret.LabelName)
  342. }
  343. }
  344. // TODO:存入数据库
  345. trans_Save(this.userId, ret.Days, labelInfo)
  346. }()
  347. }
  348. // 根据用户数据计算标签
  349. func (this *userInfo) cal(labelInfo *pb.LabelInfo, value int) pb.CalResult {
  350. var ret pb.CalResult
  351. // 获取配置信息
  352. cfg := mgr.getConfigInfo(labelInfo.TypeId)
  353. if cfg == nil {
  354. log.Error("user.cal userId=%d typeId=%d", this.userId, labelInfo.TypeId)
  355. return ret
  356. }
  357. total, totalExt, dayIndex := 0, 0, common.GetDayIndex(common.GetTimeStamp())
  358. switch labelInfo.TypeId {
  359. case tag_login_activeTime: // 1=活跃时长
  360. for _, v := range labelInfo.Days {
  361. if cfg.Days > 0 && v.Index < dayIndex-cfg.Days {
  362. continue
  363. }
  364. total += v.Value
  365. }
  366. avg := total / cfg.Days
  367. for _, v := range cfg.Content {
  368. if v.Min <= avg && avg <= v.Max {
  369. ret = pb.CalResult{
  370. Success: true,
  371. LabelId: v.LabelId,
  372. LabelName: v.LabelName,
  373. PoolValue: v.PoolValue,
  374. Days: cfg.Days,
  375. }
  376. return ret
  377. }
  378. }
  379. case tag_charge_Amount: // 2=付费金额
  380. fallthrough
  381. case tag_game_friendRoom: // 4=好友房
  382. fallthrough
  383. case tag_audioRoom_interactive: // 5=互动类
  384. fallthrough
  385. case tag_task_award: // 6=任务类
  386. fallthrough
  387. case tag_chat: // 7=聊天类
  388. fallthrough
  389. case tag_bankruptcy: // 21=破产
  390. fallthrough
  391. case tag_game_love_online: // 3=游戏喜好时长
  392. fallthrough
  393. case tag_game_love_bet: // 22=游戏喜好流水
  394. fallthrough
  395. case tag_game_love_match: // 23=游戏喜好比赛报名
  396. fallthrough
  397. case tag_charge_frequency: // 24=付费频率
  398. for _, v := range labelInfo.Days {
  399. if cfg.Days > 0 && v.Index < dayIndex-cfg.Days {
  400. continue
  401. }
  402. total += v.Value
  403. }
  404. for _, v := range cfg.Content {
  405. if v.Min <= total && total <= v.Max {
  406. ret = pb.CalResult{
  407. Success: true,
  408. LabelId: v.LabelId,
  409. LabelName: v.LabelName,
  410. PoolValue: v.PoolValue,
  411. Days: cfg.Days,
  412. }
  413. return ret
  414. }
  415. }
  416. case tag_friend: // 8=交际类
  417. fallthrough
  418. case tag_login_return: // 20=登录回归
  419. for _, v := range cfg.Content {
  420. if labelInfo.TotalValue >= v.Min {
  421. ret = pb.CalResult{
  422. Success: true,
  423. LabelId: v.LabelId,
  424. LabelName: v.LabelName,
  425. PoolValue: v.PoolValue,
  426. Days: cfg.Days,
  427. }
  428. return ret
  429. }
  430. }
  431. case tag_charge_potentialCharge: // 13=潜在付费
  432. for _, v := range labelInfo.Days {
  433. if cfg.Days > 0 && v.Index < dayIndex-cfg.Days {
  434. continue
  435. }
  436. total += v.Value
  437. totalExt += v.ExtValue
  438. }
  439. for _, v := range cfg.Content {
  440. if v.Min <= total && v.Ext >= totalExt {
  441. ret = pb.CalResult{
  442. Success: true,
  443. LabelId: v.LabelId,
  444. LabelName: v.LabelName,
  445. PoolValue: v.PoolValue,
  446. Days: cfg.Days,
  447. }
  448. return ret
  449. }
  450. }
  451. case tag_register_ipDanger: // 9=IP危险
  452. // Nothing(manager已处理)
  453. case tag_register_iMeiDanger: // 10=IMei危险
  454. // Nothing(manager已处理)
  455. case tag_charge_game_loseDanger: // 11=输金危险
  456. fallthrough
  457. case tag_charge_game_winDanger: // 18=赚金危险
  458. for _, v := range labelInfo.Days {
  459. if cfg.Days > 0 && v.Index < dayIndex-cfg.Days {
  460. continue
  461. }
  462. total += v.Value
  463. }
  464. for _, v := range cfg.Content {
  465. if total > 0 && total >= int(float64(labelInfo.TotalValue*v.Ext)*(float64(v.Percentage)/100.00)) && total >= v.Min {
  466. ret = pb.CalResult{
  467. Success: true,
  468. LabelId: v.LabelId,
  469. LabelName: v.LabelName,
  470. PoolValue: v.PoolValue,
  471. Days: cfg.Days,
  472. }
  473. return ret
  474. }
  475. }
  476. case tag_game_cheatingDanger: // 12=作弊危险
  477. fallthrough
  478. case tag_charge_passiveCharge: // 14=被动付费
  479. fallthrough
  480. case tag_charge_discountCharge: // 16=折扣付费
  481. for _, v := range labelInfo.Days {
  482. if cfg.Days > 0 && v.Index < dayIndex-cfg.Days {
  483. continue
  484. }
  485. total += v.Value
  486. }
  487. for _, v := range cfg.Content {
  488. if total > 0 && total >= int(float64(labelInfo.TotalValue)*(float64(v.Percentage)/100.00)) {
  489. ret = pb.CalResult{
  490. Success: true,
  491. LabelId: v.LabelId,
  492. LabelName: v.LabelName,
  493. PoolValue: v.PoolValue,
  494. Days: cfg.Days,
  495. }
  496. return ret
  497. }
  498. }
  499. case tag_charge_savingsCharge: // 15=储蓄付费
  500. for _, v := range cfg.Content {
  501. if value >= int(float64(labelInfo.TotalValue*v.Ext)*(float64(v.Percentage)/100.00)) && value >= v.Min {
  502. ret = pb.CalResult{
  503. Success: true,
  504. LabelId: v.LabelId,
  505. LabelName: v.LabelName,
  506. PoolValue: v.PoolValue,
  507. Days: cfg.Days,
  508. }
  509. return ret
  510. }
  511. }
  512. case tag_login_newbieBehavior: // 17=新手行为
  513. // total = labelInfo.Days[len(labelInfo.Days)-1].Index - labelInfo.TotalValue + 1
  514. if cfg.Days > 0 && labelInfo.TotalValue < labelInfo.Days[len(labelInfo.Days)-1].Index-cfg.Days {
  515. ret = pb.CalResult{
  516. Success: true,
  517. LabelId: "",
  518. LabelName: "",
  519. PoolValue: 0,
  520. Days: cfg.Days,
  521. }
  522. return ret
  523. }
  524. total = len(labelInfo.Days)
  525. for _, v := range cfg.Content {
  526. if v.Min <= total && total <= v.Max {
  527. // log.Debug("userId=%d v=%+v", this.userId, v)
  528. ret = pb.CalResult{
  529. Success: true,
  530. LabelId: v.LabelId,
  531. LabelName: v.LabelName,
  532. PoolValue: v.PoolValue,
  533. Days: cfg.Days,
  534. }
  535. return ret
  536. }
  537. }
  538. case tag_register_utmsource: // 19=新注册来源
  539. utmSource := ""
  540. for _, v := range labelInfo.Days {
  541. if cfg.Days > 0 && v.Index < dayIndex-cfg.Days {
  542. continue
  543. }
  544. utmSource = strings.ToLower(v.Param)
  545. }
  546. for _, v := range cfg.Content {
  547. if !strings.Contains(utmSource, strings.ToLower(v.LabelName)) {
  548. continue
  549. }
  550. ret = pb.CalResult{
  551. Success: true,
  552. LabelId: v.LabelId,
  553. LabelName: v.LabelName,
  554. PoolValue: v.PoolValue,
  555. Days: cfg.Days,
  556. }
  557. return ret
  558. }
  559. case tag_time_love: // 25=时间偏好
  560. sum_list := make(map[string]int)
  561. for _, v := range labelInfo.Days {
  562. if cfg.Days > 0 && v.Index < dayIndex-cfg.Days {
  563. continue
  564. }
  565. vu, ok := sum_list[v.Param]
  566. if ok {
  567. vu += v.Value
  568. }
  569. sum_list[v.Param] = vu
  570. }
  571. if len(sum_list) <= 0 {
  572. break
  573. }
  574. var (
  575. max_value int
  576. max_labelId string
  577. max_labelName string
  578. max_poolValue int
  579. )
  580. for _, v := range cfg.Content {
  581. vu, ok := sum_list[v.LabelName]
  582. if !ok {
  583. continue
  584. }
  585. if vu < max_value {
  586. continue
  587. }
  588. max_value = vu
  589. max_labelId = v.LabelId
  590. max_labelName = v.LabelName
  591. max_poolValue = v.PoolValue
  592. }
  593. ret = pb.CalResult{
  594. Success: true,
  595. LabelId: max_labelId,
  596. LabelName: max_labelName,
  597. PoolValue: max_poolValue,
  598. Days: cfg.Days,
  599. }
  600. return ret
  601. }
  602. ret = pb.CalResult{
  603. Success: true,
  604. LabelId: "",
  605. LabelName: "",
  606. PoolValue: 0,
  607. Days: cfg.Days,
  608. }
  609. return ret
  610. }
  611. // IPAddress、IMei 类计算
  612. func (this *userInfo) calIPAndIMei(typeId int, ipAddress, iMei string) {
  613. // 获取配置信息
  614. cfg := mgr.getConfigInfo(typeId)
  615. if cfg == nil {
  616. log.Error("user.calIPAndIMei userId=%d typeId=%d ipAddress=%s iMei=%s", this.userId, typeId, ipAddress, iMei)
  617. return
  618. }
  619. for _, v := range cfg.Content {
  620. // TODO:从数据库查询
  621. users := trans_GetIPAndIMei(ipAddress, iMei, cfg.Days)
  622. // 没有达到用户数
  623. if len(users) < v.Min {
  624. continue
  625. }
  626. // 符合标签的用户
  627. for _, uId := range users {
  628. // 获取当前用户
  629. u := mgr.getUser(uId)
  630. if u == nil {
  631. log.Debug("manager.calIPAndIMei userId=%d typeId=%d ipAddress=%s iMei=%s ", uId, typeId, ipAddress, iMei)
  632. continue
  633. }
  634. // 设置标签
  635. u.setLabel(typeId, cfg.Days, v.LabelId)
  636. }
  637. }
  638. return
  639. }