micro_roadshow.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. "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 int false "筛选条件 0:全部 1:视频 2:音频"
  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.GetInt("Filter", 0)
  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. if list[i].Type == 3 && list[i].IndustryName != ""{
  122. list[i].Title = "5min"+"【"+ list[i].IndustryName +"】"+"逻辑解析"
  123. }
  124. }
  125. resp := new(models.MicroRoadShowListResp)
  126. page := paging.GetPaging(currentIndex, pageSize, total)
  127. resp.List = list
  128. resp.Paging = page
  129. br.Ret = 200
  130. br.Success = true
  131. br.Msg = "获取成功"
  132. br.Data = resp
  133. }
  134. // @Title 记录用户浏览音频回放接口
  135. // @Description 记录用户浏览音频回放接口
  136. // @Param request body models.ActivityIdRep true "type json string"
  137. // @Success Ret=200 {object} models.AppointmentResp
  138. // @router /videoHistory/add [post]
  139. func (this *MicroRoadShowController) VideoHistoryAdd() {
  140. br := new(models.BaseResponse).Init()
  141. defer func() {
  142. this.Data["json"] = br
  143. this.ServeJSON()
  144. }()
  145. user := this.User
  146. if user == nil {
  147. br.Msg = "请登录"
  148. br.ErrMsg = "请登录,用户信息为空"
  149. br.Ret = 408
  150. return
  151. }
  152. uid := user.UserId
  153. var req models.AddVideoHistoryReq
  154. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  155. if err != nil {
  156. br.Msg = "参数解析异常!"
  157. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  158. return
  159. }
  160. videoId := req.VideoId
  161. playSeconds := req.PlaySeconds
  162. sourceType := req.SourceType
  163. if sourceType == 0 {
  164. sourceType = 1
  165. }
  166. var sellerName string
  167. sellerName, err = models.GetCompanySellerName(user.CompanyId)
  168. if err != nil {
  169. br.Msg = "报名失败!"
  170. br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
  171. return
  172. }
  173. if sourceType == 1 {
  174. item := models.CygxMicroRoadshowVideoHistory{
  175. VideoId: videoId,
  176. UserId: uid,
  177. Mobile: user.Mobile,
  178. Email: user.Email,
  179. CompanyId: user.CompanyId,
  180. CompanyName: user.CompanyName,
  181. RealName: user.RealName,
  182. SellerName: sellerName,
  183. PlaySeconds: strconv.Itoa(playSeconds),
  184. CreateTime: time.Now(),
  185. ModifyTime: time.Now(),
  186. }
  187. if playSeconds != 0 {
  188. lastItem, err := models.GetLastCygxMicroRoadshowVideoHistory(videoId, user.UserId)
  189. if err != nil {
  190. br.Msg = "操作失败"
  191. br.ErrMsg = "操作失败,GetLastCygxMicroRoadshowVideoHistory Err:" + err.Error()
  192. return
  193. }
  194. err = models.UpdateLastCygxActivityVideoHistory(strconv.Itoa(playSeconds), lastItem.Id)
  195. if err != nil {
  196. br.Msg = "更新失败"
  197. br.ErrMsg = "更新失败,UpdateLastCygxActivityVideoHistory Err:" + err.Error()
  198. return
  199. }
  200. } else {
  201. err = models.AddCygxMicroRoadshowVideoHistory(&item)
  202. if err != nil {
  203. br.Msg = "操作失败"
  204. br.ErrMsg = "操作失败,Err:" + err.Error()
  205. return
  206. }
  207. err = models.UpdateCygxActivityVideoCounts(videoId)
  208. if err != nil {
  209. br.Msg = "更新失败"
  210. br.ErrMsg = "更新失败,Err:" + err.Error()
  211. return
  212. }
  213. }
  214. } else if sourceType == 2 {
  215. err = services.AddActivityVideoHistory(user, videoId)
  216. if err != nil {
  217. br.Msg = "更新失败"
  218. br.ErrMsg = "更新失败,AddActivityVideoHistory Err:" + err.Error()
  219. return
  220. }
  221. }
  222. br.Ret = 200
  223. br.Success = true
  224. br.Msg = "操作成功"
  225. return
  226. }