splash.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package splash
  2. import (
  3. "encoding/json"
  4. "go-common/app/interface/main/app-resource/model"
  5. xtime "go-common/library/time"
  6. )
  7. // Splash is splash type.
  8. type Splash struct {
  9. ID int64 `json:"id"`
  10. Type int8 `json:"type"`
  11. Animate int8 `json:"animate"`
  12. Duration int16 `json:"duration"`
  13. Start xtime.Time `json:"start_time,omitempty"`
  14. End xtime.Time `json:"end_time,omitempty"`
  15. Image string `json:"thumb"`
  16. Hash string `json:"hash"`
  17. Times int16 `json:"times"`
  18. Skip int8 `json:"skip"`
  19. URI string `json:"uri"`
  20. Area string `json:"-"`
  21. Plat int8 `json:"-"`
  22. Goto string `json:"-"`
  23. Param string `json:"-"`
  24. Width int `json:"-"`
  25. Height int `json:"-"`
  26. Build int `json:"-"`
  27. Condition string `json:"-"`
  28. Operate int `json:"-"`
  29. NoPreview int `json:"-"`
  30. // bitrhday
  31. BirthStart string `json:"start_date,omitempty"`
  32. BirthEnd string `json:"end_date,omitempty"`
  33. BirthStartMonth string `json:"-"`
  34. BirthEndMonth string `json:"-"`
  35. }
  36. type List struct {
  37. ID int64 `json:"id"`
  38. Type int8 `json:"type"`
  39. CardType int8 `json:"card_type"`
  40. Duration int16 `json:"duration"`
  41. Start xtime.Time `json:"begin_time,omitempty"`
  42. End xtime.Time `json:"end_time,omitempty"`
  43. Image string `json:"thumb"`
  44. Hash string `json:"hash"`
  45. LogoURL string `json:"logo_url"`
  46. LogoHash string `json:"logo_hash"`
  47. Skip int8 `json:"skip"`
  48. URI string `json:"uri"`
  49. VideoURL string `json:"video_url,omitempty"`
  50. VideoHash string `json:"video_hash,omitempty"`
  51. VideoWidth int `json:"video_width,omitempty"`
  52. VideoHeight int `json:"video_height,omitempty"`
  53. URITitle string `json:"uri_title"`
  54. Source int `json:"source,omitempty"`
  55. CmMark int `json:"cm_mark,omitempty"`
  56. AdCb string `json:"ad_cb,omitempty"`
  57. ResourceID int `json:"resource_id,omitempty"`
  58. RequestID string `json:"request_id,omitempty"`
  59. ClientIP string `json:"client_ip,omitempty"`
  60. IsAd bool `json:"is_ad"`
  61. IsAdLoc bool `json:"is_ad_loc,omitempty"`
  62. Schema string `json:"schema,omitempty"`
  63. SchemaTitle string `json:"schema_title,omitempty"`
  64. SchemaPackageName string `json:"schema_package_name,omitempty"`
  65. SchemaCallupWhiteList []string `json:"schema_callup_white_list,omitempty"`
  66. Extra json.RawMessage `json:"extra,omitempty"`
  67. }
  68. type Show struct {
  69. ID int64 `json:"id"`
  70. Stime xtime.Time `json:"stime"`
  71. Etime xtime.Time `json:"etime"`
  72. }
  73. type CmSplash struct {
  74. *CmConfig
  75. List []*List `json:"list,omitempty"`
  76. Show []*Show `json:"show,omitempty"`
  77. }
  78. type CmConfig struct {
  79. MaxTime int `json:"max_time"`
  80. MinInterval int `json:"min_interval"`
  81. PullInterval int `json:"pull_interval"`
  82. }
  83. // PlatChange
  84. func (s *Splash) PlatChange() {
  85. switch s.Plat {
  86. case 1: // resource iphone
  87. s.Plat = model.PlatIPhone
  88. case 2: // resource android
  89. s.Plat = model.PlatAndroid
  90. case 3: // resource pad
  91. s.Plat = model.PlatIPad
  92. case 4: // resource iphoneg
  93. s.Plat = model.PlatIPhoneI
  94. case 5: // resource androidg
  95. s.Plat = model.PlatAndroidG
  96. case 6: // resource padg
  97. s.Plat = model.PlatIPadI
  98. case 8: // resource androidi
  99. s.Plat = model.PlatAndroidI
  100. }
  101. if s.Operate == 1 { // NOTE: operate=1 means AD
  102. s.Type = 1 // NOTE: type=1 compatiable mobile, must type=1 can splash
  103. }
  104. }
  105. // BirthDate
  106. func (s *Splash) BirthDate() {
  107. s.BirthStart = s.Start.Time().Format("0102")
  108. s.BirthEnd = s.End.Time().Format("0102")
  109. s.BirthStartMonth = s.Start.Time().Format("01")
  110. s.BirthEndMonth = s.End.Time().Format("01")
  111. s.Start = xtime.Time(0)
  112. s.End = xtime.Time(0)
  113. }
  114. // Ratio calc width/height ratio.
  115. func Ratio(w, h int) float64 {
  116. return float64(w) / float64(h)
  117. }