user.go 6.3 KB

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