micro_roadshow.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hongze_cygx/models"
  6. "hongze/hongze_cygx/services"
  7. "hongze/hongze_cygx/utils"
  8. "time"
  9. )
  10. // 微路演
  11. type MicroRoadShowController struct {
  12. BaseAuthController
  13. }
  14. // @Title 微路演列表
  15. // @Description 微路演列表接口
  16. // @Param PageSize query int true "每页数据条数"
  17. // @Param CurrentIndex query int true "当前页页码,从1开始"
  18. // @Param KeyWord query string false "搜索关键词"
  19. // @Param AudioId query int false "音频ID"
  20. // @Param VideoId query int false "视频ID"
  21. // @Success 200 {object} models.HomeListResp
  22. // @router /list [get]
  23. func (this *MicroRoadShowController) List() {
  24. br := new(models.BaseResponse).Init()
  25. defer func() {
  26. this.Data["json"] = br
  27. this.ServeJSON()
  28. }()
  29. user := this.User
  30. if user == nil {
  31. br.Msg = "请登录"
  32. br.ErrMsg = "请登录,用户信息为空"
  33. br.Ret = 408
  34. return
  35. }
  36. pageSize, _ := this.GetInt("PageSize")
  37. currentIndex, _ := this.GetInt("CurrentIndex")
  38. keywords := this.GetString("KeyWord")
  39. audioId, _ := this.GetInt("AudioId")
  40. videoId, _ := this.GetInt("VideoId")
  41. if pageSize <= 0 {
  42. pageSize = utils.PageSize20
  43. }
  44. if currentIndex <= 0 {
  45. currentIndex = 1
  46. }
  47. // 微路演列表
  48. list, total, e := services.GetMicroRoadShowPageList(pageSize, currentIndex, audioId, videoId, keywords)
  49. if e != nil {
  50. br.Msg = "获取失败"
  51. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  52. return
  53. }
  54. // 用户权限
  55. authInfo, permissionArr, e := services.GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  56. if e != nil {
  57. br.Msg = "获取失败"
  58. br.ErrMsg = "获取用户权限失败, Err: " + e.Error()
  59. return
  60. }
  61. // 获取默认图配置
  62. audioMap, videoMap, e := services.GetMicroRoadShowDefaultImgConfig()
  63. if e != nil {
  64. br.Msg = "获取失败"
  65. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  66. return
  67. }
  68. for i := range list {
  69. // 权限
  70. au := new(models.UserPermissionAuthInfo)
  71. au.SellerName = authInfo.SellerName
  72. au.SellerMobile = authInfo.SellerMobile
  73. au.HasPermission = authInfo.HasPermission
  74. if authInfo.HasPermission == 1 {
  75. if !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  76. au.HasPermission = 2
  77. }
  78. }
  79. if authInfo.HasPermission == 2 {
  80. if list[i].Type == 1 {
  81. au.PopupMsg = services.UserPermissionPopupMsgCallActivity
  82. } else {
  83. au.PopupMsg = services.UserPermissionPopupMsgCallMicroVideo
  84. }
  85. }
  86. if authInfo.HasPermission == 3 {
  87. if list[i].Type == 1 {
  88. au.PopupMsg = services.UserPermissionPopupMsgApplyActivity
  89. } else {
  90. au.PopupMsg = services.UserPermissionPopupMsgApplyMicroVideo
  91. }
  92. }
  93. list[i].AuthInfo = au
  94. // 默认图
  95. if list[i].BackgroundImg == "" {
  96. if list[i].Type == 1 {
  97. list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  98. } else {
  99. list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  100. }
  101. }
  102. }
  103. resp := new(models.MicroRoadShowListResp)
  104. page := paging.GetPaging(currentIndex, pageSize, total)
  105. resp.List = list
  106. resp.Paging = page
  107. br.Ret = 200
  108. br.Success = true
  109. br.Msg = "获取成功"
  110. br.Data = resp
  111. }
  112. // @Title 记录用户浏览音频回放接口
  113. // @Description 记录用户浏览音频回放接口
  114. // @Param request body models.ActivityIdRep true "type json string"
  115. // @Success Ret=200 {object} models.AppointmentResp
  116. // @router /videoHistory/add [post]
  117. func (this *MicroRoadShowController) VideoHistoryAdd() {
  118. br := new(models.BaseResponse).Init()
  119. defer func() {
  120. this.Data["json"] = br
  121. this.ServeJSON()
  122. }()
  123. user := this.User
  124. if user == nil {
  125. br.Msg = "请登录"
  126. br.ErrMsg = "请登录,用户信息为空"
  127. br.Ret = 408
  128. return
  129. }
  130. uid := user.UserId
  131. var req models.AddVideoHistoryReq
  132. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  133. if err != nil {
  134. br.Msg = "参数解析异常!"
  135. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  136. return
  137. }
  138. videoId := req.VideoId
  139. playSeconds := req.PlaySeconds
  140. var sellerName string
  141. sellerName, err = models.GetCompanySellerName(user.CompanyId)
  142. if err != nil {
  143. br.Msg = "报名失败!"
  144. br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
  145. return
  146. }
  147. item := models.CygxMicroRoadshowVideoHistory{
  148. VideoId: videoId,
  149. UserId: uid,
  150. Mobile: user.Mobile,
  151. Email: user.Email,
  152. CompanyId: user.CompanyId,
  153. CompanyName: user.CompanyName,
  154. RealName: user.RealName,
  155. SellerName: sellerName,
  156. PlaySeconds: playSeconds,
  157. CreateTime: time.Now(),
  158. ModifyTime: time.Now(),
  159. }
  160. if playSeconds != "" {
  161. lastItem, err := models.GetLastCygxMicroRoadshowVideoHistory(videoId, user.UserId)
  162. if err != nil {
  163. br.Msg = "操作失败"
  164. br.ErrMsg = "操作失败,GetLastCygxMicroRoadshowVideoHistory Err:" + err.Error()
  165. return
  166. }
  167. err = models.UpdateLastCygxActivityVoiceHistory(playSeconds, lastItem.Id)
  168. if err != nil {
  169. br.Msg = "更新失败"
  170. br.ErrMsg = "更新失败,UpdateLastCygxActivityVoiceHistory Err:" + err.Error()
  171. return
  172. }
  173. } else {
  174. err = models.AddCygxMicroRoadshowVideoHistory(&item)
  175. if err != nil {
  176. br.Msg = "操作失败"
  177. br.ErrMsg = "操作失败,Err:" + err.Error()
  178. return
  179. }
  180. }
  181. br.Ret = 200
  182. br.Success = true
  183. br.Msg = "操作成功"
  184. return
  185. }