match_active.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package model
  2. import (
  3. "fmt"
  4. "strings"
  5. "go-common/library/xstr"
  6. )
  7. const (
  8. _moduleInsertSQL = "INSERT INTO es_matchs_module(ma_id,name,oids) VALUES %s"
  9. _moduleEditSQL = "UPDATE es_matchs_module SET name = CASE %s END,oids = CASE %s END WHERE id IN (%s)"
  10. )
  11. // ParamMA .
  12. type ParamMA struct {
  13. MatchActive
  14. Modules string `json:"-" form:"modules"`
  15. Adid int64 `json:"-" form:"adid" validate:"required"`
  16. }
  17. // MatchActive .
  18. type MatchActive struct {
  19. ID int64 `json:"id" form:"id"`
  20. Sid int64 `json:"sid" form:"sid" validate:"required"`
  21. Mid int64 `json:"mid" form:"mid" validate:"required"`
  22. Background string `json:"background" form:"background"`
  23. BackColor string `json:"back_color" form:"back_color"`
  24. ColorStep string `json:"color_step" form:"color_step"`
  25. LiveID int64 `json:"live_id" form:"live_id" validate:"required"`
  26. Intr string `json:"intr" form:"intr"`
  27. Focus string `json:"focus" form:"focus"`
  28. URL string `json:"url" form:"url"`
  29. Status int `json:"status" form:"status"`
  30. H5Background string `json:"h5_background" form:"h5_background"`
  31. H5BackColor string `json:"h5_back_color" form:"h5_back_color"`
  32. H5Focus string `json:"h5_focus" form:"h5_focus"`
  33. H5URL string `json:"h5_url" form:"h5_url"`
  34. IntrLogo string `json:"intr_logo" form:"intr_logo"`
  35. IntrTitle string `json:"intr_title" form:"intr_title"`
  36. IntrText string `json:"intr_text" form:"intr_text"`
  37. }
  38. // Module .
  39. type Module struct {
  40. ID int64 `json:"id"`
  41. MaID int64 `json:"ma_id"`
  42. Name string `json:"name"`
  43. Oids string `json:"oids"`
  44. Status int `json:"-" form:"status"`
  45. }
  46. // MatchModule .
  47. type MatchModule struct {
  48. *MatchActive
  49. Modules []*Module `json:"modules"`
  50. MatchTitle string `json:"match_title"`
  51. MatchSubTitle string `json:"match_sub_title"`
  52. SeasonTitle string `json:"season_title"`
  53. SeasonSubTitle string `json:"season_sub_title"`
  54. }
  55. // TableName es_matchs_module.
  56. func (t Module) TableName() string {
  57. return "es_matchs_module"
  58. }
  59. // TableName es_matchs_active.
  60. func (t MatchActive) TableName() string {
  61. return "es_matchs_active"
  62. }
  63. // BatchAddModuleSQL .
  64. func BatchAddModuleSQL(maID int64, data []*Module) string {
  65. if len(data) == 0 {
  66. return ""
  67. }
  68. var rowStrings []string
  69. for _, v := range data {
  70. rowStrings = append(rowStrings, fmt.Sprintf("(%d,'%s','%s')", maID, v.Name, v.Oids))
  71. }
  72. return fmt.Sprintf(_moduleInsertSQL, strings.Join(rowStrings, ","))
  73. }
  74. // BatchEditModuleSQL .
  75. func BatchEditModuleSQL(mapModuel []*Module) string {
  76. if len(mapModuel) == 0 {
  77. return ""
  78. }
  79. var (
  80. nameStr, oidsStr string
  81. ids []int64
  82. )
  83. for _, module := range mapModuel {
  84. nameStr = fmt.Sprintf("%s WHEN id = %d THEN '%s'", nameStr, module.ID, module.Name)
  85. oidsStr = fmt.Sprintf("%s WHEN id = %d THEN '%s'", oidsStr, module.ID, module.Oids)
  86. ids = append(ids, module.ID)
  87. }
  88. return fmt.Sprintf(_moduleEditSQL, nameStr, oidsStr, xstr.JoinInts(ids))
  89. }