av_charge_test.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. package income
  2. import (
  3. "bytes"
  4. "context"
  5. "strconv"
  6. "testing"
  7. "time"
  8. model "go-common/app/job/main/growup/model/income"
  9. //xtime "go-common/library/time"
  10. . "github.com/smartystreets/goconvey/convey"
  11. )
  12. func Test_AvDailyCharge(t *testing.T) {
  13. Convey("AvDailyCharge", t, func() {
  14. _, err := d.AvDailyCharge(context.Background(), time.Now(), 0, 2000)
  15. So(err, ShouldBeNil)
  16. })
  17. }
  18. func Test_AvWeeklyCharge(t *testing.T) {
  19. Convey("AvWeeklyCharge", t, func() {
  20. _, err := d.AvWeeklyCharge(context.Background(), time.Now(), 0, 2000)
  21. So(err, ShouldBeNil)
  22. })
  23. }
  24. func Test_AvMonthlyCharge(t *testing.T) {
  25. Convey("AvMonthlyCharge", t, func() {
  26. _, err := d.AvMonthlyCharge(context.Background(), time.Now(), 0, 2000)
  27. So(err, ShouldBeNil)
  28. })
  29. }
  30. func Test_InsertAvChargeTable(t *testing.T) {
  31. Convey("InsertAvChargeTable", t, func() {
  32. c := context.Background()
  33. d.db.Exec(c, "DELETE FROM av_weekly_charge where av_id = 11")
  34. avCharge := []*model.AvCharge{}
  35. value := &model.AvCharge{
  36. AvID: 11,
  37. MID: 11,
  38. TagID: 11,
  39. }
  40. avCharge = append(avCharge, value)
  41. vals := assembleAvCharge(avCharge)
  42. count, err := d.InsertAvChargeTable(c, vals, "av_weekly_charge")
  43. So(err, ShouldBeNil)
  44. So(count, ShouldEqual, 1)
  45. d.db.Exec(c, "DELETE FROM av_weekly_charge where av_id = 11")
  46. })
  47. }
  48. func assembleAvCharge(avCharge []*model.AvCharge) (vals string) {
  49. var buf bytes.Buffer
  50. for _, row := range avCharge {
  51. buf.WriteString("(")
  52. buf.WriteString(strconv.FormatInt(row.AvID, 10))
  53. buf.WriteByte(',')
  54. buf.WriteString(strconv.FormatInt(row.MID, 10))
  55. buf.WriteByte(',')
  56. buf.WriteString(strconv.FormatInt(row.TagID, 10))
  57. buf.WriteByte(',')
  58. buf.WriteString(strconv.Itoa(row.IsOriginal))
  59. buf.WriteByte(',')
  60. buf.WriteString(strconv.FormatInt(row.DanmakuCount, 10))
  61. buf.WriteByte(',')
  62. buf.WriteString(strconv.FormatInt(row.CommentCount, 10))
  63. buf.WriteByte(',')
  64. buf.WriteString(strconv.FormatInt(row.CollectCount, 10))
  65. buf.WriteByte(',')
  66. buf.WriteString(strconv.FormatInt(row.CoinCount, 10))
  67. buf.WriteByte(',')
  68. buf.WriteString(strconv.FormatInt(row.ShareCount, 10))
  69. buf.WriteByte(',')
  70. buf.WriteString(strconv.FormatInt(row.ElecPayCount, 10))
  71. buf.WriteByte(',')
  72. buf.WriteString(strconv.FormatInt(row.TotalPlayCount, 10))
  73. buf.WriteByte(',')
  74. buf.WriteString(strconv.FormatInt(row.WebPlayCount, 10))
  75. buf.WriteByte(',')
  76. buf.WriteString(strconv.FormatInt(row.AppPlayCount, 10))
  77. buf.WriteByte(',')
  78. buf.WriteString(strconv.FormatInt(row.H5PlayCount, 10))
  79. buf.WriteByte(',')
  80. buf.WriteString(strconv.FormatInt(row.LvUnknown, 10))
  81. buf.WriteByte(',')
  82. buf.WriteString(strconv.FormatInt(row.Lv0, 10))
  83. buf.WriteByte(',')
  84. buf.WriteString(strconv.FormatInt(row.Lv1, 10))
  85. buf.WriteByte(',')
  86. buf.WriteString(strconv.FormatInt(row.Lv2, 10))
  87. buf.WriteByte(',')
  88. buf.WriteString(strconv.FormatInt(row.Lv3, 10))
  89. buf.WriteByte(',')
  90. buf.WriteString(strconv.FormatInt(row.Lv4, 10))
  91. buf.WriteByte(',')
  92. buf.WriteString(strconv.FormatInt(row.Lv5, 10))
  93. buf.WriteByte(',')
  94. buf.WriteString(strconv.FormatInt(row.Lv6, 10))
  95. buf.WriteByte(',')
  96. buf.WriteString(strconv.FormatInt(row.VScore, 10))
  97. buf.WriteByte(',')
  98. buf.WriteString(strconv.FormatInt(row.IncCharge, 10))
  99. buf.WriteByte(',')
  100. buf.WriteString(strconv.FormatInt(row.TotalCharge, 10))
  101. buf.WriteByte(',')
  102. buf.WriteByte('\'')
  103. buf.WriteString(row.Date.Time().Format(_layout))
  104. buf.WriteByte('\'')
  105. buf.WriteByte(',')
  106. buf.WriteByte('\'')
  107. buf.WriteString(row.UploadTime.Time().Format(_layout))
  108. buf.WriteByte('\'')
  109. buf.WriteString(")")
  110. buf.WriteByte(',')
  111. }
  112. if buf.Len() > 0 {
  113. buf.Truncate(buf.Len() - 1)
  114. }
  115. vals = buf.String()
  116. buf.Reset()
  117. return
  118. }