friend.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package model
  2. import (
  3. "leafstalk/otherutils/deepcopy"
  4. "strconv"
  5. "time"
  6. "xorm.io/xorm"
  7. )
  8. // 0:未赠送 1:已赠送 2:已领取
  9. const (
  10. SendFlag_Unsent = 0
  11. SendFlag_Sent = 1
  12. SendFlag_Received = 2
  13. )
  14. // // 好友状态
  15. // type FriendStatus struct {
  16. // SendFlag int64 `json:"SendFlag"` // 赠送的体力的标志位 0:未赠送 1:已赠送
  17. // RcvFlag int64 `json:"RcvFlag"` // 赠送的体力的标志位 0:未赠送 1:已赠送 2:已领取
  18. // // LastTs int64 `json:"lastTs"` //最后收发的时间
  19. // }
  20. // 申请列表
  21. // type FriendRequestItem struct {
  22. // Requester int64 `json:"requester"` // 申请人
  23. // CreateTs int64 `json:"createTs"` // 申请时间
  24. // }
  25. // 玩家好友数据
  26. type FriendPlayer struct {
  27. Id int64 // id
  28. PlayerId int64 `xorm:"BIGINT index 'playerid'"` // 玩家ID
  29. Friends map[int64]struct{} `xorm:"-"` // 好友
  30. Requests map[int64]int64 `xorm:"-"` // 好友申请
  31. Approvals map[int64]int64 `xorm:"-"` // 好友审核
  32. Gives map[int64]struct{} `xorm:"Text json 'gives'"` // 已赠送给谁
  33. Receives map[int64]int `xorm:"Text json 'receives'"` // 领取状态
  34. LastGiveTs int64 `xorm:"BIGINT 'lastGiveTs'"` // 最后赠送的时间
  35. CreatedAt int64 `xorm:"BIGINT 'createdat'"`
  36. }
  37. func (m FriendPlayer) TableName() string {
  38. return "friend_player"
  39. }
  40. // 需要保存的数据需确保在这里能复制到new1 中
  41. //
  42. // func (m *FriendPlayer) DeepCopy() interface{} {
  43. // new1 := new(FriendPlayer)
  44. // *new1 = *m
  45. //
  46. // return new1
  47. // }
  48. func (m *FriendPlayer) QueryExist(eng *xorm.Engine) (bool, error) {
  49. player := new(FriendPlayer)
  50. player.PlayerId = m.PlayerId
  51. return eng.Exist(player)
  52. }
  53. func (m *FriendPlayer) UpdateDB(eng *xorm.Engine) (int64, error) {
  54. return eng.Where("playerid=?", m.PlayerId).AllCols().Update(m)
  55. }
  56. func (m *FriendPlayer) GetUniqueKey() string {
  57. return strconv.FormatInt(m.PlayerId, 10)
  58. }
  59. func CopyFriend(old *FriendPlayer) *FriendPlayer {
  60. nu := deepcopy.MustCopy(old).(*FriendPlayer)
  61. return nu
  62. }
  63. type FriendRelation struct {
  64. Id int64
  65. UserId int64 `xorm:"index notnull 'userId'"`
  66. FriendId int64 `xorm:"index notnull 'friendId'"`
  67. CreatedAt int64 `xorm:"created"`
  68. // Status int `xorm:"tinyint(1) notnull comment('0-待确认 1-已好友 2-已拉黑')"`
  69. // Group string `xorm:"varchar(20) comment('好友分组')"`
  70. // UpdatedAt int64 `xorm:"updated"`
  71. }
  72. func (m *FriendRelation) TableName() string {
  73. return "friend_relation"
  74. }
  75. // 好友申请表
  76. type FriendRequest struct {
  77. Id int64
  78. Requester int64 `xorm:"index notnull 'requester'"`
  79. Recipient int64 `xorm:"index notnull 'recipient'"`
  80. CreatedAt time.Time `xorm:"created"`
  81. // Status int `xorm:"tinyint(1) notnull comment('0-待处理 1-已接受 2-已拒绝')"`
  82. // Message string `xorm:"varchar(255) comment('申请留言')"`
  83. // ProcessedAt time.Time `xorm:"comment('处理时间')"`
  84. }
  85. func (m *FriendRequest) TableName() string {
  86. return "friend_request"
  87. }
  88. // TableName 表名
  89. // func (m Friend) TableName() string {
  90. // return "friend"
  91. // }
  92. // 好友基础表|Vertical-FriendBase exported from 好友相关配置.xlsx
  93. type FriendBase struct {
  94. FriendMax int64 `json:"FriendMax"` // 好友上限
  95. GiveStamina int64 `json:"GiveStamina"` // 体力单次赠送值/体力单次获得值
  96. GiveStaminaNumMax int64 `json:"GiveStaminaNumMax"` // 每天赠送体力次数上限
  97. GetStaminaNumMax int64 `json:"GetStaminaNumMax"` // 每日接收体力次数上限
  98. FriendApplyTs int64 `json:"FriendApplyTs"` // 好友申请有效时间 /天
  99. FriendRefNum int64 `json:"FriendRefNum"` // 好友添加刷新人数 /个
  100. }