creditlog.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package upcrmmodel
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "go-common/library/time"
  6. systime "time"
  7. )
  8. const (
  9. //BusinessTypeArticleAudit 1
  10. BusinessTypeArticleAudit = 1
  11. )
  12. const (
  13. //DateStr date format
  14. DateStr = "2006-01-02"
  15. //CreditLogTableCount all credit log table count
  16. CreditLogTableCount = 100
  17. )
  18. //ArgCreditLogAdd arg
  19. type ArgCreditLogAdd struct {
  20. Type int `form:"type" json:"type"` // 日志类型,具体与业务方确定
  21. OpType int `form:"op_type" json:"optype"` // 操作类型,具体与业务方确定
  22. Reason int `form:"reason" json:"reason"` // 原因类型,具体与业务方确定
  23. BusinessType int `form:"bussiness_type" json:"business_type"` // 业务类型
  24. Mid int64 `form:"mid" validate:"required" json:"mid"` // 用户id
  25. Oid int64 `form:"oid" json:"oid"` // 对象类型,如aid
  26. UID int `form:"uid" json:"uid"` // 管理员id
  27. Content string `form:"content" json:"content"` // 日志内容描述
  28. CTime time.Time `form:"ctime" json:"ctime"` // 创建时间
  29. Extra json.RawMessage `form:"extra" json:"extra,omitempty"` // 额外字段,与业务方确定
  30. }
  31. //ArgMidDate arg
  32. type ArgMidDate struct {
  33. Mid int64 `form:"mid" validate:"required"`
  34. Days int `form:"days"` // 最近n天内的数据,1表示最近1天(今天),2表示最近2天,默认为0
  35. FromDate string `form:"from_date"` // 2006-01-02
  36. ToDate string `form:"to_date"` // 2006-01-02
  37. ScoreType int `form:"score_type" default:"3"` // 分数类型, 1,2,3,参见ScoreTypeCredit
  38. }
  39. //GetScoreParam arg
  40. type GetScoreParam struct {
  41. Mid int64
  42. FromDate systime.Time
  43. ToDate systime.Time
  44. ScoreType int
  45. }
  46. //ArgGetLogHistory arg
  47. type ArgGetLogHistory struct {
  48. Mid int64 `form:"mid" validate:"required"`
  49. FromDate systime.Time `form:"from_date"`
  50. ToDate systime.Time `form:"to_date"`
  51. Limit int `form:"limit" default:"20"`
  52. }
  53. //CreditLog db struct
  54. type CreditLog struct {
  55. ID uint `gorm:"primary_key" json:"-"`
  56. Type int
  57. OpType int
  58. Reason int
  59. BusinessType int
  60. Mid int64
  61. Oid int64
  62. UID int `gorm:"column:uid"`
  63. Content string
  64. CTime time.Time `gorm:"column:ctime"`
  65. MTime time.Time `gorm:"column:mtime"`
  66. Extra string `sql:"type:text;" json:"-"`
  67. }
  68. //TableName table name
  69. func (c *CreditLog) TableName() string {
  70. return getTableName(c.Mid)
  71. }
  72. func getTableName(mid int64) string {
  73. return fmt.Sprintf("credit_log_%02d", mid%CreditLogTableCount)
  74. }
  75. //CopyFrom copy
  76. func (c *CreditLog) CopyFrom(arg *ArgCreditLogAdd) *CreditLog {
  77. c.Type = arg.Type
  78. c.OpType = arg.OpType
  79. c.BusinessType = arg.BusinessType
  80. c.Reason = arg.Reason
  81. c.Mid = arg.Mid
  82. c.Oid = arg.Oid
  83. c.UID = arg.UID
  84. c.Content = arg.Content
  85. c.CTime = arg.CTime
  86. c.MTime = arg.CTime
  87. c.Extra = string(arg.Extra)
  88. return c
  89. }
  90. //SimpleCreditLog db struct
  91. type SimpleCreditLog struct {
  92. ID uint `gorm:"primary_key" json:"-"`
  93. Type int `json:"type"`
  94. OpType int `json:"op_type"`
  95. Reason int `json:"reason"`
  96. BusinessType int `json:"business_type"`
  97. Mid int64 `json:"mid"`
  98. Oid int64 `json:"oid"`
  99. CTime time.Time `gorm:"column:ctime" json:"ctime"`
  100. }
  101. //TableName table name
  102. func (c *SimpleCreditLog) TableName() string {
  103. return getTableName(c.Mid)
  104. }
  105. //SimpleCreditLogWithContent log with content
  106. type SimpleCreditLogWithContent struct {
  107. SimpleCreditLog
  108. Content string `form:"content" json:"content"` // 日志内容描述
  109. }