user.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. Aid string `json:"aid" gorm:"not null;" column:"aid;"`
  27. Pid string `json:"pid" gorm:"not null;" column:"pid;"`
  28. Cid string `json:"cid" gorm:"not null;" column:"cid;"`
  29. UserId int `json:"userId" gorm:"not null;column:userId;"`
  30. OpenId string `json:"openId" gorm:"not null;column:openId;"`
  31. CreatedAt time.Time `json:"createdAt" gorm:"column:createdAt;"`
  32. }
  33. type UserLogin struct {
  34. ID int `json:"id" gorm:"not null;"`
  35. Pf string `json:"pf" gorm:"not null;"`
  36. Gid string `json:"gid" gorm:"not null;"`
  37. UserId int `json:"userId" gorm:"not null;column:userId;"`
  38. LoginTime time.Time `json:"loginTime" gorm:"column:loginTime;"`
  39. }
  40. type UserOnline struct {
  41. ID int `json:"id" gorm:"not null;"`
  42. Pf string `json:"pf" gorm:"not null;"`
  43. Gid string `json:"gid" gorm:"not null;"`
  44. UserId int `json:"userId" gorm:"not null;column:userId;"`
  45. Type int `json:"type" gorm:"not null;"`
  46. Date string `json:"date" gorm:"not null;"`
  47. LogTime time.Time `json:"logTime" gorm:"column:logTime;"`
  48. }
  49. type UserOnlineSplit struct {
  50. ID int `json:"id" gorm:"not null;"`
  51. Pf string `json:"pf" gorm:"not null;"`
  52. UserId int `json:"userId" gorm:"not null;column:userId;"`
  53. Type int `json:"type" gorm:"not null;"`
  54. LogTime time.Time `json:"logTime" gorm:"column:logTime;"`
  55. }
  56. type UserSeeAds struct {
  57. ID int `json:"id" gorm:"not null;"`
  58. Pf string `json:"pf" gorm:"not null;"`
  59. Gid string `json:"gid" gorm:"not null;"`
  60. UserId int `json:"userId" gorm:"not null;column:userId;"`
  61. Date string `json:"date" gorm:"not null;"`
  62. CreatedAt time.Time `json:"createdAt" gorm:"column:createdAt;"`
  63. StartTime time.Time `json:"startTime" gorm:"column:startTime;"`
  64. AdsId string `json:"adsId" gorm:"not null;column:adsId;"`
  65. AdsType string `json:"adsType" gorm:"not null;column:adsType;"`
  66. AdsScene string `json:"adsScene" gorm:"not null;column:adsScene;"`
  67. AdsState int `json:"adsState" gorm:"not null;column:adsState;"`
  68. }
  69. // 1. 创建 time.Time 类型的副本 XTime;
  70. type XTime struct {
  71. time.Time
  72. }
  73. // 2. 为 Xtime 重写 MarshaJSON 方法,在此方法中实现自定义格式的转换;
  74. func (t XTime) MarshalJSON() ([]byte, error) {
  75. output := fmt.Sprintf("\"%s\"", t.Format("2006-01-02 15:04:05"))
  76. return []byte(output), nil
  77. }
  78. // 3. 为 Xtime 实现 Value 方法,写入数据库时会调用该方法将自定义时间类型转换并写入数据库;
  79. func (t XTime) Value() (driver.Value, error) {
  80. var zeroTime time.Time
  81. if t.Time.UnixNano() == zeroTime.UnixNano() {
  82. return nil, nil
  83. }
  84. return t.Time, nil
  85. }
  86. // 4. 为 Xtime 实现 Scan 方法,读取数据库时会调用该方法将时间数据转换成自定义时间类型;
  87. func (t *XTime) Scan(v interface{}) error {
  88. value, ok := v.(time.Time)
  89. if ok {
  90. *t = XTime{Time: value}
  91. return nil
  92. }
  93. return fmt.Errorf("can not convert %v to timestamp", v)
  94. }
  95. type GameAction struct {
  96. ID int `json:"id" gorm:"not null;"`
  97. Gid string `json:"gid" gorm:"not null;"`
  98. ActionId string `json:"actionId" gorm:"not null;column:actionId;"`
  99. ActionName string `json:"actionName" gorm:"not null;column:actionName;"`
  100. Status int `json:"status" gorm:"not null;column:status;"`
  101. Remark string `json:"remark" gorm:"not null;column:remark;"`
  102. CreatedAt XTime `json:"createdAt" gorm:"column:createdAt;type:date;"`
  103. UpdatedAt XTime `json:"updatedAt" gorm:"column:updatedAt;type:date;"`
  104. }
  105. type GameActionOption struct {
  106. ID int `json:"id" gorm:"not null;"`
  107. ActionId int `json:"actionId" gorm:"not null;column:actionId;"`
  108. OptionId string `json:"optionId" gorm:"not null;column:optionId;"`
  109. OptionName string `json:"optionName" gorm:"not null;column:optionName;"`
  110. OptionType string `json:"optionType" gorm:"not null;column:optionType;"`
  111. Status int `json:"status" gorm:"not null;column:status;"`
  112. CreatedAt XTime `json:"createdAt" gorm:"column:createdAt;"`
  113. UpdatedAt XTime `json:"updatedAt" gorm:"column:updatedAt;"`
  114. }
  115. type UserAction struct {
  116. ID int `json:"id" gorm:"not null;"`
  117. Pf string `json:"pf" gorm:"not null;"`
  118. Gid string `json:"gid" gorm:"not null;"`
  119. ActionId string `json:"actionId" gorm:"not null;column:actionId;"`
  120. UserId int `json:"userId" gorm:"not null;column:userId;"`
  121. Date string `json:"date" gorm:"not null;column:date;"`
  122. CreatedAt XTime `json:"createdAt" gorm:"column:createdAt;type:date;"`
  123. }
  124. type UserActionOption struct {
  125. ID int `json:"id" gorm:"not null;"`
  126. OptionId string `json:"optionId" gorm:"not null;column:optionId;"`
  127. UserActionId int `json:"userActionId" gorm:"not null;column:userActionId;"`
  128. CreatedAt XTime `json:"createdAt" gorm:"column:createdAt;type:date;"`
  129. Value string `json:"value" gorm:"not null;column:value;"`
  130. }