user.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. package model
  2. import (
  3. "database/sql/driver"
  4. "fmt"
  5. "time"
  6. )
  7. /* code 结构体 */
  8. type CodeData struct {
  9. Code string `form:"code" binding:"required"`
  10. Gid string `form:"gid" binding:"required"`
  11. Pf string `form:"pf" binding:"required"`
  12. Secret string `form:"secret"`
  13. }
  14. type Users struct {
  15. ID int `json:"id" gorm:"not null;"`
  16. OpenId string `json:"openId" gorm:"not null;column:openId;"`
  17. Pf string `json:"pf" gorm:"not null;"`
  18. UserId int `json:"userId" gorm:"not null;column:userId;"`
  19. CreatedAt time.Time `json:"createdAt" gorm:"column:createdAt;"`
  20. UpdatedAt time.Time `json:"updatedAt" gorm:"column:updatedAt;"`
  21. }
  22. type User struct {
  23. ID int `json:"id" gorm:"not null;"`
  24. Pf string `json:"pf" gorm:"not null;"`
  25. Gid string `json:"gid" gorm:"not null;"`
  26. UserId int `json:"userId" gorm:"not null;column:userId;"`
  27. CreatedAt time.Time `json:"createdAt" gorm:"column:createdAt;"`
  28. }
  29. type UserLogin struct {
  30. ID int `json:"id" gorm:"not null;"`
  31. Pf string `json:"pf" gorm:"not null;"`
  32. Gid string `json:"gid" gorm:"not null;"`
  33. UserId int `json:"userId" gorm:"not null;column:userId;"`
  34. LoginTime time.Time `json:"loginTime" gorm:"column:loginTime;"`
  35. }
  36. type UserOnline struct {
  37. ID int `json:"id" gorm:"not null;"`
  38. Pf string `json:"pf" gorm:"not null;"`
  39. Gid string `json:"gid" gorm:"not null;"`
  40. UserId int `json:"userId" gorm:"not null;column:userId;"`
  41. Type int `json:"type" gorm:"not null;"`
  42. Date string `json:"date" gorm:"not null;"`
  43. LogTime time.Time `json:"logTime" gorm:"column:logTime;"`
  44. }
  45. type UserSeeAds struct {
  46. ID int `json:"id" gorm:"not null;"`
  47. Pf string `json:"pf" gorm:"not null;"`
  48. Gid string `json:"gid" gorm:"not null;"`
  49. UserId int `json:"userId" gorm:"not null;column:userId;"`
  50. Date string `json:"date" gorm:"not null;"`
  51. CreatedAt time.Time `json:"createdAt" gorm:"column:createdAt;"`
  52. AdsId string `json:"adsId" gorm:"not null;column:adsId;"`
  53. AdsType string `json:"adsType" gorm:"not null;column:adsType;"`
  54. AdsScene string `json:"adsScene" gorm:"not null;column:adsScene;"`
  55. AdsState int `json:"adsState" gorm:"not null;column:adsState;"`
  56. }
  57. // 1. 创建 time.Time 类型的副本 XTime;
  58. type XTime struct {
  59. time.Time
  60. }
  61. // 2. 为 Xtime 重写 MarshaJSON 方法,在此方法中实现自定义格式的转换;
  62. func (t XTime) MarshalJSON() ([]byte, error) {
  63. output := fmt.Sprintf("\"%s\"", t.Format("2006-01-02 15:04:05"))
  64. return []byte(output), nil
  65. }
  66. // 3. 为 Xtime 实现 Value 方法,写入数据库时会调用该方法将自定义时间类型转换并写入数据库;
  67. func (t XTime) Value() (driver.Value, error) {
  68. var zeroTime time.Time
  69. if t.Time.UnixNano() == zeroTime.UnixNano() {
  70. return nil, nil
  71. }
  72. return t.Time, nil
  73. }
  74. // 4. 为 Xtime 实现 Scan 方法,读取数据库时会调用该方法将时间数据转换成自定义时间类型;
  75. func (t *XTime) Scan(v interface{}) error {
  76. value, ok := v.(time.Time)
  77. if ok {
  78. *t = XTime{Time: value}
  79. return nil
  80. }
  81. return fmt.Errorf("can not convert %v to timestamp", v)
  82. }
  83. type GameAction struct {
  84. ID int `json:"id" gorm:"not null;"`
  85. Gid string `json:"gid" gorm:"not null;"`
  86. ActionId string `json:"actionId" gorm:"not null;column:actionId;"`
  87. ActionName string `json:"actionName" gorm:"not null;column:actionName;"`
  88. Status int `json:"status" gorm:"not null;column:status;"`
  89. Remark string `json:"remark" gorm:"not null;column:remark;"`
  90. CreatedAt XTime `json:"createdAt" gorm:"column:createdAt;type:date;"`
  91. UpdatedAt XTime `json:"updatedAt" gorm:"column:updatedAt;type:date;"`
  92. }
  93. type GameActionOption struct {
  94. ID int `json:"id" gorm:"not null;"`
  95. ActionId int `json:"actionId" gorm:"not null;column:actionId;"`
  96. OptionId string `json:"optionId" gorm:"not null;column:optionId;"`
  97. OptionName string `json:"optionName" gorm:"not null;column:optionName;"`
  98. OptionType string `json:"optionType" gorm:"not null;column:optionType;"`
  99. Status int `json:"status" gorm:"not null;column:status;"`
  100. CreatedAt XTime `json:"createdAt" gorm:"column:createdAt;"`
  101. UpdatedAt XTime `json:"updatedAt" gorm:"column:updatedAt;"`
  102. }
  103. type UserAction struct {
  104. ID int `json:"id" gorm:"not null;"`
  105. Pf string `json:"pf" gorm:"not null;"`
  106. Gid string `json:"gid" gorm:"not null;"`
  107. ActionId string `json:"actionId" gorm:"not null;column:actionId;"`
  108. UserId int `json:"userId" gorm:"not null;column:userId;"`
  109. CreatedAt XTime `json:"createdAt" gorm:"column:createdAt;type:date;"`
  110. }
  111. type UserActionOption struct {
  112. ID int `json:"id" gorm:"not null;"`
  113. OptionId string `json:"optionId" gorm:"not null;column:optionId;"`
  114. UserActionId int `json:"userActionId" gorm:"not null;column:userActionId;"`
  115. CreatedAt XTime `json:"createdAt" gorm:"column:createdAt;type:date;"`
  116. Value string `json:"value" gorm:"not null;column:value;"`
  117. }