season_repo.go 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. package model
  2. import (
  3. "net/url"
  4. "reflect"
  5. "strconv"
  6. "go-common/library/time"
  7. "github.com/siddontang/go-mysql/mysql"
  8. )
  9. // TVEpContent reprensents the content table
  10. type TVEpContent struct {
  11. ID int64 `form:"id" params:"id" validate:"required"`
  12. CID int `form:"cid" params:"cid" gorm:"column:cid" validate:"required"`
  13. SeasonID int64 `form:"season_id" params:"season_id" validate:"required"`
  14. Title string `form:"title" params:"title"`
  15. LongTitle string `form:"long_title" params:"long_title"`
  16. Cover string `form:"cover" params:"cover"`
  17. Length int32 `form:"length" params:"length"`
  18. Order int `form:"order" params:"order" validate:"required"`
  19. PayStatus int `form:"pay_status" validate:"required" gorm:"-"`
  20. Desc string `form:"desc" gorm:"-"`
  21. IsDeleted int8
  22. Ctime time.Time
  23. Mtime time.Time
  24. }
  25. // TVEpSeason represents the season table
  26. type TVEpSeason struct {
  27. ID int64 `form:"id" json:"id" params:"id" validate:"required" gorm:"column:id"`
  28. OriginName string `form:"origin_name" json:"origin_name" params:"origin_name" validate:"required"`
  29. Title string `form:"title" json:"title" params:"title"`
  30. Alias string `form:"alias" json:"alias" params:"alias"`
  31. Category int `form:"category" json:"category" params:"category" validate:"required" gorm:"column:category"`
  32. Desc string `form:"desc" json:"desc" params:"desc"`
  33. Style string `form:"style" json:"style" params:"style"`
  34. Area string `form:"area" json:"area" params:"area"`
  35. PlayTime time.Time `form:"play_time" json:"play_time" params:"play_time" validate:"required"`
  36. Info int `form:"info" json:"info" params:"info" validate:"required"`
  37. State string `form:"state" json:"state" validate:"required" params:"state"`
  38. TotalNum string `form:"total_num" json:"total_num" params:"total_num" validate:"required"`
  39. Upinfo string `form:"upinfo" json:"upinfo" params:"upinfo"`
  40. Staff string `form:"staff" json:"staff" params:"staff"`
  41. Role string `form:"role" json:"role" params:"role"`
  42. Copyright string `form:"copyright" json:"copyright" params:"copyright"`
  43. Cover string `form:"cover" json:"cover" params:"cover" gorm:"column:cover"`
  44. Check int `json:"check"`
  45. IsDeleted int `json:"is_deleted"`
  46. AuditTime int `json:"audit_time"`
  47. Valid int `json:"valid"`
  48. Reason string `json:"reason"`
  49. Version string `json:"version" form:"version"` // v1.13 new fields, movie, OVA or normal
  50. Producer string `json:"producer" form:"producer"` // v1.13 new fields, BBC, CCTV etc
  51. AliasSearch string `json:"alias_search" form:"alias_search"`
  52. Brief string `json:"brief" form:"brief"`
  53. Status string `json:"status" form:"status"`
  54. }
  55. // SeaRepoCore def.
  56. type SeaRepoCore struct {
  57. ID int64 `json:"id" params:"id"`
  58. OriginName string `json:"origin_name" params:"origin_name"`
  59. Title string `json:"title" params:"title"`
  60. Alias string `json:"alias" params:"alias"`
  61. Category int8 `json:"category" params:"category"`
  62. Desc string `json:"desc" params:"desc"`
  63. Style string `json:"style" params:"style"`
  64. Area string `json:"area" params:"area"`
  65. Info int8 `json:"info" params:"info"`
  66. State int8 `json:"state" params:"state"`
  67. TotalNum int32 `json:"total_num" params:"total_num"`
  68. Upinfo string `json:"upinfo" params:"upinfo"`
  69. Staff string `json:"staff" params:"staff"`
  70. Role string `json:"role" params:"role"`
  71. Copyright string `json:"copyright" params:"copyright"`
  72. Cover string `json:"cover" params:"cover" gorm:"column:cover"`
  73. Check int8 `json:"check"`
  74. IsDeleted int8 `json:"is_deleted"`
  75. AuditTime int `json:"audit_time"`
  76. Ctime time.Time `json:"ctime"`
  77. Valid int8 `json:"valid"`
  78. InjectTime time.Time `json:"inject_time"`
  79. Reason string `json:"reason"`
  80. }
  81. // SeaRepoDB def.
  82. type SeaRepoDB struct {
  83. SeaRepoCore
  84. PlayTime time.Time `gorm:"column:play_time"`
  85. Mtime time.Time `json:"mtime"`
  86. }
  87. // SeaRepoList def.
  88. type SeaRepoList struct {
  89. SeaRepoCore
  90. Mtime string `json:"mtime"`
  91. Pubdate string `json:"pubdate"`
  92. }
  93. // ToList transforms a SeaRepoDB to list, time transformation
  94. func (v *SeaRepoDB) ToList() (list *SeaRepoList) {
  95. list = &SeaRepoList{
  96. SeaRepoCore: v.SeaRepoCore,
  97. }
  98. list.Mtime = v.Mtime.Time().Format(mysql.TimeFormat)
  99. list.Pubdate = v.PlayTime.Time().Format(mysql.TimeFormat)
  100. return
  101. }
  102. // TableName gives the table name of content
  103. func (*TVEpContent) TableName() string {
  104. return "tv_ep_content"
  105. }
  106. // TableName gives the table name of season
  107. func (*TVEpSeason) TableName() string {
  108. return "tv_ep_season"
  109. }
  110. // TableName gives the table name of season
  111. func (v *SeaRepoDB) TableName() string {
  112. return "tv_ep_season"
  113. }
  114. // SeasonRepoPager def.
  115. type SeasonRepoPager struct {
  116. TotalCount int64 `json:"total_count"`
  117. Pn int `json:"pn"`
  118. Ps int `json:"ps"`
  119. Items []*SeaRepoList `json:"items"`
  120. }
  121. // Updated picks value from request and compare with the struct to analyse the difference
  122. func (sn TVEpSeason) Updated(req url.Values) (fields map[string]interface{}) {
  123. var (
  124. vl = reflect.ValueOf(sn)
  125. tp = reflect.TypeOf(sn)
  126. )
  127. fields = make(map[string]interface{})
  128. for i := 0; i < vl.NumField(); i++ {
  129. var (
  130. t = tp.Field(i)
  131. v = vl.Field(i)
  132. name = t.Tag.Get("json")
  133. )
  134. if reqV := req.Get(name); reqV != "" {
  135. if kind := t.Type.Kind(); kind == reflect.Int || kind == reflect.Int64 {
  136. if v.Int() != atoi(reqV) {
  137. fields[name] = atoi(reqV)
  138. }
  139. } else {
  140. if v.String() != reqV {
  141. fields[name] = reqV
  142. }
  143. }
  144. }
  145. }
  146. return
  147. }
  148. // ToContent transforms an ep to content object
  149. func (epc *TVEpContent) ToContent(isInit bool) (res *Content) {
  150. res = &Content{
  151. Title: epc.LongTitle,
  152. Subtitle: epc.Title,
  153. Desc: epc.Desc,
  154. Cover: epc.Cover,
  155. SeasonID: int(epc.SeasonID),
  156. CID: epc.CID,
  157. EPID: int(epc.ID),
  158. PayStatus: epc.PayStatus,
  159. }
  160. if isInit {
  161. res.State = 1
  162. }
  163. return
  164. }
  165. func atoi(value string) (intval int64) {
  166. intval, err := strconv.ParseInt(value, 10, 64)
  167. if err != nil {
  168. intval = 0
  169. }
  170. return intval
  171. }