community_question.go 4.0 KB

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