gamemgr.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package game
  2. import (
  3. "fmt"
  4. "sort"
  5. "time"
  6. "bet24.com/log"
  7. )
  8. var mgr *gameManager
  9. type gameManager struct {
  10. index_list map[string]*gameIndexInfo
  11. }
  12. func Run() {
  13. mgr = new(gameManager)
  14. mgr.index_list = make(map[string]*gameIndexInfo)
  15. }
  16. func (this *gameManager) recordIndexStat(gameId, partnerId int, beginTime, endTime string) []*gameIndexInfo {
  17. var list []*gameIndexInfo
  18. end, _ := time.Parse(dateFormat, endTime)
  19. for begin, _ := time.Parse(dateFormat, beginTime); !begin.After(end); begin = begin.AddDate(0, 0, 1) {
  20. dateStr := begin.Format(dateFormat)
  21. key := fmt.Sprintf("%s_%d_%d", dateStr, gameId, partnerId)
  22. v, ok := this.index_list[key]
  23. if ok {
  24. list = append(list, v)
  25. continue
  26. }
  27. for _, v := range gameRecordIndex(gameId, partnerId, dateStr, dateStr) {
  28. log.Debug("gamemgr.recordIndexStat ==> %+v", v)
  29. if begin.Format(dateFormat) == time.Now().Format(dateFormat) {
  30. list = append(list, v)
  31. continue
  32. }
  33. key = fmt.Sprintf("%s_%d_%d", v.DateFlag, gameId, partnerId)
  34. this.index_list[key] = v
  35. list = append(list, v)
  36. }
  37. }
  38. sort.SliceStable(list, func(i, j int) bool {
  39. return list[i].DateFlag < list[j].DateFlag
  40. })
  41. return list
  42. }
  43. // 获取牌局统计
  44. func (this *gameManager) getCardStatList(req requestInfo) (int, []cardStatInfo) {
  45. return trans_getCardStatList(req)
  46. }
  47. // 中途退出统计
  48. func (this *gameManager) getMidwayStatList(req requestInfo) (int, []midwayStatInfo) {
  49. return trans_getMidwayStatList(req)
  50. }
  51. // 水池统计
  52. func (this *gameManager) getWaterPoolStatList(req requestInfo) []*info {
  53. return trans_getWaterPoolStatList(req.BeginTime, req.EndTime)
  54. }