template_users.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. package models
  2. import (
  3. "eta/eta_mini_crm_ht/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. const (
  8. unOpen AccountStatus = "unOpen"
  9. open AccountStatus = "open"
  10. )
  11. var (
  12. accountStatusMap = map[AccountStatus]string{
  13. open: "已开户",
  14. unOpen: "未开户",
  15. }
  16. )
  17. type AccountStatus string
  18. // TemplateUsers
  19. // @Description: 临时用户表
  20. type TemplateUser struct {
  21. Id int `orm:"pk" description:"用户id"`
  22. UserName string `description:"姓名"`
  23. Mobile string `description:"手机号"`
  24. OpenId string `description:"用户openid"`
  25. UnionId string `description:"用户unionid"`
  26. IsDeleted int `description:"是否已删除"`
  27. GzhOpenId string `description:"用户公众号openid"`
  28. ReadCount int `description:"阅读次数"`
  29. FollowingGzh bool `description:"是否关注公众号"`
  30. AccountStatus AccountStatus `description:"账号状态"`
  31. LastReadTime time.Time `description:"最近一次阅读时间"`
  32. CreatedTime time.Time `description:"创建时间"`
  33. UpdatedTime time.Time `description:"变更时间"`
  34. }
  35. // TemplateUsers
  36. // @Description: 临时用户表
  37. type TemplateUsersItem struct {
  38. Id int `orm:"pk" description:"用户id"`
  39. UserName string `description:"姓名"`
  40. Mobile string `description:"手机号"`
  41. OpenId string `description:"用户openid"`
  42. UnionId string `description:"用户unionid"`
  43. GzhOpenId string `description:"用户公众号openid"`
  44. ReadCount int `description:"阅读次数"`
  45. AccountStatus string `description:"账号状态"`
  46. LastReadTime string `description:"最近一次阅读时间"`
  47. CreatedTime string `description:"创建时间"`
  48. UpdatedTime string `description:"变更时间"`
  49. }
  50. func (u *TemplateUser) TableName() string {
  51. return "template_users"
  52. }
  53. // GetPageTemplateUserList
  54. // @Description: 获取分页用户数据
  55. // @author: Roc
  56. // @datetime 2024-08-09 16:45:15
  57. // @param condition string
  58. // @param pars []interface{}
  59. // @param startSize int
  60. // @param pageSize int
  61. // @return total int
  62. // @return items []*TemplateUsers
  63. // @return err error
  64. func GetPageTemplateUserList(condition string, pars []interface{}, sortStr string, startSize, pageSize int) (total int, items []*TemplateUser, err error) {
  65. o := orm.NewOrm()
  66. totalSql := `SELECT count(1) ct FROM template_users AS a WHERE is_deleted = 0 `
  67. if condition != "" {
  68. totalSql += condition
  69. }
  70. err = o.Raw(totalSql, pars).QueryRow(&total)
  71. if err != nil {
  72. return
  73. }
  74. sql := `SELECT * FROM template_users AS a WHERE is_deleted = 0 `
  75. if condition != "" {
  76. sql += condition
  77. }
  78. if sortStr != `` {
  79. sql += ` ORDER BY ` + sortStr
  80. }
  81. sql += ` LIMIT ?,? `
  82. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  83. return
  84. }
  85. func GetTemplateUserList() (items []*TemplateUser, err error) {
  86. o := orm.NewOrm()
  87. sql := `SELECT * FROM template_users WHERE is_deleted = 0 `
  88. _, err = o.Raw(sql).QueryRows(&items)
  89. return
  90. }
  91. func GetTemplateUserListByCondition(condition string, pars []interface{}, sortStr string) (items []*TemplateUser, err error) {
  92. o := orm.NewOrm()
  93. sql := `SELECT * FROM template_users AS a WHERE is_deleted = 0 `
  94. if condition != "" {
  95. sql += condition
  96. }
  97. if sortStr != `` {
  98. sql += ` ORDER BY ` + sortStr
  99. }
  100. _, err = o.Raw(sql, pars).QueryRows(&items)
  101. return
  102. }
  103. func GetTemplateUser(id int) (item *TemplateUser, err error) {
  104. o := orm.NewOrm()
  105. sql := `SELECT * FROM template_users WHERE id=? and is_deleted = 0 `
  106. err = o.Raw(sql, id).QueryRow(&item)
  107. return
  108. }
  109. // ToItem
  110. // @Description: 转结构体返回
  111. // @author: Roc
  112. // @receiver m
  113. // @datetime 2024-08-09 16:50:41
  114. // @return item TemplateUsersItem
  115. func (m *TemplateUser) ToItem() (item TemplateUsersItem) {
  116. item = TemplateUsersItem{
  117. Id: m.Id,
  118. UserName: m.UserName,
  119. Mobile: m.Mobile,
  120. OpenId: m.OpenId,
  121. UnionId: m.UnionId,
  122. GzhOpenId: m.GzhOpenId,
  123. ReadCount: m.ReadCount,
  124. AccountStatus: accountStatusMap[m.AccountStatus],
  125. LastReadTime: "",
  126. CreatedTime: m.CreatedTime.Format(utils.FormatDateTime),
  127. UpdatedTime: m.UpdatedTime.Format(utils.FormatDateTime),
  128. }
  129. if !m.LastReadTime.IsZero() {
  130. item.LastReadTime = m.LastReadTime.Format(utils.FormatDateTime)
  131. }
  132. return
  133. }