question.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. package model
  2. import "time"
  3. // check info.
  4. const (
  5. WaitCheck = int8(0)
  6. PassCheck = int8(1)
  7. NoPassCheck = int8(2)
  8. )
  9. // count.
  10. const (
  11. ArgsCount = 6
  12. MaxCount = 1000
  13. FileMaxSize = 2 * (1024 * 1024) // FileMaxSize max 2M
  14. )
  15. // Medal info
  16. const (
  17. PassNum50 = 50
  18. PassNum100 = 100
  19. PassNum200 = 200
  20. Nid53 = 53
  21. Nid54 = 54
  22. Nid55 = 55
  23. StageDisable int8 = 2
  24. )
  25. // size
  26. const (
  27. MaxQuestion = 120
  28. MinQuestion = 6
  29. MaxAns = 100
  30. MinAns = 2
  31. MaxTips = 100
  32. MinTips = 2
  33. MaxLoadQueSize = 100000
  34. )
  35. // media type
  36. const (
  37. TextMediaType = int8(1)
  38. ImageMediaType = int8(2)
  39. )
  40. //QuestionPage admin page
  41. type QuestionPage struct {
  42. Total int64 `json:"total"`
  43. Items []*QuestionDB `json:"items"`
  44. }
  45. //HistoryPage .
  46. type HistoryPage struct {
  47. Total int64 `json:"total"`
  48. Items []*AnswerHistoryDB `json:"items"`
  49. }
  50. // QuestionDB question info.
  51. type QuestionDB struct {
  52. ID int64 `gorm:"column:id" json:"id" form:"id" validate:"required"`
  53. Mid int64 `gorm:"column:mid" json:"mid"`
  54. IP string `gorm:"column:ip" json:"ip"`
  55. TypeID int8 `gorm:"column:type_id" json:"type_id"`
  56. Question string `gorm:"column:question" json:"question" form:"question" validate:"required"`
  57. Ans1 string `gorm:"column:ans1" json:"ans1" form:"ans1" validate:"required"`
  58. Ans2 string `gorm:"column:ans2" json:"ans2" form:"ans2" validate:"required"`
  59. Ans3 string `gorm:"column:ans3" json:"ans3" form:"ans3" validate:"required"`
  60. Ans4 string `gorm:"column:ans4" json:"ans4" form:"ans4" validate:"required"`
  61. State int8 `gorm:"column:state" json:"state"`
  62. Tips string `gorm:"column:tips" json:"tips"`
  63. AvID int32 `gorm:"column:avid" json:"avid"`
  64. MediaType int8 `gorm:"column:media_type" json:"media_type"`
  65. Source int8 `gorm:"column:source" json:"source"`
  66. Ctime time.Time `gorm:"column:ctime" json:"ctime"`
  67. Mtime time.Time `gorm:"column:mtime" json:"mtime"`
  68. Operator string `gorm:"column:operator" json:"operator"`
  69. }
  70. // TableName for gorm.
  71. func (b QuestionDB) TableName() string {
  72. return "ans_v3_question"
  73. }
  74. // Question question info.
  75. type Question struct {
  76. *QuestionDB
  77. Ans []string
  78. }
  79. // ArgQue admin question query param.
  80. type ArgQue struct {
  81. Question string `form:"question"`
  82. TypeID int8 `form:"type_id"`
  83. State int8 `form:"state" default:"-1"`
  84. Ps int `form:"ps" default:"20"`
  85. Pn int `form:"pn" default:"1"`
  86. }
  87. // ArgHistory .
  88. type ArgHistory struct {
  89. Mid int64 `form:"mid" validate:"required"`
  90. Ps int `form:"ps" default:"20"`
  91. Pn int `form:"pn" default:"1"`
  92. }
  93. // Sizer .
  94. type Sizer interface {
  95. Size() int64
  96. }
  97. // AnswerHistory info.
  98. type AnswerHistory struct {
  99. ID int64 `json:"id"`
  100. Hid int64 `json:"hid"`
  101. Mid int64 `json:"mid"`
  102. StartTime time.Time `json:"start_time"`
  103. StepOneErrTimes int8 `json:"step_one_err_times"`
  104. StepOneCompleteTime int64 `json:"step_one_complete_time"`
  105. StepExtraStartTime time.Time `json:"step_extra_start_time"`
  106. StepExtraCompleteTime int64 `json:"step_extra_complete_time"`
  107. StepExtraScore int64 `json:"step_extra_score"`
  108. StepTwoStartTime time.Time `json:"step_two_start_time"`
  109. CompleteTime time.Time `json:"complete_time"`
  110. CompleteResult string `json:"complete_result"`
  111. Score int8 `json:"score"`
  112. IsFirstPass int8 `json:"is_first_pass"`
  113. IsPassCaptcha int8 `json:"is_pass_captcha"`
  114. PassedLevel int8 `json:"passed_level"`
  115. RankID int `json:"rank_id"`
  116. Ctime time.Time `json:"ctime"`
  117. Mtime time.Time `json:"mtime"`
  118. }
  119. //List .
  120. type List struct {
  121. Total int `json:"total"`
  122. Items []*AnswerHistory `json:"items"`
  123. }
  124. // Histories history sorted.
  125. type Histories []*AnswerHistory
  126. func (h Histories) Len() int { return len(h) }
  127. func (h Histories) Less(i, j int) bool {
  128. return h[i].Ctime.Unix() > h[j].Ctime.Unix()
  129. }
  130. func (h Histories) Swap(i, j int) { h[i], h[j] = h[j], h[i] }