article_collect.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/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. Mobile string `description:"手机号"`
  12. Email string `description:"邮箱"`
  13. CompanyId int `description:"公司id"`
  14. CompanyName string `description:"公司名称"`
  15. RealName string `description:"用户实际名称"`
  16. }
  17. //添加收藏信息
  18. func AddCygxArticleCollect(item *CygxArticleCollect) (lastId int64, err error) {
  19. o := orm.NewOrm()
  20. lastId, err = o.Insert(item)
  21. return
  22. }
  23. type ArticleCollectReq struct {
  24. ArticleId int `description:"报告id"`
  25. }
  26. type ArticleCollectResp struct {
  27. Status int `description:"1:收藏,2:取消收藏"`
  28. CollectCount int `description:"收藏总数"`
  29. }
  30. func RemoveArticleCollect(userId, articleId int) (err error) {
  31. o := orm.NewOrm()
  32. sql := `DELETE FROM cygx_article_collect WHERE user_id=? AND article_id=? `
  33. _, err = o.Raw(sql, userId, articleId).Exec()
  34. return
  35. }
  36. func GetArticleCollectUsersCount(articleId int) (count int, err error) {
  37. sql := `SELECT COUNT(user_id) AS count FROM cygx_article_collect WHERE article_id=? `
  38. err = orm.NewOrm().Raw(sql, articleId).QueryRow(&count)
  39. return
  40. }
  41. func GetArticleCollectCount(userId, articleId int) (count int, err error) {
  42. sql := `SELECT COUNT(1) AS count FROM cygx_article_collect WHERE user_id=? AND article_id=? `
  43. err = orm.NewOrm().Raw(sql, userId, articleId).QueryRow(&count)
  44. return
  45. }
  46. type ArticleCollectList struct {
  47. Id int `orm:"column(id);pk"`
  48. ArticleId int
  49. UserId int
  50. CreateTime time.Time
  51. Title string `description:"标题"`
  52. TitleEn string `description:"英文标题 "`
  53. UpdateFrequency string `description:"更新周期"`
  54. CreateDate string `description:"创建时间"`
  55. PublishDate string `description:"发布时间"`
  56. Body string `description:"内容"`
  57. Abstract string `description:"摘要"`
  58. CategoryName string `description:"一级分类"`
  59. SubCategoryName string `description:"二级分类"`
  60. }
  61. func GetCygxArticleCollectList() (items []*CygxArticleCollect, err error) {
  62. o := orm.NewOrm()
  63. sql := `SELECT * FROM cygx_article_collect GROUP BY user_id `
  64. _, err = o.Raw(sql).QueryRows(&items)
  65. return
  66. }
  67. //修改用户收藏文章的相关信息
  68. func UpdateCygxArticleCollect(wxUser *WxUserItem) (err error) {
  69. o := orm.NewOrm()
  70. sql := `UPDATE cygx_article_collect SET email=?,company_id=?,company_name=?,mobile=?,real_name=? WHERE user_id=? `
  71. _, err = o.Raw(sql, wxUser.Email, wxUser.CompanyId, wxUser.CompanyName, wxUser.Mobile, wxUser.RealName, wxUser.UserId).Exec()
  72. return
  73. }