cygx_yanxuan_special_special_like.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. // 留言点赞
  8. type CygxYanxuanSpecialSpecialLike struct {
  9. YanxuanSpecialLikeId int `orm:"column(yanxuan_special_like_id);pk"`
  10. YanxuanSpecialId int `comment:"cygx_yanxuan_special 表主键ID"`
  11. UserId int `comment:"用户ID"`
  12. Mobile string `comment:"手机号"`
  13. Email string `comment:"邮箱"`
  14. CompanyId int `comment:"公司ID"`
  15. CompanyName string `comment:"公司名称"`
  16. RealName string `comment:"用户实际名称"`
  17. RegisterPlatform int `comment:"来源 1小程序,2:网页,5买方研选小程序,6:买方研选网页版"`
  18. CreateTime time.Time `comment:"创建时间"`
  19. ModifyTime time.Time `comment:"修改时间"`
  20. }
  21. type LikeCygxYanxuanSpecialSpecialLikeReq struct {
  22. YanxuanSpecialId int `comment:"专栏文章ID"`
  23. DoType int `comment:"0取消置顶,1置顶"`
  24. }
  25. // 新增
  26. func AddCygxCygxYanxuanSpecialSpecialLike(item *CygxYanxuanSpecialSpecialLike, authorUserId int) (err error) {
  27. o, err := orm.NewOrm().Begin()
  28. if err != nil {
  29. return
  30. }
  31. defer func() {
  32. fmt.Println(err)
  33. if err == nil {
  34. o.Commit()
  35. } else {
  36. o.Rollback()
  37. }
  38. }()
  39. _, err = o.Insert(item)
  40. if err != nil {
  41. return
  42. }
  43. sql := `UPDATE cygx_yanxuan_special SET like_count = like_count+1 WHERE id = ?`
  44. _, err = o.Raw(sql, item.YanxuanSpecialId).Exec()
  45. if err != nil {
  46. return
  47. }
  48. sql = `UPDATE cygx_yanxuan_special_author SET special_like_count = special_like_count+1 WHERE user_id = ?`
  49. _, err = o.Raw(sql, authorUserId).Exec()
  50. return
  51. }
  52. // 删除
  53. func DeleteCygxYanxuanSpecialSpecialLike(userId, yanxuanSpecialId, authorUserId int) (err error) {
  54. o, err := orm.NewOrm().Begin()
  55. if err != nil {
  56. return
  57. }
  58. defer func() {
  59. fmt.Println(err)
  60. if err == nil {
  61. o.Commit()
  62. } else {
  63. o.Rollback()
  64. }
  65. }()
  66. //o := orm.NewOrm()
  67. sql := ` DELETE FROM cygx_yanxuan_special_special_like WHERE user_id = ? AND yanxuan_special_id = ? `
  68. _, err = o.Raw(sql, userId, yanxuanSpecialId).Exec()
  69. if err != nil {
  70. return
  71. }
  72. sql = `UPDATE cygx_yanxuan_special SET like_count = like_count-1 WHERE id = ?`
  73. _, err = o.Raw(sql, yanxuanSpecialId).Exec()
  74. if err != nil {
  75. return
  76. }
  77. sql = `UPDATE cygx_yanxuan_special_author SET special_like_count = special_like_count-1 WHERE user_id = ?`
  78. _, err = o.Raw(sql, authorUserId).Exec()
  79. return
  80. }
  81. // 获取数量
  82. func GetCygxYanxuanSpecialSpecialLikeCountByUidYid(userId, yanxuanSpecialId int) (count int, err error) {
  83. o := orm.NewOrm()
  84. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_yanxuan_special_special_like WHERE user_id = ? AND yanxuan_special_id = ? `
  85. err = o.Raw(sqlCount, userId, yanxuanSpecialId).QueryRow(&count)
  86. return
  87. }
  88. func GetCygxYanxuanSpecialSpecialLikeList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxYanxuanSpecialMessageLike, err error) {
  89. o := orm.NewOrm()
  90. sql := `SELECT *
  91. FROM
  92. cygx_yanxuan_special_special_like
  93. WHERE 1 = 1 ` + condition
  94. sql += ` LIMIT ?,? `
  95. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  96. return
  97. }
  98. // GetCygxYanxuanSpecialMessageLikeByUser 根据用户ID获取所有点赞留言
  99. func GetCygxYanxuanSpecialSpecialLikeByUser(userId int) (items []*CygxYanxuanSpecialSpecialLike, err error) {
  100. o := orm.NewOrm()
  101. sql := `SELECT yanxuan_special_id FROM cygx_yanxuan_special_special_like WHERE 1 =1 AND user_id =? `
  102. _, err = o.Raw(sql, userId).QueryRows(&items)
  103. return
  104. }