user.go 6.1 KB

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