const.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. package income
  2. import (
  3. "time"
  4. )
  5. var (
  6. _layout = "2006-01-02"
  7. _layoutMonth = "2006-01"
  8. )
  9. const (
  10. _upIncome = "up_income"
  11. _upIncomeWeekly = "up_income_weekly"
  12. _upIncomeMonthly = "up_income_monthly"
  13. _avDailyStatis = "av_income_daily_statis"
  14. _avWeeklyStatis = "av_income_weekly_statis"
  15. _avMonthlyStatis = "av_income_monthly_statis"
  16. _cmDailyStatis = "column_income_daily_statis"
  17. _cmWeeklyStatis = "column_income_weekly_statis"
  18. _cmMonthlyStatis = "column_income_monthly_statis"
  19. _bgmDailyStatis = "bgm_income_daily_statis"
  20. _bgmWeeklyStatis = "bgm_income_weekly_statis"
  21. _bgmMonthlyStatis = "bgm_income_monthly_statis"
  22. _avChargeDailyStatis = "av_charge_daily_statis"
  23. _avChargeWeeklyStatis = "av_charge_weekly_statis"
  24. _avChargeMonthlyStatis = "av_charge_monthly_statis"
  25. _cmChargeDailyStatis = "column_charge_daily_statis"
  26. _cmChargeWeeklyStatis = "column_charge_weekly_statis"
  27. _cmChargeMonthlyStatis = "column_charge_monthly_statis"
  28. _bgmChargeDailyStatis = "bgm_charge_daily_statis"
  29. _bgmChargeWeeklyStatis = "bgm_charge_weekly_statis"
  30. _bgmChargeMonthlyStatis = "bgm_charge_monthly_statis"
  31. _upIncomeDailyStatis = "up_income_daily_statis"
  32. _upAvDailyStatis = "up_av_daily_statis"
  33. _upColumnDailyStatis = "up_column_daily_statis"
  34. _upBgmDailyStatis = "up_bgm_daily_statis"
  35. _groupDay = 1
  36. _groupWeek = 2
  37. _groupMonth = 3
  38. _video = 0
  39. // _audio = 1
  40. _column = 2
  41. _bgm = 3
  42. _up = 4
  43. _lottery = 5 // 动态抽奖
  44. _leastAvIncome = 30000
  45. // add blacklist reason
  46. _avBlack = 1
  47. _avBreach = 2
  48. )
  49. func getUpInfoTable(typ int) (table string) {
  50. switch typ {
  51. case _video:
  52. table = "up_info_video"
  53. case _column:
  54. table = "up_info_column"
  55. case _bgm:
  56. table = "up_info_bgm"
  57. }
  58. return
  59. }
  60. func getUpInfoByType(typ int) (table string, incomeType string) {
  61. switch typ {
  62. case _video:
  63. table, incomeType = _upAvDailyStatis, "av_income"
  64. case _column:
  65. table, incomeType = _upColumnDailyStatis, "column_income"
  66. case _bgm:
  67. table, incomeType = _upBgmDailyStatis, "bgm_income"
  68. case _up:
  69. table, incomeType = _upIncomeDailyStatis, "income"
  70. }
  71. return
  72. }
  73. func getUpFieldByType(typ int) (field string) {
  74. switch typ {
  75. case _video:
  76. field = "av_income,av_tax,av_base_income,av_total_income"
  77. case _column:
  78. field = "column_income,column_tax,column_base_income,column_total_income"
  79. case _bgm:
  80. field = "bgm_income,bgm_tax,bgm_base_income,bgm_total_income"
  81. case _up:
  82. field = "income,tax_money,base_income,total_income"
  83. }
  84. return
  85. }
  86. func setUpTableByGroup(groupType int) string {
  87. table := _upIncome
  88. if groupType == _groupWeek {
  89. table = _upIncomeWeekly
  90. } else if groupType == _groupMonth {
  91. table = _upIncomeMonthly
  92. }
  93. return table
  94. }
  95. func setArchiveTableByGroup(typ, groupType int) string {
  96. table := ""
  97. switch typ {
  98. case _video:
  99. table = _avDailyStatis
  100. if groupType == _groupWeek {
  101. table = _avWeeklyStatis
  102. } else if groupType == _groupMonth {
  103. table = _avMonthlyStatis
  104. }
  105. case _column:
  106. table = _cmDailyStatis
  107. if groupType == _groupWeek {
  108. table = _cmWeeklyStatis
  109. } else if groupType == _groupMonth {
  110. table = _cmMonthlyStatis
  111. }
  112. case _bgm:
  113. table = _bgmDailyStatis
  114. if groupType == _groupWeek {
  115. table = _bgmWeeklyStatis
  116. } else if groupType == _groupMonth {
  117. table = _bgmMonthlyStatis
  118. }
  119. }
  120. return table
  121. }
  122. func setChargeTableByGroup(typ, groupType int) string {
  123. table := ""
  124. switch typ {
  125. case _video:
  126. table = _avChargeDailyStatis
  127. if groupType == _groupWeek {
  128. table = _avChargeWeeklyStatis
  129. } else if groupType == _groupMonth {
  130. table = _avChargeMonthlyStatis
  131. }
  132. case _column:
  133. table = _cmChargeDailyStatis
  134. if groupType == _groupWeek {
  135. table = _cmChargeWeeklyStatis
  136. } else if groupType == _groupMonth {
  137. table = _cmChargeMonthlyStatis
  138. }
  139. case _bgm:
  140. table = _bgmChargeDailyStatis
  141. if groupType == _groupWeek {
  142. table = _bgmChargeWeeklyStatis
  143. } else if groupType == _groupMonth {
  144. table = _bgmChargeMonthlyStatis
  145. }
  146. }
  147. return table
  148. }
  149. func getDateByGroup(groupType int, date time.Time) time.Time {
  150. if groupType == _groupWeek {
  151. return getStartWeekDate(date)
  152. } else if groupType == _groupMonth {
  153. return getStartMonthDate(date)
  154. }
  155. return date
  156. }
  157. func addDayByGroup(groupType int, date time.Time) time.Time {
  158. if groupType == _groupWeek {
  159. return date.AddDate(0, 0, 7)
  160. } else if groupType == _groupMonth {
  161. return date.AddDate(0, 1, 0)
  162. }
  163. return date.AddDate(0, 0, 1)
  164. }
  165. func getStartWeekDate(date time.Time) time.Time {
  166. for date.Weekday() != time.Monday {
  167. date = date.AddDate(0, 0, -1)
  168. }
  169. return date
  170. }
  171. func getStartMonthDate(date time.Time) time.Time {
  172. return time.Date(date.Year(), date.Month(), 1, 0, 0, 0, 0, time.Local)
  173. }
  174. func fromYuanToFen(d int64) float64 {
  175. return float64(d) / float64(100)
  176. }