teammgr.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package team
  2. import (
  3. "bet24.com/log"
  4. pb "bet24.com/servers/micros/guess/proto"
  5. "strconv"
  6. )
  7. var mgr *teammgr
  8. // 球队
  9. type teammgr struct {
  10. teamList []pb.Team
  11. }
  12. func getTeamManager() *teammgr {
  13. if mgr == nil {
  14. mgr = new(teammgr)
  15. mgr.ctor()
  16. }
  17. return mgr
  18. }
  19. func (this *teammgr) ctor() {
  20. list := trans_GetTeamList()
  21. this.teamList = list
  22. return
  23. }
  24. // 获取球队信息
  25. func (this *teammgr) getTeam(teamId int) pb.Team {
  26. for _, v := range this.teamList {
  27. if v.Id == teamId {
  28. return v
  29. }
  30. }
  31. return pb.Team{}
  32. }
  33. // 获取球队列表
  34. func (this *teammgr) getTeamList() []pb.Team {
  35. return this.teamList
  36. }
  37. // 添加球队信息
  38. func (this *teammgr) addTeam(name, icon, shortName string, op pb.OpUser) {
  39. // GOTO:存入数据库
  40. teamId := trans_AddTeam(name, icon, shortName, op)
  41. if teamId <= 0 {
  42. log.Error("addTeam.trans_AddTeam name=%s icon=%s shortName=%s", name, icon, shortName)
  43. return
  44. }
  45. // 新增
  46. this.teamList = append(this.teamList, pb.Team{
  47. Id: teamId,
  48. Name: name,
  49. Icon: icon,
  50. ShortName: shortName,
  51. })
  52. return
  53. }
  54. // 修改球队信息
  55. func (this *teammgr) updateTeam(id int, name, icon, shortName string, op pb.OpUser, freshMatchTeam func(teamId int)) {
  56. for i := 0; i < len(this.teamList); i++ {
  57. if this.teamList[i].Id != id {
  58. continue
  59. }
  60. info := pb.Team{
  61. Id: id,
  62. Name: name,
  63. Icon: icon,
  64. ShortName: shortName,
  65. }
  66. // 修改
  67. this.teamList[i] = info
  68. // GOTO:存入数据库
  69. trans_UpdateTeam(info, op)
  70. // 刷新球赛队伍
  71. go freshMatchTeam(info.Id)
  72. return
  73. }
  74. }
  75. // 打印球队
  76. func (this *teammgr) dumpTeam(param1 string) {
  77. var teamId int
  78. if param1 != "" {
  79. teamId, _ = strconv.Atoi(param1)
  80. }
  81. log.Debug(" ^_^ 开始打印球队数据,房间(%d)个", len(this.teamList))
  82. for _, v := range this.teamList {
  83. if teamId > 0 && v.Id != teamId {
  84. continue
  85. }
  86. log.Debug("%+v", v)
  87. }
  88. log.Debug("完成球队数据打印 ^_^")
  89. }