yb_community_question_like_tease.go 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. package yb
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // YbCommunityQuestionLikeTease 问答点赞/吐槽表
  7. type YbCommunityQuestionLikeTease struct {
  8. CommunityQuestionLikeTeaseID uint64 `orm:"column(community_question_like_tease_id);pk" description:"点赞/吐槽自增id"`
  9. UserId uint64 `orm:"column(user_id)" description:"用户id"`
  10. OpType int8 `orm:"column(op_type)" description:"类型. 1-点赞 2-吐槽"`
  11. Enabled int8 `orm:"column(enabled)" description:"状态. 0-无效数据(已取消点赞/吐槽) 1-有效数据(点赞/吐槽)"`
  12. CreateTime time.Time `orm:"column(create_time)" description:"创建时间"`
  13. ModifyTime time.Time `orm:"column(modify_time)" description:"修改时间"`
  14. CommunityQuestionID uint32 `gorm:"column(community_question_id)" description:"问答ID"`
  15. SourceAgent int8 `orm:"column(source_agent)" description:"点赞/吐槽入口来源,1:小程序,2:小程序pc, 4:web pc"`
  16. }
  17. // StatCommunityQuestionLikeTeaseItem 问答点赞/吐槽数据
  18. type StatCommunityQuestionLikeTeaseItem struct {
  19. CommunityQuestionId int `description:"问答id"`
  20. QuestionContent string `description:"问答内容"`
  21. Num int `description:"点赞/吐槽数"`
  22. CreateTime string `description:"提问时间"`
  23. ModifyTime string `description:"最新点赞时间"`
  24. VarietyTagId int `description:"品种标签ID"`
  25. VarietyClassifyTag string `description:"品种分类及标签"`
  26. }
  27. // GetYbCommunityQuestionLikeTeaseQuestion 根据条件查询点赞/吐槽相关的 问答id
  28. func GetYbCommunityQuestionLikeTeaseQuestion(opType int8, orderStr string, startSize, pageSize int) (list []*StatCommunityQuestionLikeTeaseItem, err error) {
  29. o := orm.NewOrm()
  30. sql := `SELECT
  31. count( 1 ) AS num,
  32. a.community_question_id,
  33. MAX(a.modify_time) as modify_time,b.question_content,b.create_time
  34. FROM
  35. yb_community_question_like_tease a
  36. join yb_community_question b on a.community_question_id=b.community_question_id
  37. WHERE
  38. a.enabled = 1 AND b.is_deleted = 0 AND a.op_type = ? AND a.source = 1
  39. GROUP BY a.community_question_id ORDER BY `
  40. sql += ` ` + orderStr
  41. sql += ` ,modify_time desc`
  42. sql += ` LIMIT ?,?`
  43. _, err = o.Raw(sql, opType, startSize, pageSize).QueryRows(&list)
  44. return
  45. }
  46. // GetYbCommunityQuestionLikeTeaseTotal 根据条件查询点赞/吐槽 数据汇总数
  47. func GetYbCommunityQuestionLikeTeaseTotal(opType int8) (total int64, err error) {
  48. o := orm.NewOrm()
  49. sql := `SELECT
  50. count( 1 ) AS like_tease_num,
  51. a.community_question_id,
  52. MAX(a.modify_time) as modify_time,b.question_content,b.create_time
  53. FROM
  54. yb_community_question_like_tease a
  55. join yb_community_question b on a.community_question_id=b.community_question_id
  56. WHERE
  57. a.enabled = 1 AND b.is_deleted = 0 AND a.op_type = ?
  58. GROUP BY a.community_question_id `
  59. sql = `select count(1) total from (` + sql + `) tmp `
  60. err = o.Raw(sql, opType).QueryRow(&total)
  61. return
  62. }
  63. // LikeTeaseListItem 问答详情点赞/吐槽用户列表详情数据
  64. type LikeTeaseListItem struct {
  65. CommunityQuestionLikeTeaseId uint64 `description:"点赞ID"`
  66. NickName string `description:"用户名称"`
  67. RealName string `description:"用户真实姓名"`
  68. CompanyId int `description:"客户id"`
  69. CompanyName string `description:"客户名称"`
  70. CompanyFiccStatus string `description:"客户ficc状态"`
  71. UserId uint64 `description:"用户id"`
  72. SourceAgent int8 `description:"留言入口来源,1:小程序,2:pc"`
  73. ModifyTime string `description:"修改时间"`
  74. }
  75. // GetYbCommunityQuestionLikeTeaseQuestionListById 根据问答ID,查询点赞/吐槽列表
  76. func GetYbCommunityQuestionLikeTeaseQuestionListById(CommunityQuestionId, opType, source, startSize, pageSize int) (total int, list []*LikeTeaseListItem, err error) {
  77. o := orm.NewOrm()
  78. sql := `SELECT
  79. community_question_like_tease_id,
  80. user_id,
  81. source_agent,
  82. modify_time
  83. FROM
  84. yb_community_question_like_tease
  85. WHERE
  86. community_question_id =? AND op_type =? AND enabled = 1 AND source = ? `
  87. totalSql := `SELECT count(1) total FROM (` + sql + `) z `
  88. if err = o.Raw(totalSql, CommunityQuestionId, opType, source).QueryRow(&total); err != nil {
  89. return
  90. }
  91. sql += ` ORDER BY modify_time DESC, community_question_like_tease_id DESC`
  92. sql += ` LIMIT ?,?`
  93. _, err = o.Raw(sql, CommunityQuestionId, opType, source, startSize, pageSize).QueryRows(&list)
  94. return
  95. }
  96. // GetYbCommunityVideoLikeTeaseTotal 根据条件查询视频点赞/吐槽 数据汇总数
  97. func GetYbCommunityVideoLikeTeaseTotal(opType int8) (total int64, err error) {
  98. o := orm.NewOrm()
  99. sql := `SELECT
  100. count(1) AS like_tease_num,
  101. a.community_question_id,
  102. MAX(a.modify_time) AS modify_time,
  103. b.title AS question_content,
  104. b.create_time
  105. FROM
  106. yb_community_question_like_tease a
  107. JOIN yb_community_video b ON a.community_question_id = b.community_video_id
  108. WHERE
  109. a.enabled = 1 AND b.is_deleted = 0 AND a.op_type = ? AND a.source = 2
  110. GROUP BY
  111. a.community_question_id `
  112. sql = `select count(1) total from (` + sql + `) tmp `
  113. err = o.Raw(sql, opType).QueryRow(&total)
  114. return
  115. }
  116. // GetYbCommunityVideoLikeTeaseList 根据条件查询点赞/吐槽相关的 视频信息
  117. func GetYbCommunityVideoLikeTeaseList(opType int8, orderStr string, startSize, pageSize int) (list []*StatCommunityQuestionLikeTeaseItem, err error) {
  118. o := orm.NewOrm()
  119. sql := `SELECT
  120. count(1) AS num,
  121. a.community_question_id,
  122. MAX(a.modify_time) AS modify_time,
  123. b.title AS question_content,
  124. b.create_time,
  125. b.variety_tag_id
  126. FROM
  127. yb_community_question_like_tease a
  128. JOIN yb_community_video b ON a.community_question_id = b.community_video_id
  129. WHERE
  130. a.enabled = 1 AND b.is_deleted = 0 AND a.op_type = ? AND a.source = 2
  131. GROUP BY
  132. a.community_question_id ORDER BY `
  133. sql += ` ` + orderStr
  134. sql += ` ,modify_time desc`
  135. sql += ` LIMIT ?,?`
  136. _, err = o.Raw(sql, opType, startSize, pageSize).QueryRows(&list)
  137. return
  138. }
  139. // GetYbRoadVideoLikeTeaseTotal 根据条件查询线上路演点赞/吐槽 数据汇总数
  140. func GetYbRoadVideoLikeTeaseTotal(opType int8) (total int64, err error) {
  141. o := orm.NewOrm()
  142. sql := `SELECT
  143. count(1) AS like_tease_num,
  144. a.community_question_id,
  145. MAX(a.modify_time) AS modify_time,
  146. b.title AS question_content,
  147. b.create_time
  148. FROM
  149. yb_community_question_like_tease a
  150. JOIN yb_road_video b ON a.community_question_id = b.road_video_id
  151. WHERE
  152. a.enabled = 1 AND b.is_deleted = 0 AND a.op_type = ? AND a.source = 3
  153. GROUP BY
  154. a.community_question_id `
  155. sql = `select count(1) total from (` + sql + `) tmp `
  156. err = o.Raw(sql, opType).QueryRow(&total)
  157. return
  158. }
  159. // GetYbRoadVideoLikeTeaseList 根据条件查询点赞/吐槽相关的 线上路演信息
  160. func GetYbRoadVideoLikeTeaseList(opType int8, orderStr string, startSize, pageSize int) (list []*StatCommunityQuestionLikeTeaseItem, err error) {
  161. o := orm.NewOrm()
  162. sql := `SELECT
  163. count(1) AS num,
  164. a.community_question_id,
  165. MAX(a.modify_time) AS modify_time,
  166. b.title AS question_content,
  167. b.create_time,
  168. b.chart_permission_ids AS variety_classify_tag
  169. FROM
  170. yb_community_question_like_tease a
  171. JOIN yb_road_video b ON a.community_question_id = b.road_video_id
  172. WHERE
  173. a.enabled = 1 AND b.is_deleted = 0 AND a.op_type = ? AND a.source = 3
  174. GROUP BY
  175. a.community_question_id ORDER BY `
  176. sql += ` ` + orderStr
  177. sql += ` ,modify_time desc`
  178. sql += ` LIMIT ?,?`
  179. _, err = o.Raw(sql, opType, startSize, pageSize).QueryRows(&list)
  180. return
  181. }