cygx_yanxuan_special_message_like.go 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. // 留言点赞
  8. type CygxYanxuanSpecialMessageLike struct {
  9. MessageLikeId int `orm:"column(message_like_id);pk"`
  10. MessageId int `comment:"留言消息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. // 新增
  22. func AddCygxYanxuanSpecialMessageLike(item *CygxYanxuanSpecialMessageLike) (err error) {
  23. o, err := orm.NewOrm().Begin()
  24. if err != nil {
  25. return
  26. }
  27. defer func() {
  28. fmt.Println(err)
  29. if err == nil {
  30. o.Commit()
  31. } else {
  32. o.Rollback()
  33. }
  34. }()
  35. _, err = o.Insert(item)
  36. if err != nil {
  37. return
  38. }
  39. sql := `UPDATE cygx_yanxuan_special_message SET like_count = like_count+1 WHERE message_id = ?`
  40. _, err = o.Raw(sql, item.MessageId).Exec()
  41. return
  42. }
  43. // 删除
  44. func DeleteCygxYanxuanSpecialMessageLike(userId, messageId int) (err error) {
  45. o, err := orm.NewOrm().Begin()
  46. if err != nil {
  47. return
  48. }
  49. defer func() {
  50. fmt.Println(err)
  51. if err == nil {
  52. o.Commit()
  53. } else {
  54. o.Rollback()
  55. }
  56. }()
  57. sql := ` DELETE FROM cygx_yanxuan_special_message_like WHERE user_id = ? AND message_id = ? `
  58. _, err = o.Raw(sql, userId, messageId).Exec()
  59. if err != nil {
  60. return
  61. }
  62. sql = `UPDATE cygx_yanxuan_special_message SET like_count = like_count-1 WHERE message_id = ?`
  63. _, err = o.Raw(sql, messageId).Exec()
  64. return
  65. }
  66. // 获取数量
  67. func GetCygxYanxuanSpecialMessageLikeCountByUidMid(userId, messageId int) (count int, err error) {
  68. o := orm.NewOrm()
  69. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_yanxuan_special_message_like WHERE user_id = ? AND message_id = ? `
  70. err = o.Raw(sqlCount, userId, messageId).QueryRow(&count)
  71. return
  72. }
  73. func GetCygxYanxuanSpecialMessageLikeList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxYanxuanSpecialMessageLike, err error) {
  74. o := orm.NewOrm()
  75. sql := `SELECT *
  76. FROM
  77. cygx_yanxuan_special_message_like
  78. WHERE 1 = 1 ` + condition
  79. sql += ` LIMIT ?,? `
  80. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  81. return
  82. }
  83. // GetCygxYanxuanSpecialMessageLikeByUser 根据用户ID获取所有点赞留言
  84. func GetCygxYanxuanSpecialMessageLikeByUser(userId int) (items []*CygxYanxuanSpecialMessageLike, err error) {
  85. o := orm.NewOrm()
  86. sql := `SELECT message_id FROM cygx_yanxuan_special_message_like WHERE 1 =1 AND user_id =? `
  87. _, err = o.Raw(sql, userId).QueryRows(&items)
  88. return
  89. }