template_users.go 3.1 KB

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