model.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package model
  2. import (
  3. "math/rand"
  4. "time"
  5. )
  6. const (
  7. // UploadTypeMid 上传文件内容为 mid
  8. UploadTypeMid = 1
  9. // UploadTypeToken 上传文件内容为 token
  10. UploadTypeToken = 2
  11. )
  12. // Page .
  13. type Page struct {
  14. Num int `json:"num"`
  15. Size int `json:"size"`
  16. Total int `json:"total"`
  17. }
  18. // Pager def.
  19. type Pager struct {
  20. Total int `json:"total"`
  21. Pn int `json:"page" form:"pn" validate:"min=1" default:"1"`
  22. Ps int `json:"pagesize" form:"ps" validate:"min=1" default:"20"`
  23. }
  24. // App .
  25. type App struct {
  26. ID int64 `json:"id" form:"id"`
  27. Name string `json:"name" form:"name" validate:"required"`
  28. PushLimitUser int `json:"push_limit_user" form:"push_limit_user"`
  29. Ctime time.Time `json:"ctime"`
  30. Mtime time.Time `json:"mtime"`
  31. Dtime int64 `json:"dtime"`
  32. Business []Business `json:"-"`
  33. Auths []Auth `json:"-"`
  34. }
  35. // Auth .
  36. type Auth struct {
  37. ID int64 `json:"id" form:"id"`
  38. AppID int64 `json:"app_id" form:"app_id"`
  39. PlatformID int `json:"platform_id" form:"platform_id"`
  40. Name string `json:"name" form:"name"`
  41. Key string `json:"key" form:"key"`
  42. Value string `json:"value" form:"value"`
  43. BundleID string `json:"bundle_id" form:"bundle_id"`
  44. Mtime time.Time `json:"mtime"`
  45. Ctime time.Time `json:"ctime"`
  46. Dtime int `json:"dtime"`
  47. }
  48. // Business .
  49. type Business struct {
  50. ID int64 `json:"id" form:"id"`
  51. Ctime time.Time `json:"ctime"`
  52. Mtime time.Time `json:"mtime"`
  53. Dtime int `json:"dtime"`
  54. AppID int64 `json:"app_id" form:"app_id"`
  55. Name string `json:"name" form:"name"`
  56. Desc string `json:"desc" gorm:"column:description" form:"desc"`
  57. Token string `json:"token"`
  58. Sound int `json:"sound" form:"sound"`
  59. Vibration int `json:"vibration" form:"vibration"`
  60. ReceiveSwitch int `json:"receive_switch" form:"receive_switch"`
  61. PushSwitch int `json:"push_switch" form:"push_switch"`
  62. AppName string `json:"app_name" gorm:"-"`
  63. SilentTime string `json:"silent_time" form:"silent_time"`
  64. PushLimitUser int `json:"push_limit_user" form:"push_limit_user"`
  65. Whitelist int `json:"whitelist" form:"whitelist"`
  66. }
  67. // TableName .
  68. func (b Business) TableName() string {
  69. return "push_business"
  70. }
  71. // Task .
  72. type Task struct {
  73. ID string `json:"id" form:"id"`
  74. Job string `json:"job" form:"job"`
  75. Type int `json:"type" form:"type"`
  76. AppID int64 `json:"app_id" form:"app_id"`
  77. PlatformID int `json:"platform_id"`
  78. BusinessID int64 `json:"business_id" form:"business_id"`
  79. Platform string `json:"platform"`
  80. Title string `json:"title" form:"title"`
  81. Summary string `json:"summary" form:"summary"`
  82. LinkType int `json:"link_type" form:"link_type"`
  83. LinkValue string `json:"link_value" form:"link_value"`
  84. Build string `json:"build" form:"build"`
  85. Sound int `json:"sound" form:"sound"`
  86. Vibration int `json:"vibration" form:"vibration"`
  87. MidFile string `json:"mid_file" form:"mid_file"`
  88. Progress string `json:"progress"`
  89. PushTime time.Time `json:"-"`
  90. ExpireTime time.Time `json:"-"`
  91. PassThrough int `json:"pass_through" form:"pass_through"`
  92. PushTimeUnix int64 `json:"push_time" form:"push_time" gorm:"-"`
  93. ExpireTimeUnix int64 `json:"expire_time" form:"expire_time" gorm:"-"`
  94. Status int `json:"status"`
  95. ImageURL string `json:"image_url" form:"image_url"`
  96. Group string `json:"group" form:"group"`
  97. Extra string `json:"extra"`
  98. Mtime time.Time `json:"mtime"`
  99. Ctime time.Time `json:"ctime"`
  100. Dtime int `json:"dtime"`
  101. }
  102. // RandomString gets random string by length.
  103. func RandomString(l int) string {
  104. bs := []byte("0123456789abcdefghijklmnopqrstuvwxyz")
  105. r := rand.New(rand.NewSource(time.Now().UnixNano()))
  106. var res []byte
  107. for i := 0; i < l; i++ {
  108. res = append(res, bs[r.Intn(len(bs))])
  109. }
  110. return string(res)
  111. }