user_info.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package model
  2. import (
  3. "time"
  4. xtime "go-common/library/time"
  5. )
  6. // UserInfo represents user info.
  7. type UserInfo struct {
  8. ID int32 `json:"id"` // 用户信息表
  9. Mid int64 `json:"mid"` // 用户mid
  10. Ver int32 `json:"ver"` // 版本控制
  11. VipType int8 `json:"vip_type"` // tv-vip类型:1.vip 2.年费vip
  12. PayType int8 `json:"pay_type"` // tv-vip购买类型:0.正常购买 1.连续包月
  13. PayChannelId string `json:"pay_channel_id"` // 自动续费渠道:wechat,alipay
  14. Status int8 `json:"status"` // tv-vip状态:0:过期 1:未过期
  15. OverdueTime xtime.Time `json:"overdue_time"` // tv-vip过期时间
  16. RecentPayTime xtime.Time `json:"recent_pay_time"` // tv-vip最近开通时间
  17. Ctime xtime.Time `json:"ctime"` // 创建时间
  18. Mtime xtime.Time `json:"mtime"` // 修改时间
  19. }
  20. // IsEmpty returns true if user id equals -1.
  21. func (ui *UserInfo) IsEmpty() bool {
  22. return ui.ID == -1
  23. }
  24. // IsExpired returns true if user is expired vip.
  25. func (ui *UserInfo) IsExpired() bool {
  26. return ui.OverdueTime < xtime.Time(time.Now().Unix())
  27. }
  28. // MarkExpired sets user status to expired status.
  29. func (ui *UserInfo) MarkExpired() {
  30. ui.Status = 0
  31. }
  32. // IsVip returns true if user is vip.
  33. func (ui *UserInfo) IsVip() bool {
  34. if ui.IsEmpty() {
  35. return false
  36. }
  37. if ui.IsExpired() {
  38. return false
  39. }
  40. return ui.Status == 1
  41. }
  42. // IsContracted returns true if user buys contracted package.
  43. func (ui *UserInfo) IsContracted() bool {
  44. return ui.PayType == 1
  45. }
  46. // CopyFromPayOrder copies fileds from pay order.
  47. func (ui *UserInfo) CopyFromPayOrder(po *PayOrder) {
  48. ui.VipType = VipTypeVip
  49. ui.PayChannelId = po.PaymentType
  50. ui.RecentPayTime = xtime.Time(time.Now().Unix())
  51. }
  52. // CopyFromPanel copies field from panel.
  53. func (ui *UserInfo) CopyFromPanel(p *PanelPriceConfig) {
  54. if p.SubType == SubTypeContract {
  55. ui.PayType = VipPayTypeSub
  56. return
  57. }
  58. ui.PayType = VipPayTypeNormal
  59. }