article_collect.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package models
  2. import (
  3. "github.com/rdlucklib/rdluck_tools/orm"
  4. "time"
  5. )
  6. type CygxArticleCollect struct {
  7. Id int `orm:"column(id);pk"`
  8. ArticleId int
  9. UserId int
  10. CreateTime time.Time
  11. }
  12. //添加收藏信息
  13. func AddCygxArticleCollect(item *CygxArticleCollect) (lastId int64, err error) {
  14. o := orm.NewOrm()
  15. lastId, err = o.Insert(item)
  16. return
  17. }
  18. type ArticleCollectReq struct {
  19. ArticleId int `description:"报告id"`
  20. }
  21. type ArticleCollectResp struct {
  22. Status int `description:"1:收藏,2:取消收藏"`
  23. CollectCount int `description:"收藏总数"`
  24. }
  25. func RemoveArticleCollect(userId, articleId int) (err error) {
  26. o := orm.NewOrm()
  27. sql := `DELETE FROM cygx_article_collect WHERE user_id=? AND article_id=? `
  28. _, err = o.Raw(sql, userId, articleId).Exec()
  29. return
  30. }
  31. func GetArticleCollectUsersCount(articleId int) (count int, err error) {
  32. sql := `SELECT COUNT(user_id) AS count FROM cygx_article_collect WHERE article_id=? `
  33. err = orm.NewOrm().Raw(sql, articleId).QueryRow(&count)
  34. return
  35. }
  36. func GetArticleCollectCount(userId, articleId int) (count int, err error) {
  37. sql := `SELECT COUNT(1) AS count FROM cygx_article_collect WHERE user_id=? AND article_id=? `
  38. err = orm.NewOrm().Raw(sql, userId, articleId).QueryRow(&count)
  39. return
  40. }
  41. type ArticleCollectList struct {
  42. Id int `orm:"column(id);pk"`
  43. ArticleId int
  44. UserId int
  45. CreateTime time.Time
  46. Title string `description:"标题"`
  47. TitleEn string `description:"英文标题 "`
  48. UpdateFrequency string `description:"更新周期"`
  49. CreateDate string `description:"创建时间"`
  50. PublishDate string `description:"发布时间"`
  51. Body string `description:"内容"`
  52. Abstract string `description:"摘要"`
  53. CategoryName string `description:"一级分类"`
  54. SubCategoryName string `description:"二级分类"`
  55. }