micro_roadshow.go 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hongze_clpt/models"
  6. "hongze/hongze_clpt/services"
  7. "hongze/hongze_clpt/utils"
  8. "strconv"
  9. "time"
  10. )
  11. // 微路演
  12. type MicroRoadShowController struct {
  13. BaseAuthController
  14. }
  15. // @Title 微路演列表
  16. // @Description 微路演列表接口
  17. // @Param PageSize query int true "每页数据条数"
  18. // @Param CurrentIndex query int true "当前页页码,从1开始"
  19. // @Param KeyWord query string false "搜索关键词"
  20. // @Param AudioId query int false "音频ID"
  21. // @Param VideoId query int false "视频ID"
  22. // @Param ActivityVideoId query int false "活动视频ID"
  23. // @Param Filter query string false "筛选条件 为空:全部 1:视频 2:音频 3:逻辑解析 4:路演回放 多个用 , 隔开"
  24. // @Success 200 {object} models.HomeListResp
  25. // @router /list [get]
  26. func (this *MicroRoadShowController) List() {
  27. br := new(models.BaseResponse).Init()
  28. defer func() {
  29. this.Data["json"] = br
  30. this.ServeJSON()
  31. }()
  32. user := this.User
  33. if user == nil {
  34. br.Msg = "请登录"
  35. br.ErrMsg = "请登录,用户信息为空"
  36. br.Ret = 408
  37. return
  38. }
  39. pageSize, _ := this.GetInt("PageSize")
  40. currentIndex, _ := this.GetInt("CurrentIndex")
  41. keywords := this.GetString("KeyWord")
  42. audioId, _ := this.GetInt("AudioId")
  43. videoId, _ := this.GetInt("VideoId")
  44. activityVideoId, _ := this.GetInt("ActivityVideoId")
  45. filter := this.GetString("Filter")
  46. if pageSize <= 0 {
  47. pageSize = utils.PageSize20
  48. }
  49. if currentIndex <= 0 {
  50. currentIndex = 1
  51. }
  52. // 微路演列表
  53. list, total, e := services.GetMicroRoadShowPageListV8(pageSize, currentIndex, audioId, videoId, activityVideoId, filter, keywords)
  54. if e != nil {
  55. br.Msg = "获取失败"
  56. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  57. return
  58. }
  59. // 用户权限
  60. authInfo, permissionArr, e := services.GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  61. if e != nil {
  62. br.Msg = "获取失败"
  63. br.ErrMsg = "获取用户权限失败, Err: " + e.Error()
  64. return
  65. }
  66. // 获取默认图配置
  67. audioMap, videoMap, audioShareMap, videoShareMap, e := services.GetMicroRoadShowDefaultImgConfig()
  68. if e != nil {
  69. br.Msg = "获取失败"
  70. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  71. return
  72. }
  73. for i := range list {
  74. // 权限
  75. au := new(models.UserPermissionAuthInfo)
  76. au.SellerName = authInfo.SellerName
  77. au.SellerMobile = authInfo.SellerMobile
  78. au.HasPermission = authInfo.HasPermission
  79. au.OperationMode = authInfo.OperationMode
  80. if au.HasPermission == 1 {
  81. // 非宏观权限进一步判断是否有权限
  82. if list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  83. au.HasPermission = 2
  84. }
  85. }
  86. // 无权限的弹框提示
  87. if au.HasPermission != 1 {
  88. if au.OperationMode == services.UserPermissionOperationModeCall {
  89. if list[i].Type == 1 {
  90. au.PopupMsg = services.UserPermissionPopupMsgCallActivity
  91. } else {
  92. au.PopupMsg = services.UserPermissionPopupMsgCallMicroVideo
  93. }
  94. } else {
  95. if list[i].Type == 1 {
  96. au.PopupMsg = services.UserPermissionPopupMsgApplyActivity
  97. } else {
  98. au.PopupMsg = services.UserPermissionPopupMsgApplyMicroVideo
  99. }
  100. }
  101. }
  102. list[i].AuthInfo = au
  103. list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
  104. // 默认图
  105. if list[i].BackgroundImg == "" {
  106. if list[i].Type == 1 {
  107. list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  108. } else {
  109. list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  110. }
  111. }
  112. // 分享图
  113. if list[i].ShareImg == "" {
  114. if list[i].Type == 1 {
  115. list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
  116. } else {
  117. list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
  118. }
  119. }
  120. }
  121. resp := new(models.MicroRoadShowListResp)
  122. page := paging.GetPaging(currentIndex, pageSize, total)
  123. resp.List = list
  124. resp.Paging = page
  125. br.Ret = 200
  126. br.Success = true
  127. br.Msg = "获取成功"
  128. br.Data = resp
  129. }
  130. // @Title 视频详情
  131. // @Description 时间线接口
  132. // @Param VideoId query int true "视频ID"
  133. // @Success 200 {object} models.IndustryVideoDetailResp
  134. // @router /detail [get]
  135. func (this *MicroRoadShowController) Detail() {
  136. br := new(models.BaseResponse).Init()
  137. defer func() {
  138. this.Data["json"] = br
  139. this.ServeJSON()
  140. }()
  141. user := this.User
  142. if user == nil {
  143. br.Msg = "请重新登录"
  144. br.Ret = 408
  145. return
  146. }
  147. videoId, _ := this.GetInt("VideoId")
  148. videoSimple, au, err := services.GetindustryVideoDetailById(user, videoId)
  149. if err != nil {
  150. br.Msg = "获取失败"
  151. br.ErrMsg = "获取用户权限失败, Err: " + err.Error()
  152. return
  153. }
  154. resp := new(models.IndustryVideoDetailResp)
  155. resp.IndustryVideo = videoSimple
  156. resp.AuthInfo = au
  157. br.Ret = 200
  158. br.Success = true
  159. br.Msg = "获取成功"
  160. br.Data = resp
  161. }
  162. // @Title 记录用户浏览音频回放接口
  163. // @Description 记录用户浏览音频回放接口
  164. // @Param request body models.ActivityIdRep true "type json string"
  165. // @Success Ret=200 {object} models.AddVideoHistoryReq
  166. // @router /videoHistory/add [post]
  167. func (this *MicroRoadShowController) VideoHistoryAdd() {
  168. br := new(models.BaseResponse).Init()
  169. defer func() {
  170. this.Data["json"] = br
  171. this.ServeJSON()
  172. }()
  173. user := this.User
  174. if user == nil {
  175. br.Msg = "请登录"
  176. br.ErrMsg = "请登录,用户信息为空"
  177. br.Ret = 408
  178. return
  179. }
  180. uid := user.UserId
  181. var req models.AddVideoHistoryReq
  182. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  183. if err != nil {
  184. br.Msg = "参数解析异常!"
  185. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  186. return
  187. }
  188. videoId := req.VideoId
  189. playSeconds := req.PlaySeconds
  190. var sellerName string
  191. sellerName, err = models.GetCompanySellerName(user.CompanyId)
  192. if err != nil {
  193. br.Msg = "报名失败!"
  194. br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
  195. return
  196. }
  197. item := models.CygxMicroRoadshowVideoHistory{
  198. VideoId: videoId,
  199. UserId: uid,
  200. Mobile: user.Mobile,
  201. Email: user.Email,
  202. CompanyId: user.CompanyId,
  203. CompanyName: user.CompanyName,
  204. RealName: user.RealName,
  205. SellerName: sellerName,
  206. PlaySeconds: strconv.Itoa(playSeconds),
  207. CreateTime: time.Now(),
  208. ModifyTime: time.Now(),
  209. }
  210. //if playSeconds != 0 {
  211. // lastItem, err := models.GetLastCygxMicroRoadshowVideoHistory(videoId, user.UserId)
  212. // if err != nil {
  213. // br.Msg = "操作失败"
  214. // br.ErrMsg = "操作失败,GetLastCygxMicroRoadshowVideoHistory Err:" + err.Error()
  215. // return
  216. // }
  217. // err = models.UpdateLastCygxActivityVideoHistory(strconv.Itoa(playSeconds), lastItem.Id)
  218. // if err != nil {
  219. // br.Msg = "更新失败"
  220. // br.ErrMsg = "更新失败,UpdateLastCygxActivityVideoHistory Err:" + err.Error()
  221. // return
  222. // }
  223. //} else {
  224. // err = models.AddCygxMicroRoadshowVideoHistory(&item)
  225. // if err != nil {
  226. // br.Msg = "操作失败"
  227. // br.ErrMsg = "操作失败,Err:" + err.Error()
  228. // return
  229. // }
  230. // err = models.UpdateCygxActivityVideoCounts(videoId)
  231. // if err != nil {
  232. // br.Msg = "更新失败"
  233. // br.ErrMsg = "更新失败,Err:" + err.Error()
  234. // return
  235. // }
  236. //}
  237. err = models.AddCygxMicroRoadshowVideoHistory(&item)
  238. if err != nil {
  239. br.Msg = "操作失败"
  240. br.ErrMsg = "操作失败,Err:" + err.Error()
  241. return
  242. }
  243. err = models.UpdateCygxActivityVideoCounts(videoId)
  244. if err != nil {
  245. br.Msg = "更新失败"
  246. br.ErrMsg = "更新失败,Err:" + err.Error()
  247. return
  248. }
  249. br.Ret = 200
  250. br.Success = true
  251. br.Msg = "操作成功"
  252. return
  253. }