bullet_chat.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package yb
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // BulletChat 弹幕
  7. type BulletChat struct {
  8. Id int `orm:"column(id);pk" description:"弹幕ID"`
  9. UserId int `description:"用户ID"`
  10. PrimaryId int `description:"视频社区/线上路演ID"`
  11. Content string `description:"弹幕内容"`
  12. Seconds float64 `descrption:"时间点(秒)"`
  13. Color string `description:"弹幕颜色"`
  14. Title string `description:"视频标题"`
  15. Source int `description:"来源: 1-视频社区; 2-线上路演"`
  16. SourceAgent int `description:"来源: 1-小程序; 2-小程序PC; 3-弘则研究公众号; 4-Web PC"`
  17. CreateTime time.Time `description:"发布时间"`
  18. ModifyTime time.Time `description:"更新时间"`
  19. OpAdminId int `description:"删除操作管理员ID"`
  20. IsDeleted int `description:"是否已删除: 0-否 1-是"`
  21. DeleteTime time.Time `description:"删除时间"`
  22. }
  23. func (item *BulletChat) TableName() string {
  24. return "yb_bullet_chat"
  25. }
  26. func (item *BulletChat) Add() (lastId int64, err error) {
  27. o := orm.NewOrm()
  28. lastId, err = o.Insert(item)
  29. if err != nil {
  30. return
  31. }
  32. item.Id = int(lastId)
  33. return
  34. }
  35. func (item *BulletChat) Update(cols []string) (err error) {
  36. o := orm.NewOrm()
  37. _, err = o.Update(item, cols...)
  38. return
  39. }
  40. // GetBulletChatById 主键获取弹幕
  41. func GetBulletChatById(id int) (item *BulletChat, err error) {
  42. o := orm.NewOrm()
  43. sql := `SELECT * FROM yb_bullet_chat WHERE id = ? LIMIT 1`
  44. err = o.Raw(sql, id).QueryRow(&item)
  45. return
  46. }
  47. // GetBulletChatPageList 获取弹幕分页列表
  48. func GetBulletChatPageList(condition string, pars []interface{}, order string, startSize, pageSize int) (total int, list []*BulletChat, err error) {
  49. o := orm.NewOrm()
  50. sql := `SELECT * FROM yb_bullet_chat WHERE is_deleted = 0 `
  51. sql += condition
  52. if order != "" {
  53. sql += order
  54. } else {
  55. sql += ` ORDER BY create_time DESC`
  56. }
  57. totalSQl := `SELECT COUNT(1) total FROM (` + sql + `) z`
  58. if err = o.Raw(totalSQl, pars).QueryRow(&total); err != nil {
  59. return
  60. }
  61. sql += ` LIMIT ?,?`
  62. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  63. return
  64. }