cygx_user_record.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxUserRecord struct {
  7. UserRecordId int `orm:"column(user_record_id);pk" description:"id"`
  8. OpenId string `description:"用户openid,最大长度:32"`
  9. UnionId string `description:"用户unionid,最大长度:64"`
  10. Subscribe int `description:"是否关注,0:未关注,1:已关注"`
  11. SubscribeTime string `description:"关注/取消关注时间"`
  12. CreateTime time.Time `description:"创建时间"`
  13. }
  14. // 优化建议
  15. func AddCygxUserRecord(item *CygxUserRecord) (lastId int64, err error) {
  16. o := orm.NewOrm()
  17. lastId, err = o.Insert(item)
  18. return
  19. }
  20. // 获取数量
  21. func GetCygxUserRecordCount(openId string) (count int, err error) {
  22. o := orm.NewOrm()
  23. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_user_record WHERE open_id=? `
  24. err = o.Raw(sqlCount, openId).QueryRow(&count)
  25. return
  26. }
  27. func GetCygxUserRecordSubscribe(unionId string) (item *CygxUserRecord, err error) {
  28. sql := ` SELECT * FROM cygx_user_record WHERE union_id=? AND subscribe = 1 limit 1 `
  29. err = orm.NewOrm().Raw(sql, unionId).QueryRow(&item)
  30. return
  31. }