record_user.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package gamelogic
  2. import (
  3. "bet24.com/log"
  4. "bet24.com/servers/games/fish/fish"
  5. "bet24.com/servers/games/fish/fishcommon"
  6. "bet24.com/servers/insecureframe/frame"
  7. "encoding/json"
  8. )
  9. // 玩家纪录
  10. type RecordInfo struct {
  11. FishID int // 鱼ID
  12. FishOdds int // 鱼的倍率
  13. Catched int // 捕获数量
  14. Consume int // 消耗金币
  15. Return int // 返还金币
  16. }
  17. type UserBetInfo struct {
  18. ServerName string `json:"SN"` // 服务器名
  19. RoomID int `json:"RID"` // 桌子号
  20. BatchID int `json:"BID"` // 序列号
  21. TotalConsume int `json:"TC"` // 总消耗
  22. TotalReturn int `json:"TR"` // 总返还
  23. From int `json:"F"` // 开始时间
  24. To int `json:"T"` // 结束时间
  25. }
  26. type UserRecord struct {
  27. UserBetInfo
  28. UserId int // 用户ID
  29. Records map[int]*RecordInfo
  30. }
  31. func (this *UserRecord) addRecord(fishID int, consume int, ret int) {
  32. fi := fish.GetFishInfo(fishID)
  33. if fi == nil {
  34. log.Release("UserRecord.addRecord invalid fishID %d", fishID)
  35. return
  36. }
  37. // 是否已有
  38. record, ok := this.Records[fishID]
  39. if !ok {
  40. record = new(RecordInfo)
  41. record.FishID = fishID
  42. record.FishOdds = fi.Odds
  43. this.Records[fishID] = record
  44. }
  45. if ret > 0 {
  46. record.Catched++
  47. }
  48. record.Consume += consume
  49. record.Return += ret
  50. //log.Debug("UserRecord.addRecord[%d],fish[%d],consume[%d]ret[%d]", this.UserId, fishID, consume, ret)
  51. }
  52. func (this *UserRecord) flush(table frame.Table) {
  53. this.To = fishcommon.GetTime()
  54. this.TotalConsume = 0
  55. this.TotalReturn = 0
  56. var detail [][]int
  57. for _, v := range this.Records {
  58. this.TotalReturn += v.Return
  59. this.TotalConsume += v.Consume
  60. r := []int{v.FishID, v.FishOdds, v.Catched, v.Consume, v.Return}
  61. detail = append(detail, r)
  62. }
  63. bd, _ := json.Marshal(this.UserBetInfo)
  64. rd, _ := json.Marshal(detail)
  65. log.Debug("UserRecord.flush %d Consume[%d]Return[%d]", this.UserId, this.TotalConsume, this.TotalReturn)
  66. go table.WriteBetRecord(this.UserId, this.TotalConsume, this.TotalReturn, 2.0, string(bd),
  67. string(rd), this.ServerName)
  68. /*
  69. writeBetRecord := transaction.NewTransWriteBetRecord()
  70. writeBetRecord.IN.UserID = this.UserId
  71. writeBetRecord.IN.GameID = fishcommon.GAMEID
  72. writeBetRecord.IN.BetAmount = this.TotalConsume
  73. writeBetRecord.IN.WinAmount = this.TotalReturn
  74. writeBetRecord.IN.WinRate = 2.0
  75. writeBetRecord.IN.RoomName = this.ServerName
  76. writeBetRecord.IN.BetDesc = string(bd)
  77. rd, _ := json.Marshal(detail)
  78. writeBetRecord.IN.ResultDesc = string(rd)
  79. go writeBetRecord.DoAction(nil)
  80. */
  81. }