format.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. package service
  2. import (
  3. "bytes"
  4. "encoding/csv"
  5. "strconv"
  6. "time"
  7. "go-common/app/admin/main/growup/model"
  8. )
  9. var (
  10. _accountState = map[int]string{
  11. 1: "未申请",
  12. 2: "待审核",
  13. 3: "已签约",
  14. 4: "已驳回",
  15. 5: "主动退出",
  16. 6: "被动退出",
  17. 7: "封禁",
  18. }
  19. _avCategory = map[int]string{
  20. 0: "默认",
  21. 1: "动画",
  22. 3: "音乐",
  23. 129: "舞蹈",
  24. 4: "游戏",
  25. 36: "科技",
  26. 160: "生活",
  27. 119: "鬼畜",
  28. 155: "时尚",
  29. 23: "电影",
  30. 11: "电视剧",
  31. 13: "番剧",
  32. 167: "国创",
  33. 165: "广告",
  34. 5: "娱乐",
  35. 177: "纪录片",
  36. 181: "影视",
  37. }
  38. _cmCategory = map[int]string{
  39. 1: "游戏",
  40. 2: "动画",
  41. 3: "生活",
  42. 16: "轻小说",
  43. 28: "影视",
  44. 29: "兴趣",
  45. }
  46. )
  47. // FormatCSV format to csv data
  48. func FormatCSV(records [][]string) (data []byte, err error) {
  49. buf := new(bytes.Buffer)
  50. // add utf bom
  51. if len(records) > 0 {
  52. buf.WriteString("\xEF\xBB\xBF")
  53. }
  54. w := csv.NewWriter(buf)
  55. err = w.WriteAll(records)
  56. if err != nil {
  57. return
  58. }
  59. data = buf.Bytes()
  60. return
  61. }
  62. func formatBlacklist(blacklist []*model.Blacklist) (data [][]string) {
  63. if len(blacklist) <= 0 {
  64. return
  65. }
  66. data = make([][]string, len(blacklist)+1)
  67. data[0] = []string{"稿件id", "加入时间", "加入原因", "累计收入", "UP主UID", "UP主昵称", "业务类型"}
  68. for i := 0; i < len(blacklist); i++ {
  69. list := blacklist[i]
  70. var ctype, reasonStr string
  71. switch list.CType {
  72. case 0:
  73. ctype = "视频"
  74. case 1:
  75. ctype = "音频"
  76. case 2:
  77. ctype = "专栏"
  78. }
  79. switch list.Reason {
  80. case 1:
  81. reasonStr = "停止收入"
  82. case 2:
  83. reasonStr = "违规扣除"
  84. case 3:
  85. reasonStr = "私单"
  86. case 4:
  87. reasonStr = "绿洲商单"
  88. }
  89. data[i+1] = []string{
  90. strconv.FormatInt(list.AvID, 10),
  91. time.Unix(int64(list.CTime), 0).Format("2006-01-02 15:04:05"),
  92. reasonStr,
  93. strconv.FormatFloat(float64(list.Income)*0.01, 'f', 3, 64),
  94. strconv.FormatInt(list.MID, 10),
  95. list.Nickname,
  96. ctype,
  97. }
  98. }
  99. return
  100. }
  101. func formatUpInfo(ups []*model.UpInfo, states []int64, typ int) (data [][]string) {
  102. if len(ups) <= 0 {
  103. return
  104. }
  105. data = make([][]string, len(ups)+1)
  106. switch typ {
  107. case _video:
  108. data[0] = []string{"UID", "昵称", "原创稿件数", "稿件播放量", "稿件量", "分区", "粉丝数"}
  109. case _column:
  110. data[0] = []string{"UID", "昵称", "稿件数", "阅读量", "分区", "粉丝数"}
  111. case _bgm:
  112. data[0] = []string{"UID", "昵称", "素材量", "视频播放量", "素材使用量", "粉丝数"}
  113. }
  114. if len(states) == 0 {
  115. data[0] = append(data[0], "账号状态")
  116. } else {
  117. switch states[0] {
  118. case 2:
  119. data[0] = append(data[0], "申请时间")
  120. case 3:
  121. data[0] = append(data[0], "申请时间")
  122. data[0] = append(data[0], "签约时间")
  123. case 4:
  124. data[0] = append(data[0], "驳回时间")
  125. data[0] = append(data[0], "到期时间")
  126. case 5:
  127. data[0] = append(data[0], "退出时间")
  128. data[0] = append(data[0], "到期时间")
  129. case 6:
  130. data[0] = append(data[0], "退出时间")
  131. case 7:
  132. data[0] = append(data[0], "封禁时间")
  133. data[0] = append(data[0], "恢复时间")
  134. }
  135. }
  136. for i := 1; i <= len(ups); i++ {
  137. up := ups[i-1]
  138. data[i] = []string{
  139. strconv.FormatInt(up.MID, 10),
  140. up.Nickname,
  141. }
  142. switch typ {
  143. case _video:
  144. data[i] = append(data[i], strconv.Itoa(up.OriginalArchiveCount))
  145. data[i] = append(data[i], strconv.Itoa(up.TotalPlayCount))
  146. data[i] = append(data[i], strconv.Itoa(up.Avs))
  147. data[i] = append(data[i], _avCategory[up.MainCategory])
  148. case _column:
  149. data[i] = append(data[i], strconv.Itoa(up.ArticleCount))
  150. data[i] = append(data[i], strconv.Itoa(up.TotalViewCount))
  151. data[i] = append(data[i], _cmCategory[up.MainCategory])
  152. case _bgm:
  153. data[i] = append(data[i], strconv.Itoa(up.BGMs))
  154. data[i] = append(data[i], strconv.Itoa(up.BgmPlayCount))
  155. data[i] = append(data[i], strconv.Itoa(up.BgmApplyCount))
  156. }
  157. data[i] = append(data[i], strconv.Itoa(up.Fans))
  158. if len(states) == 0 {
  159. data[i] = append(data[i], _accountState[up.AccountState])
  160. } else {
  161. switch states[0] {
  162. case 2:
  163. data[i] = append(data[i], up.ApplyAt.Time().Format("2006-01-02"))
  164. case 3:
  165. data[i] = append(data[i], up.ApplyAt.Time().Format("2006-01-02"))
  166. data[i] = append(data[i], up.SignedAt.Time().Format("2006-01-02"))
  167. case 4:
  168. data[i] = append(data[i], up.RejectAt.Time().Format("2006-01-02"))
  169. data[i] = append(data[i], up.ExpiredIn.Time().Format("2006-01-02"))
  170. case 5:
  171. data[i] = append(data[i], up.QuitAt.Time().Format("2006-01-02"))
  172. data[i] = append(data[i], up.ExpiredIn.Time().Format("2006-01-02"))
  173. case 6:
  174. data[i] = append(data[i], up.DismissAt.Time().Format("2006-01-02"))
  175. case 7:
  176. data[i] = append(data[i], up.ForbidAt.Time().Format("2006-01-02"))
  177. data[i] = append(data[i], up.ExpiredIn.Time().Format("2006-01-02"))
  178. }
  179. }
  180. }
  181. return
  182. }