invite.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package model
  2. import (
  3. "strconv"
  4. accmdl "go-common/app/service/main/account/model"
  5. usmdl "go-common/app/service/main/usersuit/model"
  6. xtime "go-common/library/time"
  7. )
  8. // RichInviteStat rich invite stat.
  9. type RichInviteStat struct {
  10. Mid int64 `json:"mid"`
  11. CurrentLimit int64 `json:"current_limit"`
  12. CurrentBought int64 `json:"current_bought"`
  13. TotalBought int64 `json:"total_bought"`
  14. TotalUsed int64 `json:"total_used"`
  15. InviteCodes []*RichInvite `json:"invite_codes"`
  16. }
  17. // RichInvite rich invite.
  18. type RichInvite struct {
  19. Status int64 `json:"status"`
  20. Mid int64 `json:"mid"`
  21. Code string `json:"invite_code"`
  22. Ctime xtime.Time `json:"buy_time"`
  23. Expires int64 `json:"expires"`
  24. Invitee *Invitee `json:"invitee,omitempty"`
  25. UsedAt int64 `json:"used_at,omitempty"`
  26. }
  27. // NewRichInvite new a rich invite.
  28. func NewRichInvite(inv *usmdl.Invite, info *accmdl.Info) *RichInvite {
  29. if inv == nil {
  30. return nil
  31. }
  32. var invt *Invitee
  33. if inv.Used() {
  34. if info != nil {
  35. invt = &Invitee{
  36. Mid: inv.Imid,
  37. Uname: info.Name,
  38. Face: info.Face,
  39. }
  40. } else {
  41. invt = &Invitee{
  42. Mid: inv.Imid,
  43. Uname: "用户" + strconv.FormatInt(inv.Imid, 10),
  44. Face: "http://static.hdslb.com/images/member/noface.gif",
  45. }
  46. }
  47. }
  48. return &RichInvite{
  49. Status: inv.Status,
  50. Mid: inv.Mid,
  51. Code: inv.Code,
  52. Ctime: inv.Ctime,
  53. Expires: inv.Expires,
  54. Invitee: invt,
  55. UsedAt: inv.UsedAt,
  56. }
  57. }
  58. // Invitee invitee.
  59. type Invitee struct {
  60. Mid int64 `json:"mid"`
  61. Uname string `json:"uname"`
  62. Face string `json:"face"`
  63. }