requestargs.go 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. package upcrmmodel
  2. import (
  3. "go-common/app/admin/main/up/model/datamodel"
  4. "go-common/app/admin/main/up/util"
  5. "go-common/library/time"
  6. xtime "time"
  7. )
  8. const (
  9. //CompareTypeNothing 0
  10. CompareTypeNothing = 0
  11. //CompareType7day 1
  12. CompareType7day = 1
  13. //CompareType30day 2
  14. CompareType30day = 2
  15. //CompareTypeMonthFirstDay 3
  16. CompareTypeMonthFirstDay = 3
  17. )
  18. const (
  19. //AttrBitVideo video
  20. // see http://info.bilibili.co/pages/viewpage.action?pageId=9830931
  21. AttrBitVideo = 0
  22. //AttrBitAudio audio
  23. AttrBitAudio = 1
  24. //AttrBitArticle article
  25. AttrBitArticle = 2
  26. //AttrBitPhoto photo
  27. AttrBitPhoto = 3
  28. //AttrBitSign sign
  29. AttrBitSign = 4
  30. //AttrBitGrowup growup
  31. AttrBitGrowup = 5
  32. //AttrBitVerify verify
  33. AttrBitVerify = 6
  34. )
  35. var (
  36. //AttrGroup1 筛选用第一组attr
  37. AttrGroup1 = map[int]int{AttrBitVideo: 0, AttrBitAudio: 0, AttrBitArticle: 0, AttrBitPhoto: 0}
  38. //AttrGroup2 筛选用第二组attr, 两组之间的关系是与
  39. AttrGroup2 = map[int]int{AttrBitSign: 0, AttrBitGrowup: 0, AttrBitVerify: 0}
  40. )
  41. // ScoreQueryArgs ------------------------- requests ------------------------
  42. type ScoreQueryArgs struct {
  43. ScoreType int `form:"score_type"`
  44. CompareType int `form:"compare_type"`
  45. Export string `form:"export"`
  46. }
  47. //ScoreQueryUpArgs arg
  48. type ScoreQueryUpArgs struct {
  49. Mid int64 `form:"mid" validate:"required"`
  50. Date string `form:"date"`
  51. }
  52. //ScoreQueryUpHistoryArgs arg
  53. type ScoreQueryUpHistoryArgs struct {
  54. Mid int64 `form:"mid" validate:"required"`
  55. ScoreType int `form:"score_type"`
  56. Day int `form:"day" default:"7"`
  57. Date string `form:"date"`
  58. }
  59. //PlayQueryArgs arg
  60. type PlayQueryArgs struct {
  61. Mid int64 `form:"mid" validate:"required"`
  62. BusinessType int `form:"business_type"`
  63. }
  64. //InfoQueryArgs arg
  65. type InfoQueryArgs struct {
  66. Mid int64 `form:"mid" validate:"required"`
  67. }
  68. //CreditLogQueryArgs arg
  69. type CreditLogQueryArgs struct {
  70. Mid int64 `form:"mid" validate:"required"`
  71. Limit int `form:"limit"`
  72. }
  73. //UpRankQueryArgs arg
  74. type UpRankQueryArgs struct {
  75. Type int `form:"type" validate:"required"`
  76. Page int `form:"page"` // (从1开始)
  77. Size int `form:"size"` // 1 ~ 50
  78. }
  79. //InfoAccountInfoArgs arg
  80. type InfoAccountInfoArgs struct {
  81. Mids string `form:"mids" validate:"required"`
  82. }
  83. //InfoSearchArgs arg
  84. type InfoSearchArgs struct {
  85. AccountState int `json:"account_state"`
  86. Activity int `json:"activity"`
  87. Attrs UpAttr `json:"attrs"`
  88. FirstDateBegin string `json:"first_date_begin"`
  89. FirstDateEnd string `json:"first_date_end"`
  90. Mid int64 `json:"mid"`
  91. Order struct {
  92. Field string `json:"field"`
  93. Order string `json:"order"`
  94. }
  95. Page int `json:"page"`
  96. Size int `json:"size"`
  97. }
  98. //TestGetViewBaseArgs test arg
  99. type TestGetViewBaseArgs struct {
  100. Mid int64 `form:"mid" validate:"required"`
  101. }
  102. // ------------------------- results ------------------------
  103. //ScoreSection struct
  104. type ScoreSection struct {
  105. Section int `json:"-"`
  106. Value int
  107. Percent int
  108. }
  109. //ScoreQueryResult result
  110. type ScoreQueryResult struct {
  111. CompareAxis []ScoreSection `json:"compareAxis"`
  112. XAxis []string `json:"xAxis"`
  113. YAxis []ScoreSection `json:"yAxis"`
  114. }
  115. //NewEmptyScoreQueryResult make new result
  116. func NewEmptyScoreQueryResult() ScoreQueryResult {
  117. return ScoreQueryResult{
  118. CompareAxis: []ScoreSection{},
  119. XAxis: []string{},
  120. YAxis: []ScoreSection{},
  121. }
  122. }
  123. //ScoreInfo struct
  124. type ScoreInfo struct {
  125. Current int `json:"current"`
  126. DiffLastDay int `json:"diff_last_day"`
  127. }
  128. //ScoreQueryUpResult result
  129. type ScoreQueryUpResult struct {
  130. PrScore ScoreInfo
  131. QualityScore ScoreInfo
  132. CreditScore ScoreInfo
  133. Date time.Time
  134. }
  135. //ScoreHistoryInfo struct
  136. type ScoreHistoryInfo struct {
  137. Type int `json:"type"`
  138. Score []int `json:"score"`
  139. Date []time.Time `json:"date"`
  140. }
  141. //ScoreQueryUpHistoryResult result
  142. type ScoreQueryUpHistoryResult struct {
  143. ScoreData []ScoreHistoryInfo `json:"score_data"`
  144. }
  145. //PlayInfo struct
  146. type PlayInfo struct {
  147. Type int `json:"type"`
  148. PlayCountAccumulate int64 `json:"play_count_accumulate"`
  149. PlayCountAvg int64 `json:"play_count_avg"`
  150. PlayCountAvg90Day int64 `json:"play_count_avg_90day"`
  151. }
  152. //PlayQueryResult result
  153. type PlayQueryResult struct {
  154. ArticleCount30Day int `json:"article_count_30day"`
  155. ArticleCountAccumulate int `json:"article_count_accumulate"`
  156. BusinessData []PlayInfo `json:"business_data"`
  157. }
  158. //CastUpPlayInfoToPlayInfo cast
  159. func CastUpPlayInfoToPlayInfo(info UpPlayInfo) (r PlayInfo) {
  160. r.Type = int(info.BusinessType)
  161. r.PlayCountAccumulate = info.PlayCountAccumulate
  162. r.PlayCountAvg = info.PlayCountAccumulate / info.ArticleCount
  163. r.PlayCountAvg90Day = info.PlayCount90Day / info.ArticleCount
  164. return
  165. }
  166. //UpAttr struct
  167. type UpAttr struct {
  168. AttrVerify int `json:"attr_verify"`
  169. AttrVideo int `json:"attr_video"`
  170. AttrAudio int `json:"attr_audio"`
  171. AttrArticle int `json:"attr_article"`
  172. AttrPhoto int `json:"attr_photo"`
  173. AttrSign int `json:"attr_sign"`
  174. AttrGrowup int `json:"attr_growup"`
  175. }
  176. //InfoQueryResult result
  177. type InfoQueryResult struct {
  178. ID uint32 `json:"-"`
  179. Mid int64 `json:"mid"`
  180. Name string `json:"name"`
  181. Sex int8 `json:"sex"`
  182. JoinTime time.Time `json:"join_time"`
  183. FirstUpTime time.Time `json:"first_up_time"`
  184. Level int16 `json:"level"`
  185. FansCount int `json:"fans_count"`
  186. AccountState int8 `json:"account_state"`
  187. Activity int `json:"activity"`
  188. ArticleCount30day int `json:"article_count_30day"`
  189. ArticleCountAccumulate int `json:"article_count_accumulate"`
  190. VerifyType int8 `json:"verify_type"`
  191. BusinessType int8 `json:"business_type"`
  192. CreditScore int `json:"credit_score"`
  193. PrScore int `json:"pr_score"`
  194. QualityScore int `json:"quality_score"`
  195. ActiveTid int64 `json:"active_tid"`
  196. ActiveSubtid int64 `json:"active_subtid"`
  197. Region string `json:"region"`
  198. Province string `json:"province"`
  199. Age int `json:"age"`
  200. Attr int `json:"-"`
  201. Attrs UpAttr `json:"attrs"`
  202. Birthday xtime.Time `json:"-"`
  203. }
  204. //CopyFromBaseInfo copy
  205. func (i *InfoQueryResult) CopyFromBaseInfo(info UpBaseInfo) {
  206. i.ID = info.ID
  207. i.Mid = info.Mid
  208. i.Name = info.Name
  209. i.Sex = info.Sex
  210. i.JoinTime = info.JoinTime
  211. i.FirstUpTime = info.FirstUpTime
  212. i.Level = info.Level
  213. i.FansCount = info.FansCount
  214. i.AccountState = info.AccountState
  215. i.ArticleCount30day = info.ArticleCount30day
  216. i.ArticleCountAccumulate = info.ArticleCountAccumulate
  217. i.VerifyType = info.VerifyType
  218. i.BusinessType = info.BusinessType
  219. i.CreditScore = info.CreditScore
  220. i.ActiveTid = info.ActiveTid
  221. i.Birthday = info.Birthday
  222. i.Region = info.ActiveCity
  223. i.Province = info.ActiveProvince
  224. i.Attr = info.Attr
  225. i.PrScore = info.PrScore
  226. i.QualityScore = info.QualityScore
  227. i.Activity = info.Activity
  228. }
  229. // CalculateAttr 根据attr来计算各个attr_xx的属性
  230. func (i *InfoQueryResult) CalculateAttr() {
  231. // todo 计算attr属性
  232. if util.IsBitSet(i.Attr, AttrBitVideo) {
  233. i.Attrs.AttrVideo = 1
  234. }
  235. if util.IsBitSet(i.Attr, AttrBitAudio) {
  236. i.Attrs.AttrAudio = 1
  237. }
  238. if util.IsBitSet(i.Attr, AttrBitArticle) {
  239. i.Attrs.AttrArticle = 1
  240. }
  241. if util.IsBitSet(i.Attr, AttrBitPhoto) {
  242. i.Attrs.AttrPhoto = 1
  243. }
  244. if util.IsBitSet(i.Attr, AttrBitSign) {
  245. i.Attrs.AttrSign = 1
  246. }
  247. if util.IsBitSet(i.Attr, AttrBitGrowup) {
  248. i.Attrs.AttrGrowup = 1
  249. }
  250. if util.IsBitSet(i.Attr, AttrBitVerify) {
  251. i.Attrs.AttrVerify = 1
  252. }
  253. if !i.Birthday.IsZero() {
  254. i.Age = int(xtime.Since(i.Birthday).Hours() / float64(24*365))
  255. if i.Age < 0 {
  256. i.Age = 0
  257. }
  258. }
  259. }
  260. //CreditLogInfo struct
  261. type CreditLogInfo struct {
  262. Time time.Time `json:"time"`
  263. Log string `json:"log"`
  264. }
  265. //CreditLogUpResult result
  266. type CreditLogUpResult struct {
  267. Logs []CreditLogInfo `json:"logs"`
  268. }
  269. //UpRankInfo struct
  270. type UpRankInfo struct {
  271. InfoQueryResult
  272. Rank int `json:"rank"`
  273. Value uint `json:"value"`
  274. Value2 int `json:"value_2"`
  275. CompleteTime time.Time `json:"complete_time"`
  276. RankType int16 `json:"-"`
  277. }
  278. //CopyFromUpRank copy
  279. func (u *UpRankInfo) CopyFromUpRank(upRank *UpRank) {
  280. u.Value = upRank.Value
  281. u.Value2 = upRank.Value2
  282. u.RankType = upRank.Type
  283. }
  284. //UpRankQueryResult result
  285. type UpRankQueryResult struct {
  286. Result []*UpRankInfo `json:"result"`
  287. Date time.Time `json:"date"`
  288. PageInfo
  289. }
  290. //PageInfo page info
  291. type PageInfo struct {
  292. TotalCount int `json:"total_count"`
  293. Size int `json:"size"`
  294. Page int `json:"page"`
  295. }
  296. //InfoSearchResult result
  297. type InfoSearchResult struct {
  298. Result []*InfoQueryResult `json:"result"`
  299. PageInfo
  300. }
  301. //UpInfoWithViewerData up data with view data
  302. type UpInfoWithViewerData struct {
  303. Mid int64 `json:"mid"`
  304. UpBaseInfo *InfoQueryResult `json:"up_base_info"`
  305. ViewerTrend *datamodel.ViewerTrendInfo `json:"viewer_trend"`
  306. ViewerArea *datamodel.ViewerAreaInfo `json:"viewer_area"`
  307. ViewerBase *datamodel.ViewerBaseInfo `json:"viewer_base"`
  308. UpPlayInfo *UpPlayInfo `json:"up_play_info"`
  309. }
  310. //UpInfoWithViewerResult info result
  311. type UpInfoWithViewerResult struct {
  312. Result []*UpInfoWithViewerData `json:"result"`
  313. PageInfo
  314. }
  315. // -------------
  316. const (
  317. // FlagUpBaseData up base info
  318. FlagUpBaseData = 1
  319. // FlagUpPlayData up play info
  320. FlagUpPlayData = 1 << 1
  321. // FlagViewData view base data flag
  322. FlagViewData = 1 << 2
  323. )
  324. //UpInfoWithViewerArg arg
  325. type UpInfoWithViewerArg struct {
  326. Mids string `form:"mids"`
  327. Sort string `form:"sort" default:"fans_count"`
  328. Order string `form:"order" default:"desc"`
  329. Page int `form:"page" default:"1"`
  330. Size int `form:"size" default:"20"`
  331. // 需要的信息
  332. Flag int `form:"flag" default:"0"`
  333. }