template_users.go 3.2 KB

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