subject.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. package model
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "go-common/library/ecode"
  6. "go-common/library/time"
  7. )
  8. const (
  9. // SubTypeArchive 稿件
  10. SubTypeArchive int32 = 1
  11. // SubTypeTopic 话题
  12. SubTypeTopic = 2
  13. // SubTypeDrawyoo 画站 NOTE Deprecated
  14. SubTypeDrawyoo = 3
  15. // SubTypeActivity 活动
  16. SubTypeActivity = 4
  17. // SubTypeLiveVideo 直播小视频
  18. SubTypeLiveVideo = 5
  19. // SubTypeForbiden 封禁信息
  20. SubTypeForbiden = 6
  21. // SubTypeNotice 公告信息
  22. SubTypeNotice = 7
  23. // SubTypeLiveAct 直播活动
  24. SubTypeLiveAct = 8
  25. // SubTypeActArc 活动稿件
  26. SubTypeActArc = 9
  27. // SubTypeLiveNotice 直播公告
  28. SubTypeLiveNotice = 10
  29. // SubTypeLivePicture 直播有文画
  30. SubTypeLivePicture = 11
  31. // SubTypeArticle 文章
  32. SubTypeArticle = 12
  33. // SubTypeTicket 票务
  34. SubTypeTicket = 13
  35. // SubTypeMusic 音乐
  36. SubTypeMusic = 14
  37. // SubTypeCredit 风纪委
  38. SubTypeCredit = 15
  39. // SubTypePgcCmt 点评
  40. SubTypePgcCmt = 16
  41. // SubTypeDynamic 动态
  42. SubTypeDynamic = 17
  43. // SubTypePlaylist 播单
  44. SubTypePlaylist = 18
  45. // SubTypeMusicList 音乐播单
  46. SubTypeMusicList = 19
  47. // SubTypeComicSeason 漫画部评论
  48. SubTypeComicSeason = 20
  49. // SubTypeComicEpisode 漫画话评论
  50. SubTypeComicEpisode = 21
  51. // SubStateNormal 正常
  52. SubStateNormal int32 = 0
  53. // SubStateForbid 关闭
  54. SubStateForbid = 1
  55. // SubStateMonitor 监控中 NOTE Deprecated to use attr 2
  56. SubStateMonitor = 2
  57. // SubAttrTopAdmin 管理员置顶
  58. SubAttrTopAdmin uint32 = 0
  59. // SubAttrTopUpper up主置顶
  60. SubAttrTopUpper = 1
  61. // SubAttrMonitor 监控中
  62. SubAttrMonitor = 2
  63. // SubAttrConfig 存在配置
  64. SubAttrConfig = 3
  65. // SubAttrAudit 先审后发
  66. SubAttrAudit = 4
  67. // SubAttrFrozen 冻结评论
  68. SubAttrFrozen = 5
  69. // SubAttrFolded 有折叠的根评论
  70. SubAttrFolded = 7
  71. // SujectAllow subject_allow
  72. SujectAllow = "subject_allow"
  73. // SujectForbid SujectForbid
  74. SujectForbid = "subject_forbid"
  75. // SujectFrozen SujectFrozen
  76. SujectFrozen = "subject_frozen"
  77. // SujectUnfrozenAllow SujectUnfrozenAllow
  78. SujectUnfrozenAllow = "subject_unfrozen_allow"
  79. // SujectUnfrozenForbid SujectUnfrozenForbid
  80. SujectUnfrozenForbid = "subject_unfrozen_forbid"
  81. )
  82. // Subject reply subject.
  83. type Subject struct {
  84. ID int64 `json:"-"`
  85. Oid int64 `json:"oid"`
  86. Type int32 `json:"type"`
  87. Mid int64 `json:"mid"`
  88. Count int32 `json:"count"`
  89. RCount int32 `json:"rcount"`
  90. ACount int32 `json:"acount"`
  91. State int32 `json:"state"`
  92. Attr uint32 `json:"attr"`
  93. CTime time.Time `json:"ctime"`
  94. MTime time.Time `json:"-"`
  95. Meta string `json:"meta"`
  96. }
  97. // HasFolded ...
  98. func (s *Subject) HasFolded() bool {
  99. return s.AttrVal(AttrFolded) == AttrYes
  100. }
  101. // MarkHasFolded ...
  102. func (s *Subject) MarkHasFolded() {
  103. s.AttrSet(AttrYes, AttrFolded)
  104. }
  105. // UnmarkHasFolded ...
  106. func (s *Subject) UnmarkHasFolded() {
  107. s.AttrSet(AttrNo, AttrFolded)
  108. }
  109. // SubjectMeta SubjectMeta
  110. type SubjectMeta struct {
  111. AdminTop int64 `json:"atop,omitempty"`
  112. UpperTop int64 `json:"utop,omitempty"`
  113. }
  114. // TopSet TopSet
  115. func (s *Subject) TopSet(top int64, typ uint, act uint32) (err error) {
  116. var meta SubjectMeta
  117. if s.Meta != "" {
  118. err = json.Unmarshal([]byte(s.Meta), &meta)
  119. if err != nil {
  120. return
  121. }
  122. }
  123. if act == 1 {
  124. if typ == 0 {
  125. if meta.AdminTop == top {
  126. return fmt.Errorf("subject already have the same top")
  127. }
  128. meta.AdminTop = top
  129. } else {
  130. if meta.UpperTop == top {
  131. return fmt.Errorf("subject already have the same top")
  132. }
  133. meta.UpperTop = top
  134. }
  135. } else {
  136. if typ == 0 {
  137. meta.AdminTop = 0
  138. } else {
  139. meta.UpperTop = 0
  140. }
  141. }
  142. var content []byte
  143. content, err = json.Marshal(meta)
  144. if err != nil {
  145. return err
  146. }
  147. s.Meta = string(content)
  148. return
  149. }
  150. // AttrVal return val of subject'attr.
  151. func (s *Subject) AttrVal(bit uint32) uint32 {
  152. return (s.Attr >> bit) & uint32(1)
  153. }
  154. // AttrSet set val of subject'attr.
  155. func (s *Subject) AttrSet(v uint32, bit uint32) {
  156. s.Attr = s.Attr&(^(1 << bit)) | (v << bit)
  157. }
  158. // CheckSubState check subject state is ok.
  159. func CheckSubState(state int32) (err error) {
  160. if state < SubStateNormal || state > SubStateForbid {
  161. err = ecode.ReplyIllegalSubState
  162. }
  163. return
  164. }
  165. // SubjectLog info
  166. type SubjectLog struct {
  167. AdminID int64 `json:"adminid"`
  168. AdminName string `json:"admin_name"`
  169. Oid string `json:"oid"`
  170. Type int32 `json:"type"`
  171. Remark string `json:"remark"`
  172. Action string `json:"action"`
  173. CTime string `json:"ctime"`
  174. State int32 `json:"state"`
  175. }
  176. // SubjectLogRes format
  177. type SubjectLogRes struct {
  178. Logs []*SubjectLog `json:"logs"`
  179. Page Page `json:"page"`
  180. Order string `json:"order"`
  181. Sort string `json:"sort"`
  182. }