trans_getGameList.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package transaction
  2. import (
  3. "encoding/json"
  4. "runtime/debug"
  5. "sort"
  6. "bet24.com/database"
  7. "bet24.com/log"
  8. )
  9. const (
  10. GameType_All = iota // 所有类型
  11. GameType_Gold // 金币类型
  12. GameType_Chip // 元宝类型
  13. )
  14. type trans_getGameList_in struct {
  15. PartnerID int
  16. }
  17. // GameID, ChineseName, EnglishName, IconVersion,
  18. // ServerIP, Port, Version, DownloadRoot, WebRoot,
  19. // 0 AS PartnerSort
  20. type GameInfo struct {
  21. GameID int
  22. ChineseName string
  23. EnglishName string
  24. ServerAddr string
  25. GameType int // 游戏类型
  26. DisplaySort string
  27. goldSort string
  28. chipSort string
  29. NeedLevel int // 所需等级
  30. }
  31. type trans_getGameList struct {
  32. database.Trans_base
  33. In *trans_getGameList_in
  34. Out []GameInfo
  35. }
  36. func newTransGetGameList() *trans_getGameList {
  37. return &trans_getGameList{
  38. In: &trans_getGameList_in{},
  39. }
  40. }
  41. func (this *trans_getGameList) DoAction(ch chan<- interface{}) {
  42. defer func() {
  43. if err := recover(); err != nil {
  44. log.Release("transaction recover %v", err)
  45. log.Release("%s", debug.Stack())
  46. }
  47. if ch != nil {
  48. ch <- this
  49. }
  50. }()
  51. statement := database.NewStatement()
  52. statement.SetNeedReturnValue(false)
  53. statement.SetOpenRecordSet(true)
  54. statement.SetProcName("WS_AllGame_GetList")
  55. statement.AddParamter("@PartnerID", database.AdParamInput, database.AdInteger, 4, this.In.PartnerID)
  56. sqlstring := statement.GenSql()
  57. //log.Debug(sqlstring)
  58. jsonData := CenterDB.ExecSqlJson(sqlstring)
  59. json.Unmarshal([]byte(jsonData), &this.Out)
  60. for i := 0; i < len(this.Out); i++ {
  61. displaySort := this.Out[i].DisplaySort
  62. if len(displaySort) >= 5 {
  63. this.Out[i].goldSort = displaySort[1:3]
  64. this.Out[i].chipSort = displaySort[3:]
  65. }
  66. }
  67. }
  68. func GetGameListFromDB(isChipRoom bool) []GameInfo {
  69. act := newTransGetGameList()
  70. act.DoAction(nil)
  71. var ret []GameInfo
  72. for _, v := range act.Out {
  73. if isChipRoom && v.GameType == GameType_Gold {
  74. continue
  75. }
  76. if !isChipRoom && v.GameType == GameType_Chip {
  77. continue
  78. }
  79. ret = append(ret, v)
  80. }
  81. if isChipRoom {
  82. sort.SliceStable(ret, func(i, j int) bool {
  83. return ret[i].chipSort < ret[j].chipSort
  84. })
  85. } else {
  86. sort.SliceStable(ret, func(i, j int) bool {
  87. return ret[i].goldSort < ret[j].goldSort
  88. })
  89. }
  90. return ret
  91. }