voice_broadcast.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. package yb
  2. import (
  3. "github.com/rdlucklib/rdluck_tools/paging"
  4. "hongze/hz_crm_api/controllers"
  5. "hongze/hz_crm_api/models"
  6. "hongze/hz_crm_api/models/company"
  7. "hongze/hz_crm_api/models/system"
  8. "hongze/hz_crm_api/models/yb"
  9. "hongze/hz_crm_api/models/yb/response"
  10. "hongze/hz_crm_api/utils"
  11. "strconv"
  12. "strings"
  13. )
  14. // 音频播报板块
  15. type VoiceBroadcastController struct {
  16. controllers.BaseAuthController
  17. }
  18. // VoiceBroadcastList
  19. // @Title 获取语音播报统计列表
  20. // @Description 获取语音播报统计列表
  21. // @Param SectionId query int false "板块ID"
  22. // @Param VarietyId query int false "品种ID"
  23. // @Param AdminId query int false "管理员ID"
  24. // @Param ClickSort query int false "点击量排序:1-升序 2-降序"
  25. // @Param Title query string false "标题"
  26. // @Success 200 {object} response.BroadcastStatisticsResp
  27. // @router /voice/broadcast/list [get]
  28. func (this *VoiceBroadcastController) VoiceBroadcastList() {
  29. br := new(models.BaseResponse).Init()
  30. defer func() {
  31. this.Data["json"] = br
  32. this.ServeJSON()
  33. }()
  34. sysUser := this.SysUser
  35. if sysUser == nil {
  36. br.Msg = "请登录"
  37. br.ErrMsg = "请登录,SysUser Is Empty"
  38. br.Ret = 408
  39. return
  40. }
  41. // 筛选项-板块/品种/管理员/标题/点击量排序
  42. sectionId, _ := this.GetInt("SectionId")
  43. varietyId, _ := this.GetInt("VarietyId")
  44. adminId, _ := this.GetInt("AdminId")
  45. title := this.GetString("Title")
  46. clickSort, _ := this.GetInt("ClickSort")
  47. var pars []interface{}
  48. condition := ``
  49. if sectionId > 0 {
  50. condition += ` AND section_id = ?`
  51. pars = append(pars, sectionId)
  52. }
  53. if varietyId > 0 {
  54. condition += ` AND variety_id = ?`
  55. pars = append(pars, varietyId)
  56. }
  57. if adminId > 0 {
  58. // 获取对应管理员的微信用户信息
  59. wxUser, e := models.GetWxUserByAdminId(utils.USER_RECORD_PLATFORM_YB, adminId)
  60. if e != nil && e.Error() != utils.ErrNoRow() {
  61. br.Msg = "获取失败"
  62. br.ErrMsg = "获取管理员微信信息失败, Err: " + e.Error()
  63. return
  64. }
  65. if wxUser != nil && wxUser.UserId > 0 {
  66. condition += ` AND author_id = ?`
  67. pars = append(pars, wxUser.UserId)
  68. } else {
  69. condition += ` AND author_id = 0`
  70. }
  71. }
  72. if title != "" {
  73. keywords := "%" + title + "%"
  74. condition += ` AND broadcast_name LIKE ?`
  75. pars = append(pars, keywords)
  76. }
  77. // 点击量排序: 0-发布时间降序(默认) 1-升序 2-降序
  78. orderRule := `publish_time DESC`
  79. if clickSort == 1 {
  80. orderRule = `visit_count ASC`
  81. }
  82. if clickSort == 2 {
  83. orderRule = `visit_count DESC`
  84. }
  85. // 分页
  86. pageSize, _ := this.GetInt("PageSize")
  87. currentIndex, _ := this.GetInt("CurrentIndex")
  88. var startSize int
  89. if pageSize <= 0 {
  90. pageSize = utils.PageSize20
  91. }
  92. if currentIndex <= 0 {
  93. currentIndex = 1
  94. }
  95. startSize = paging.StartIndex(currentIndex, pageSize)
  96. total, list, err := yb.GetVoiceBroadcastCensusPageList(startSize, pageSize, condition, orderRule, pars)
  97. if err != nil {
  98. br.Msg = "获取失败"
  99. br.ErrMsg = "获取失败, Err: " + err.Error()
  100. return
  101. }
  102. // 管理员信息
  103. listLen := len(list)
  104. userIdArr := make([]int, 0)
  105. for i := 0; i < listLen; i++ {
  106. userIdArr = append(userIdArr, list[i].AuthorId)
  107. }
  108. userAdminNameMap := make(map[int]string, 0)
  109. if len(userIdArr) > 0 {
  110. relationList, e := system.GetAdminWxUserRelationByWxUserIds(utils.USER_RECORD_PLATFORM_YB, userIdArr)
  111. if e != nil {
  112. br.Msg = "获取失败"
  113. br.ErrMsg = "获取管理员信息失败, Err: " + e.Error()
  114. return
  115. }
  116. for _, r := range relationList {
  117. userAdminNameMap[r.UserId] = r.RealName
  118. }
  119. }
  120. for _, v := range list {
  121. v.Author = userAdminNameMap[v.AuthorId]
  122. }
  123. page := paging.GetPaging(currentIndex, pageSize, total)
  124. resp := response.BroadcastStatisticsResp{
  125. List: list,
  126. Paging: page,
  127. }
  128. br.Ret = 200
  129. br.Success = true
  130. br.Msg = "获取成功"
  131. br.Data = resp
  132. }
  133. // VoiceBroadcastDetail
  134. // @Title 获取语音播报统计详情
  135. // @Description 获取语音播报统计详情
  136. // @Param BroadcastId query int true "语音ID"
  137. // @Success 200 {object} response.BroadcastStatisticsResp
  138. // @router /voice/broadcast/deatil [get]
  139. func (this *VoiceBroadcastController) VoiceBroadcastDetail() {
  140. br := new(models.BaseResponse).Init()
  141. defer func() {
  142. this.Data["json"] = br
  143. this.ServeJSON()
  144. }()
  145. sysUser := this.SysUser
  146. if sysUser == nil {
  147. br.Msg = "请登录"
  148. br.ErrMsg = "请登录,SysUser Is Empty"
  149. br.Ret = 408
  150. return
  151. }
  152. broadcastId, _ := this.GetInt("BroadcastId")
  153. // 分页
  154. pageSize, _ := this.GetInt("PageSize")
  155. currentIndex, _ := this.GetInt("CurrentIndex")
  156. var startSize int
  157. if pageSize <= 0 {
  158. pageSize = utils.PageSize20
  159. }
  160. if currentIndex <= 0 {
  161. currentIndex = 1
  162. }
  163. startSize = paging.StartIndex(currentIndex, pageSize)
  164. total, list, err := yb.GetVoiceBroadcastDetailBySource(broadcastId, startSize, pageSize)
  165. if err != nil {
  166. br.Msg = "获取失败"
  167. br.ErrMsg = "获取失败, Err: " + err.Error()
  168. return
  169. }
  170. // 查询用户相关的客户信息
  171. listLen := len(list)
  172. userIdArr := make([]string, 0)
  173. for i := 0; i < listLen; i++ {
  174. userIdArr = append(userIdArr, strconv.Itoa(list[i].UserId))
  175. }
  176. userIds := strings.Join(userIdArr, ",")
  177. userCompanyMap := make(map[int]*company.CompanyUser)
  178. if userIds != "" {
  179. companyUserList, e := company.GetFiccCompanyUserByUserIds(userIds)
  180. if e != nil {
  181. br.Msg = "获取失败"
  182. br.ErrMsg = "获取客户信息失败, Err: " + e.Error()
  183. return
  184. }
  185. for _, v := range companyUserList {
  186. userCompanyMap[int(v.UserId)] = v
  187. }
  188. }
  189. respList := make([]*yb.VoiceBroadcastTotal, 0)
  190. for _, v := range list {
  191. item := new(yb.VoiceBroadcastTotal)
  192. if u, ok := userCompanyMap[v.UserId]; ok {
  193. item.RealName = u.RealName
  194. item.CompanyName = u.CompanyName
  195. item.CompanyStatus = u.Status
  196. }
  197. item.VisitCount = v.VisitCount
  198. item.Source = v.NewSource
  199. item.CreateTime = v.CreateTime
  200. respList = append(respList, item)
  201. }
  202. page := paging.GetPaging(currentIndex, pageSize, total)
  203. resp := response.BroadcastStatisticsResp{
  204. List: respList,
  205. Paging: page,
  206. }
  207. br.Ret = 200
  208. br.Success = true
  209. br.Msg = "获取成功"
  210. br.Data = resp
  211. }