yb_community_question.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package yb_community_question
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // CommunityQuestion 问答社区
  7. type CommunityQuestion struct {
  8. CommunityQuestionId int `orm:"column(community_question_id);pk" description:"问题ID"`
  9. UserId int `description:"提问用户ID"`
  10. UserOpenid string `description:"提问用户openid"`
  11. Mobile string `description:"用户手机号"`
  12. RealName string `description:"用户名"`
  13. QuestionContent string `description:"问题描述"`
  14. ReplierUserId int `description:"回复人的user_id"`
  15. ReplierOpenid string `description:"回复人openid"`
  16. ReplierAdminId int `description:"回复人关联的admin_id"`
  17. ReplierRealName string `description:"回复人姓名"`
  18. ReplierAvatar string `description:"回复人头像"`
  19. ResearchGroupFirstId int `description:"回复人研究方向一级分组ID"`
  20. ResearchGroupSecondId int `description:"回复人研究方向二级分组ID"`
  21. ResearchGroupFirstName string `description:"研究方向一级分组名称"`
  22. ResearchGroupSecondName string `description:"研究方向二级分组名称"`
  23. DistributeAdminId int `description:"分配人admin_id"`
  24. DistributeTime time.Time `description:"分配时间"`
  25. VarietyTagId int `description:"标签ID"`
  26. VarietyTagName string `description:"标签名称"`
  27. IsRead int `description:"用户是否已读 0-未读 1-已读"`
  28. ReplierIsRead int `description:"回复人是否已读 0-未读 1-已读"`
  29. ReplyStatus int `description:"状态 1-待分配 2-待回答 3-已回答"`
  30. MsgSendStatus int `description:"消息推送进度 0-待推送 1-已推送回答人 2-已推送提问人"`
  31. ReplyTime time.Time `description:"回复时间"`
  32. CreateTime time.Time `description:"提问时间"`
  33. ModifyTime time.Time `description:"修改时间"`
  34. IsDeleted int `description:"是否已删除 0-否 1-是"`
  35. DeleteTime time.Time `description:"删除时间"`
  36. StopReason string `description:"终止原因"`
  37. }
  38. type CommunityQuestionMore struct {
  39. CommunityQuestion
  40. ClickNum int `description:"点击量"`
  41. }
  42. func (item *CommunityQuestion) TableName() string {
  43. return "yb_community_question"
  44. }
  45. func (item *CommunityQuestion) Update(cols []string) (err error) {
  46. o := orm.NewOrm()
  47. _, err = o.Update(item, cols...)
  48. return
  49. }
  50. // GetQuestionById 主键获取提问
  51. func GetQuestionById(questionId int) (item *CommunityQuestion, err error) {
  52. o := orm.NewOrm()
  53. sql := `SELECT * FROM yb_community_question WHERE community_question_id = ? AND is_deleted = 0 LIMIT 1`
  54. err = o.Raw(sql, questionId).QueryRow(&item)
  55. return
  56. }
  57. // GetCommunityQuestionList 获取问答列表
  58. func GetCommunityQuestionList(condition string, pars []interface{}, startSize, pageSize int) (total int, list []*CommunityQuestionMore, err error) {
  59. o := orm.NewOrm()
  60. //汇总数据
  61. totalSQl := `SELECT COUNT(1) total FROM yb_community_question q WHERE q.is_deleted = 0 `
  62. totalSQl += condition
  63. if err = o.Raw(totalSQl, pars).QueryRow(&total); err != nil {
  64. return
  65. }
  66. // 列表数据
  67. sql := `SELECT q.* FROM yb_community_question q WHERE q.is_deleted = 0 `
  68. sql += condition
  69. sql += ` ORDER BY q.create_time DESC LIMIT ?,?`
  70. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  71. return
  72. }
  73. type CommunityQuestionCount struct {
  74. ReplyStatus int `json:"reply_status"`
  75. Total int `json:"total"`
  76. }
  77. // GetCommunityQuestionCount 根据状态获取问答数
  78. func GetCommunityQuestionCount() (list []*CommunityQuestionCount, err error) {
  79. o := orm.NewOrm()
  80. sql := `SELECT reply_status, COUNT(1) total FROM yb_community_question WHERE is_deleted = 0 GROUP BY reply_status`
  81. _, err = o.Raw(sql).QueryRows(&list)
  82. return
  83. }
  84. // DeleteQuestion (软)删除问题
  85. func DeleteQuestion(questionId int) (err error) {
  86. o := orm.NewOrm()
  87. sql := `UPDATE yb_community_question SET is_deleted = 1, delete_time = NOW() WHERE community_question_id = ? LIMIT 1`
  88. _, err = o.Raw(sql, questionId).Exec()
  89. return
  90. }
  91. // GetCommunityQuestionListByIds 根据问答id获取列表数据
  92. func GetCommunityQuestionListByIds(CommunityQuestionIds string) (list []*CommunityQuestion, err error) {
  93. o := orm.NewOrm()
  94. // 列表数据
  95. sql := `SELECT q.* FROM yb_community_question q WHERE q.is_deleted = 0 AND community_question_id in (` + CommunityQuestionIds + `)`
  96. _, err = o.Raw(sql).QueryRows(&list)
  97. return
  98. }