model.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. package model
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "time"
  6. xtime "go-common/library/time"
  7. "github.com/satori/go.uuid"
  8. )
  9. const (
  10. // FlagNo 否
  11. FlagNo = int32(0)
  12. // FlagYes 是
  13. FlagYes = int32(1)
  14. // ExpFlagOnLogin 每日登录经验
  15. ExpFlagOnLogin = int32(1)
  16. // ExpFlagOnShare 每日分享经验
  17. ExpFlagOnShare = int32(2)
  18. // ExpFlagOnView 每日播放经验
  19. ExpFlagOnView = int32(4)
  20. // ExpFlagOnEmail 一次性绑定邮箱
  21. ExpFlagOnEmail = int32(8)
  22. // ExpFlagOnPhone 一次性绑定手机
  23. ExpFlagOnPhone = int32(16)
  24. // ExpFlagOnSafe 一次性绑定密保
  25. ExpFlagOnSafe = int32(32)
  26. // ExpFlagOnIdentify 一次性实名认证
  27. ExpFlagOnIdentify = int32(64)
  28. // ExpActOnCoin 投币奖励动作
  29. ExpActOnCoin = int64(1)
  30. // ExpActOnLogin 登录奖励动作
  31. ExpActOnLogin = int64(2)
  32. // ExpActOnView 播放奖励动作
  33. ExpActOnView = int64(3)
  34. // ExpActOnShare 分享奖励动作
  35. ExpActOnShare = int64(4)
  36. // ExpActOnEmail 绑定邮箱动作
  37. ExpActOnEmail = int64(5)
  38. // ExpActOnPhone 绑定手机动作
  39. ExpActOnPhone = int64(6)
  40. // ExpActOnSafe 绑定密保动作
  41. ExpActOnSafe = int64(7)
  42. // ExpActOnIdentify 实名认证动作
  43. ExpActOnIdentify = int64(8)
  44. )
  45. var (
  46. login = &ExpOper{ExpFlagOnLogin, 5, "login", "登录奖励"}
  47. share = &ExpOper{ExpFlagOnShare, 5, "shareClick", "分享视频奖励"}
  48. view = &ExpOper{ExpFlagOnView, 5, "watch", "观看视频奖励"}
  49. email = &ExpOper{ExpFlagOnEmail, 20, "bindEmail", "绑定邮箱奖励"}
  50. safe = &ExpOper{ExpFlagOnSafe, 30, "pwdPro", "设置密保奖励"}
  51. phone = &ExpOper{ExpFlagOnPhone, 100, "bindPhone", "绑定手机奖励"}
  52. identify = &ExpOper{ExpFlagOnIdentify, 50, "realIdentity", "实名认证奖励"}
  53. // ExpFlagOper exp flag map for oper
  54. ExpFlagOper = map[string]*ExpOper{"login": login, "share": share, "view": view, "email": email, "phone": phone, "safe": safe, "identify": identify}
  55. )
  56. // Exp userexp for mysql scan.
  57. type Exp struct {
  58. Mid int64 `json:"mid"`
  59. Exp float32 `json:"exp"`
  60. Mtime xtime.Time `json:"modify_time"`
  61. }
  62. // ExpLog user exp log for mysql
  63. type ExpLog struct {
  64. Mid int64 `json:"mid"`
  65. FromExp float32 `json:"from_exp"`
  66. ToExp float32 `json:"to_exp"`
  67. Operater string `json:"operater"`
  68. Reason string `json:"reason"`
  69. Action int64 `json:"actin_id"`
  70. Mtime xtime.Time `json:"modify_time"`
  71. }
  72. // NewExp userexp for mysql scan.
  73. type NewExp struct {
  74. Mid int64 `json:"mid"`
  75. Exp int64 `json:"exp"`
  76. Flag int32 `json:"flag"`
  77. Addtime xtime.Time `json:"addtime"`
  78. Mtime xtime.Time `json:"mtime"`
  79. }
  80. // ExpOper exp operation
  81. type ExpOper struct {
  82. Flag int32
  83. Count int64
  84. Oper string
  85. Reason string
  86. }
  87. // Message binlog databus msg.
  88. type Message struct {
  89. Action string `json:"action"`
  90. Table string `json:"table"`
  91. New json.RawMessage `json:"new"`
  92. Old json.RawMessage `json:"old"`
  93. }
  94. //Flag is.
  95. type Flag struct {
  96. Mid int64 `json:"mid,omitempty"`
  97. Flag int64 `json:"finish_action"`
  98. Exp int64 `json:"modify_exp"`
  99. }
  100. // UserLog user log.
  101. type UserLog struct {
  102. Mid int64 `json:"mid"`
  103. IP string `json:"ip"`
  104. TS int64 `json:"ts"`
  105. LogID string `json:"log_id"`
  106. Content map[string]string `json:"content"`
  107. }
  108. // AddExp databus add exp arg.
  109. type AddExp struct {
  110. Event string `json:"event,omitempty"`
  111. Mid int64 `json:"mid,omitempty"`
  112. IP string `json:"ip,omitempty"`
  113. Ts int64 `json:"ts,omitempty"`
  114. }
  115. // LoginLog user login log.
  116. type LoginLog struct {
  117. Mid int64 `json:"mid,omitempty"`
  118. Loginip int64 `json:"loginip,omitempty"`
  119. Timestamp int64 `json:"timestamp,omitempty"`
  120. }
  121. // LoginLogIPString user login log message with string ip.
  122. type LoginLogIPString struct {
  123. Mid int64 `json:"mid,omitempty"`
  124. Loginip string `json:"loginip,omitempty"`
  125. Timestamp int64 `json:"timestamp,omitempty"`
  126. }
  127. // FaceCheckRes face check result.
  128. type FaceCheckRes struct {
  129. FileName string `json:"file_name,omitempty"`
  130. Bucket string `json:"bucket,omitempty"`
  131. Sex float64 `json:"sex,omitempty"`
  132. Politics float64 `json:"politics,omitempty"`
  133. }
  134. // FacePath is
  135. func (fcr *FaceCheckRes) FacePath() string {
  136. return fmt.Sprintf("/bfs/%s/%s", fcr.Bucket, fcr.FileName)
  137. }
  138. //String is.
  139. func (fcr *FaceCheckRes) String() string {
  140. return fmt.Sprintf("Sex: %.4f, Politics: %.4f", fcr.Sex, fcr.Politics)
  141. }
  142. // MemberMid member mid
  143. type MemberMid struct {
  144. Mid int64 `json:"mid"`
  145. }
  146. // MemberAso member aso
  147. type MemberAso struct {
  148. Email string `json:"email"`
  149. Telphone string `json:"telphone"`
  150. SafeQs int8 `json:"safe_question"`
  151. Spacesta int8 `json:"spacesta"`
  152. }
  153. // ExpMessage exp msg
  154. type ExpMessage struct {
  155. Mid int64 `json:"mid"`
  156. Exp int64 `json:"exp"`
  157. }
  158. // FlagDailyReset reset daily flag with ts.
  159. func (e *NewExp) FlagDailyReset(now time.Time) {
  160. e.Flag = e.Flag & ^0x7
  161. e.Addtime = RestrictDate(xtime.Time(now.Unix()))
  162. }
  163. // RestrictDate restric user brithday
  164. func RestrictDate(xt xtime.Time) xtime.Time {
  165. t := xt.Time()
  166. year := t.Year()
  167. if year < 0 {
  168. year = 0
  169. }
  170. return xtime.Time(time.Date(year, t.Month(), t.Day(), 0, 0, 0, 0, t.Location()).Unix())
  171. }
  172. // UUID4 is generate uuid
  173. func UUID4() string {
  174. return uuid.NewV4().String()
  175. }