user.go 5.2 KB

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