cygx_user_record.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. }
  32. // 获取所有关注了该产业用户的openid
  33. func GetCygxUserIndustryFllowOpneid(IndustrialManagementId int) (items []*OpenIdList, err error) {
  34. o := orm.NewOrm()
  35. sql := `SELECT
  36. cr.open_id,
  37. cr.cygx_user_id AS user_id
  38. FROM
  39. cygx_user_record AS cr
  40. INNER JOIN cygx_industry_fllow AS cf ON cr.cygx_user_id = cf.user_id
  41. WHERE
  42. 1 = 1
  43. AND cf.industrial_management_id = ? `
  44. _, err = o.Raw(sql, IndustrialManagementId).QueryRows(&items)
  45. return
  46. }