card.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. package card
  2. import (
  3. "encoding/json"
  4. "strconv"
  5. "go-common/app/interface/main/app-card/model/card/ai"
  6. "go-common/app/interface/main/app-show/model"
  7. xtime "go-common/library/time"
  8. )
  9. type Column struct {
  10. ID int `json:"-"`
  11. Tab int `json:"-"`
  12. RegionID int `json:"-"`
  13. Tpl int `json:"-"`
  14. Name string `json:"-"`
  15. Desc string `json:"-"`
  16. PlatVer string `json:"-"`
  17. Plat int8 `json:"-"`
  18. Build int `json:"-"`
  19. Condition string `json:"-"`
  20. Type string `json:"-"`
  21. }
  22. type ColumnNper struct {
  23. ID int `json:"-"`
  24. ColumnID int `json:"-"`
  25. Name string `json:"-"`
  26. Desc string `json:"-"`
  27. Nper string `json:"-"`
  28. NperTime xtime.Time `json:"-"`
  29. Cover string `json:"-"`
  30. PlatVer string `json:"-"`
  31. Title string `json:"-"`
  32. Rtype int `json:"-"`
  33. Rvalue string `json:"-"`
  34. Plat int8 `json:"-"`
  35. Build int `json:"-"`
  36. Condition string `json:"-"`
  37. Goto string `json:"-"`
  38. Param string `json:"-"`
  39. URI string `json:"-"`
  40. }
  41. type Content struct {
  42. ID int `json:"-"`
  43. Module int `json:"-"`
  44. RecID int `json:"-"`
  45. Type int8 `json:"-"`
  46. Value string `json:"-"`
  47. Title string `json:"-"`
  48. TagID int `json:"-"`
  49. }
  50. type Card struct {
  51. ID int `json:"-"`
  52. Tab int `json:"-"`
  53. RegionID int `json:"-"`
  54. Type int `json:"-"`
  55. Title string `json:"-"`
  56. Cover string `json:"-"`
  57. Rtype int `json:"-"`
  58. Rvalue string `json:"-"`
  59. PlatVer string `json:"-"`
  60. Plat int8 `json:"-"`
  61. Build int `json:"-"`
  62. Condition string `json:"-"`
  63. TypeStr string `json:"-"`
  64. Goto string `json:"-"`
  65. Param string `json:"-"`
  66. URi string `json:"-"`
  67. Desc string `json:"-"`
  68. TagID int `json:"-"`
  69. }
  70. type ColumnList struct {
  71. Cid int `json:"-"`
  72. Ceid int `json:"-"`
  73. Name string `json:"-"`
  74. Cname string `json:"-"`
  75. PlatVer string `json:"-"`
  76. Plat int8 `json:"-"`
  77. Build int `json:"-"`
  78. Condition string `json:"-"`
  79. }
  80. type PlatLimit struct {
  81. Plat int8 `json:"plat"`
  82. Build int `json:"build"`
  83. Condition string `json:"conditions"`
  84. }
  85. type PopularCard struct {
  86. ID int64 `json:"id"`
  87. Title string `json:"title"`
  88. ChannelID int64 `json:"channel_id"`
  89. Type string `json:"type"`
  90. Value int64 `json:"value"`
  91. Reason string `json:"reason"`
  92. ReasonType int8 `json:"reason_type"`
  93. Pos int `json:"pos"`
  94. FromType string `json:"from_type"`
  95. PopularCardPlat map[int8][]*PopularCardPlat `json:"popularcardplat"`
  96. Idx int64 `json:"-"`
  97. CornerMark int8 `json:"corner_mark"`
  98. }
  99. type PopularCardPlat struct {
  100. CardID int64 `json:"card_id"`
  101. Plat int8 `json:"plat"`
  102. Condition string `json:"condition"`
  103. Build int `json:"build"`
  104. }
  105. func (c *Card) CardPlatChange() (platlinits []*PlatLimit) {
  106. platlinits = platJsonChange(c.PlatVer)
  107. return
  108. }
  109. func (c *Column) ColumnPlatChange() (platlinits []*PlatLimit) {
  110. platlinits = platJsonChange(c.PlatVer)
  111. return
  112. }
  113. func (c *ColumnList) ColumnListPlatChange() (platlinits []*PlatLimit) {
  114. platlinits = platJsonChange(c.PlatVer)
  115. return
  116. }
  117. func (c *ColumnNper) ColumnNperPlatChange() (platlinits []*PlatLimit) {
  118. platlinits = platJsonChange(c.PlatVer)
  119. return
  120. }
  121. func (c *Card) CardGotoChannge() {
  122. c.TypeStr = cardTypeChange(c.Type)
  123. c.Goto, c.Param, c.URi = gotoURI(c.Rtype, c.Rvalue)
  124. }
  125. func (c *Column) ColumnGotoChannge() {
  126. switch c.Tpl {
  127. case 1:
  128. c.Type = model.GotoDaily
  129. case 2:
  130. c.Type = model.GotoColumn
  131. }
  132. }
  133. func (c *ColumnNper) ColumnNperGotoChange() {
  134. c.Goto, c.Param, c.URI = gotoURI(c.Rtype, c.Rvalue)
  135. }
  136. func gotoURI(typeInt int, value string) (gotoStr, paramStr, uri string) {
  137. switch typeInt {
  138. case 1:
  139. gotoStr = model.GotoDaily
  140. case 4:
  141. gotoStr = model.GotoWeb
  142. case 5:
  143. gotoStr = model.GotoAv
  144. case 6:
  145. gotoStr = model.GotoLive
  146. case 7:
  147. gotoStr = model.GotoBangumi
  148. case 8:
  149. gotoStr = model.GotoGame
  150. case 9:
  151. gotoStr = model.GotoColumn
  152. case 10:
  153. gotoStr = model.GotoColumnStage
  154. case 11:
  155. gotoStr = model.GotoArticle
  156. default:
  157. return
  158. }
  159. paramStr = value
  160. uri = model.FillURI(gotoStr, paramStr, nil)
  161. return
  162. }
  163. func cardTypeChange(cardInt int) (cardStr string) {
  164. switch cardInt {
  165. case 1:
  166. cardStr = model.GotoDaily
  167. case 2:
  168. cardStr = model.GotoTopic
  169. case 3:
  170. cardStr = model.GotoActivity
  171. case 4:
  172. cardStr = model.GotoRank
  173. case 5:
  174. cardStr = model.GotoCard
  175. case 6:
  176. cardStr = model.GotoVeidoCard
  177. case 7:
  178. cardStr = model.GotoSpecialCard
  179. case 8:
  180. cardStr = model.GotoTagCard
  181. }
  182. return
  183. }
  184. // platJsonChange json change plat build condition
  185. func platJsonChange(jsonStr string) (platlinits []*PlatLimit) {
  186. var tmp []struct {
  187. Plat string `json:"plat"`
  188. Build string `json:"build"`
  189. Condition string `json:"conditions"`
  190. }
  191. if err := json.Unmarshal([]byte(jsonStr), &tmp); err == nil {
  192. for _, limit := range tmp {
  193. platlinit := &PlatLimit{}
  194. switch limit.Plat {
  195. case "0": // resource android
  196. platlinit.Plat = model.PlatAndroid
  197. case "1": // resource iphone
  198. platlinit.Plat = model.PlatIPhone
  199. case "2": // resource pad
  200. platlinit.Plat = model.PlatIPad
  201. case "5": // resource iphone_i
  202. platlinit.Plat = model.PlatIPhoneI
  203. case "8": // resource android_i
  204. platlinit.Plat = model.PlatAndroidI
  205. }
  206. platlinit.Build, _ = strconv.Atoi(limit.Build)
  207. platlinit.Condition = limit.Condition
  208. platlinits = append(platlinits, platlinit)
  209. }
  210. }
  211. return
  212. }
  213. func (c *PopularCard) PopularCardToAiChange() (a *ai.Item) {
  214. a = &ai.Item{
  215. Goto: c.Type,
  216. ID: c.Value,
  217. RcmdReason: c.fromRcmdReason(),
  218. CornerMark: c.CornerMark,
  219. }
  220. if c.CornerMark == 2 {
  221. a.CornerMark = 4
  222. }
  223. return
  224. }
  225. func (c *PopularCard) fromRcmdReason() (a *ai.RcmdReason) {
  226. var content string
  227. switch c.ReasonType {
  228. case 0:
  229. content = ""
  230. case 1:
  231. content = "编辑精选"
  232. case 2:
  233. content = "热门推荐"
  234. case 3:
  235. content = c.Reason
  236. }
  237. if content != "" {
  238. a = &ai.RcmdReason{ID: 1, Content: content, BgColor: "yellow", IconLocation: "left_top"}
  239. }
  240. return
  241. }