yb_voice_broadcast_statistics.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. package yb
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. )
  5. type VoiceBroadcastStatistics struct {
  6. Id int `orm:"column(id);pk"`
  7. CompanyId int `description:"客户ID"`
  8. CompanyName string `description:"客户名称"`
  9. UserId int `description:"用户ID"`
  10. RealName string `description:"用户名称"`
  11. Mobile string `description:"用户手机号"`
  12. Email string `description:"电子邮箱"`
  13. CompanyStatus string `description:"客户状态"`
  14. Source int `description:"点击来源,1手机小程序,2pc小程序,3web端"`
  15. BroadcastId int `description:"语音ID"`
  16. BroadcastName string `description:"语音名称"`
  17. SectionId int `description:"语音分类ID"`
  18. SectionName string `description:"语音分类名称"`
  19. VarietyId int `description:"品种id"`
  20. VarietyName string `description:"品种名称"`
  21. AuthorId int `description:"作者id"`
  22. Author string `description:"语音管理员"`
  23. CreateTime string `description:"访问时间"`
  24. }
  25. // TableName 表名变更
  26. func (voiceBroadcastStatistics *VoiceBroadcastStatistics) TableName() string {
  27. return "yb_voice_broadcast_statistics"
  28. }
  29. type VoiceBroadcastTotal struct {
  30. CompanyId int `description:"客户ID"`
  31. CompanyName string `description:"客户名称"`
  32. UserId int `description:"用户ID"`
  33. RealName string `description:"用户名称"`
  34. Mobile string `description:"用户手机号"`
  35. Email string `description:"电子邮箱"`
  36. CompanyStatus string `description:"客户状态"`
  37. Source int `description:"点击来源,1手机小程序,2pc小程序,3web端"`
  38. BroadcastId int `description:"语音ID"`
  39. BroadcastName string `description:"语音名称"`
  40. SectionId int `description:"语音分类ID"`
  41. SectionName string `description:"语音分类名称"`
  42. VarietyId int `description:"品种id"`
  43. VarietyName string `description:"品种名称"`
  44. VisitCount int `description:"阅读量"`
  45. AuthorId int `description:"作者id"`
  46. Author string `description:"作者"`
  47. CreateTime string `description:"访问时间"`
  48. PublishTime string `description:"发布时间"`
  49. }
  50. // GetVoiceBroadcastCensusPageList 获取语音播报统计列表-分页
  51. func GetVoiceBroadcastCensusPageList(startSize, pageSize int, condition, orderRule string, pars []interface{}) (total int, list []*VoiceBroadcastTotal, err error) {
  52. o := orm.NewOrm()
  53. //sql := `SELECT *, COUNT(1) AS visit_count FROM yb_voice_broadcast_statistics WHERE 1=1`
  54. sql := `SELECT broadcast_id, broadcast_name, section_name, variety_name, author_id, publish_time, COUNT(1) AS visit_count FROM yb_voice_broadcast_statistics WHERE 1=1`
  55. sql += condition
  56. sql += ` GROUP BY broadcast_id`
  57. if orderRule != `` {
  58. sql += ` ORDER BY ` + orderRule
  59. }
  60. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) a `
  61. err = o.Raw(totalSql, pars).QueryRow(&total)
  62. if err != nil {
  63. return
  64. }
  65. sql += ` LIMIT ?,? `
  66. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  67. return
  68. }
  69. type VoiceBroadcastCensusDetail struct {
  70. UserId int `description:"用户ID" json:"user_id"`
  71. NewSource int `description:"点击来源,1手机小程序,2pc小程序,3web端" json:"new_source"`
  72. VisitCount int `description:"阅读量" json:"visit_count"`
  73. CreateTime string `description:"访问时间" json:"create_time"`
  74. }
  75. // GetVoiceBroadcastDetailBySource 获取语音播报统计详情
  76. func GetVoiceBroadcastDetailBySource(broadcastId, startSize, pageSize int) (total int, list []*VoiceBroadcastCensusDetail, err error) {
  77. o := orm.NewOrm()
  78. sql := `SELECT
  79. user_id,
  80. IF (source = 4,2,source) AS new_source,
  81. COUNT(1) AS visit_count,
  82. create_time
  83. FROM
  84. yb_voice_broadcast_statistics
  85. WHERE
  86. 1=1
  87. AND broadcast_id = ?
  88. GROUP BY
  89. user_id, new_source
  90. ORDER BY
  91. create_time DESC`
  92. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) a `
  93. err = o.Raw(totalSql, broadcastId).QueryRow(&total)
  94. if err != nil {
  95. return
  96. }
  97. sql += ` LIMIT ?,? `
  98. _, err = o.Raw(sql, broadcastId, startSize, pageSize).QueryRows(&list)
  99. return
  100. }
  101. func UpdateVoiceBroadcastName(id int, name string) (err error) {
  102. o := orm.NewOrm()
  103. sql := "UPDATE yb_voice_broadcast_statistics SET section_name=? WHERE section_id=? "
  104. _, err = o.Raw(sql, name, id).Exec()
  105. return
  106. }
  107. // GetVoiceBroadcastDeatilBysourceTwo 获取语音播报点击量详情
  108. func GetVoiceBroadcastDeatilBysourceTwo(broadcastId, startSize, pageSize int) (total int, list []*VoiceBroadcastTotal, err error) {
  109. o := orm.NewOrm()
  110. sql := ` SELECT *,COUNT(1) AS visit_count FROM yb_voice_broadcast_statistics WHERE broadcast_id=? AND source IN (2,4) GROUP BY user_id ORDER BY create_time DESC `
  111. totalSql := `select count(1) total from (` + sql + `) a `
  112. err = o.Raw(totalSql, broadcastId).QueryRow(&total)
  113. if err != nil {
  114. return
  115. }
  116. sql += ` LIMIT ?,? `
  117. _, err = o.Raw(sql, broadcastId, startSize, pageSize).QueryRows(&list)
  118. return
  119. }
  120. // UserVoiceBroadcastVisitCount 用户语音播报点击量
  121. type UserVoiceBroadcastVisitCount struct {
  122. VisitCount int `json:"visit_count"`
  123. BroadcastId int `json:"broadcast_id"`
  124. BroadcastName string `json:"broadcast_name"`
  125. NewSource int `json:"new_source"`
  126. RecentTime string `json:"recent_time"`
  127. }
  128. // GetVoiceBroadcastVisitCountByUserId 语音播报点击量统计-根据用户
  129. func GetVoiceBroadcastVisitCountByUserId(sectionId, userId, startSize, pageSize int, orderRule string) (total int, list []*UserVoiceBroadcastVisitCount, err error) {
  130. o := orm.NewOrm()
  131. sql := `SELECT COUNT(1) AS visit_count, broadcast_id, broadcast_name, IF(source=4,2,source) as new_source, MAX(create_time) AS recent_time
  132. FROM yb_voice_broadcast_statistics WHERE user_id = ? AND section_id = ?
  133. GROUP BY broadcast_id, new_source`
  134. if orderRule != `` {
  135. sql += ` ORDER BY ` + orderRule
  136. } else {
  137. sql += ` ORDER BY recent_time DESC`
  138. }
  139. totalSQL := `SELECT COUNT(1) total FROM (` + sql + `) z `
  140. err = o.Raw(totalSQL, sectionId, userId).QueryRow(&total)
  141. if err != nil {
  142. return
  143. }
  144. sql += ` LIMIT ?,?`
  145. _, err = o.Raw(sql, sectionId, userId, startSize, pageSize).QueryRows(&list)
  146. return
  147. }