micro_roadshow.go 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. var keyWordArr []string
  53. var err error
  54. if keywords != "" {
  55. keyWordArr, err = services.GetIndustryMapNameSliceV3(keywords)
  56. if err != nil {
  57. br.Msg = "获取失败"
  58. br.ErrMsg = "获取分词失败,GetIndustryMapNameSliceV3 Err: " + err.Error()
  59. return
  60. }
  61. keyWordArr = services.RemoveDuplicatesAndEmpty(keyWordArr)
  62. }
  63. var list []*models.MicroRoadShowPageList
  64. var total int
  65. var e error
  66. // 微路演列表
  67. list, total, e = services.GetMicroRoadShowPageListV8(pageSize, currentIndex, audioId, videoId, activityVideoId, filter, keywords)
  68. if e != nil {
  69. br.Msg = "获取失败"
  70. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  71. return
  72. }
  73. var pageSizeIk int
  74. //获取总的数量
  75. totalIk, e := services.CountMicroRoadShowPageListIkWord(audioId, videoId, activityVideoId, keyWordArr, filter)
  76. if e != nil {
  77. br.Msg = "获取失败"
  78. br.ErrMsg = "获取微路演联想词列表失败, Err: " + e.Error()
  79. return
  80. }
  81. //return
  82. pageSizeIk = totalIk - len(list)
  83. //处理IK分词部分的分页获取条数
  84. startSizeIk := utils.StartIndex(currentIndex, pageSize)
  85. startSizeIk = startSizeIk - total
  86. if startSizeIk < 0 {
  87. startSizeIk = 0
  88. }
  89. if pageSizeIk > 0 {
  90. lisIk, e := services.GetMicroRoadShowPageListIkWord(startSizeIk, pageSizeIk, audioId, videoId, activityVideoId, keyWordArr, filter, keywords)
  91. if e != nil {
  92. br.Msg = "获取失败"
  93. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  94. return
  95. }
  96. for _, item := range lisIk {
  97. list = append(list, item)
  98. }
  99. }
  100. // 用户权限
  101. authInfo, permissionArr, e := services.GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  102. if e != nil {
  103. br.Msg = "获取失败"
  104. br.ErrMsg = "获取用户权限失败, Err: " + e.Error()
  105. return
  106. }
  107. // 获取默认图配置
  108. audioMap, videoMap, audioShareMap, videoShareMap, e := services.GetMicroRoadShowDefaultImgConfig()
  109. if e != nil {
  110. br.Msg = "获取失败"
  111. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  112. return
  113. }
  114. for i := range list {
  115. // 权限
  116. au := new(models.UserPermissionAuthInfo)
  117. au.SellerName = authInfo.SellerName
  118. au.SellerMobile = authInfo.SellerMobile
  119. au.HasPermission = authInfo.HasPermission
  120. au.OperationMode = authInfo.OperationMode
  121. if au.HasPermission == 1 {
  122. // 非宏观权限进一步判断是否有权限
  123. if list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  124. au.HasPermission = 2
  125. }
  126. }
  127. // 无权限的弹框提示
  128. if au.HasPermission != 1 {
  129. if au.OperationMode == services.UserPermissionOperationModeCall {
  130. if list[i].Type == 1 {
  131. au.PopupMsg = services.UserPermissionPopupMsgCallActivity
  132. } else {
  133. au.PopupMsg = services.UserPermissionPopupMsgCallMicroVideo
  134. }
  135. } else {
  136. if list[i].Type == 1 {
  137. au.PopupMsg = services.UserPermissionPopupMsgApplyActivity
  138. } else {
  139. au.PopupMsg = services.UserPermissionPopupMsgApplyMicroVideo
  140. }
  141. }
  142. }
  143. list[i].AuthInfo = au
  144. list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
  145. // 默认图
  146. if list[i].BackgroundImg == "" {
  147. if list[i].Type == 1 {
  148. list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  149. } else {
  150. list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  151. }
  152. }
  153. // 分享图
  154. if list[i].ShareImg == "" {
  155. if list[i].Type == 1 {
  156. list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
  157. } else {
  158. list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
  159. }
  160. }
  161. }
  162. resp := new(models.MicroRoadShowListResp)
  163. page := paging.GetPaging(currentIndex, pageSize, totalIk)
  164. resp.List = list
  165. resp.Paging = page
  166. br.Ret = 200
  167. br.Success = true
  168. br.Msg = "获取成功"
  169. br.Data = resp
  170. }
  171. // @Title 视频详情
  172. // @Description 时间线接口
  173. // @Param VideoId query int true "视频ID"
  174. // @Success 200 {object} models.IndustryVideoDetailResp
  175. // @router /detail [get]
  176. func (this *MicroRoadShowController) Detail() {
  177. br := new(models.BaseResponse).Init()
  178. defer func() {
  179. this.Data["json"] = br
  180. this.ServeJSON()
  181. }()
  182. user := this.User
  183. if user == nil {
  184. br.Msg = "请重新登录"
  185. br.Ret = 408
  186. return
  187. }
  188. videoId, _ := this.GetInt("VideoId")
  189. videoSimple, au, err := services.GetindustryVideoDetailById(user, videoId)
  190. if err != nil {
  191. br.Msg = "获取失败"
  192. br.ErrMsg = "获取用户权限失败, Err: " + err.Error()
  193. return
  194. }
  195. resp := new(models.IndustryVideoDetailResp)
  196. resp.IndustryVideo = videoSimple
  197. resp.AuthInfo = au
  198. br.Ret = 200
  199. br.Success = true
  200. br.Msg = "获取成功"
  201. br.Data = resp
  202. }
  203. // @Title 记录用户浏览音频回放接口
  204. // @Description 记录用户浏览音频回放接口
  205. // @Param request body models.ActivityIdRep true "type json string"
  206. // @Success Ret=200 {object} models.AddVideoHistoryReq
  207. // @router /videoHistory/add [post]
  208. func (this *MicroRoadShowController) VideoHistoryAdd() {
  209. br := new(models.BaseResponse).Init()
  210. defer func() {
  211. this.Data["json"] = br
  212. this.ServeJSON()
  213. }()
  214. user := this.User
  215. if user == nil {
  216. br.Msg = "请登录"
  217. br.ErrMsg = "请登录,用户信息为空"
  218. br.Ret = 408
  219. return
  220. }
  221. uid := user.UserId
  222. var req models.AddVideoHistoryReq
  223. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  224. if err != nil {
  225. br.Msg = "参数解析异常!"
  226. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  227. return
  228. }
  229. videoId := req.VideoId
  230. playSeconds := req.PlaySeconds
  231. var sellerName string
  232. sellerName, err = models.GetCompanySellerName(user.CompanyId)
  233. if err != nil {
  234. br.Msg = "报名失败!"
  235. br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
  236. return
  237. }
  238. item := models.CygxMicroRoadshowVideoHistory{
  239. VideoId: videoId,
  240. UserId: uid,
  241. Mobile: user.Mobile,
  242. Email: user.Email,
  243. CompanyId: user.CompanyId,
  244. CompanyName: user.CompanyName,
  245. RealName: user.RealName,
  246. SellerName: sellerName,
  247. PlaySeconds: strconv.Itoa(playSeconds),
  248. CreateTime: time.Now(),
  249. ModifyTime: time.Now(),
  250. }
  251. //if playSeconds != 0 {
  252. // lastItem, err := models.GetLastCygxMicroRoadshowVideoHistory(videoId, user.UserId)
  253. // if err != nil {
  254. // br.Msg = "操作失败"
  255. // br.ErrMsg = "操作失败,GetLastCygxMicroRoadshowVideoHistory Err:" + err.Error()
  256. // return
  257. // }
  258. // err = models.UpdateLastCygxActivityVideoHistory(strconv.Itoa(playSeconds), lastItem.Id)
  259. // if err != nil {
  260. // br.Msg = "更新失败"
  261. // br.ErrMsg = "更新失败,UpdateLastCygxActivityVideoHistory Err:" + err.Error()
  262. // return
  263. // }
  264. //} else {
  265. // err = models.AddCygxMicroRoadshowVideoHistory(&item)
  266. // if err != nil {
  267. // br.Msg = "操作失败"
  268. // br.ErrMsg = "操作失败,Err:" + err.Error()
  269. // return
  270. // }
  271. // err = models.UpdateCygxActivityVideoCounts(videoId)
  272. // if err != nil {
  273. // br.Msg = "更新失败"
  274. // br.ErrMsg = "更新失败,Err:" + err.Error()
  275. // return
  276. // }
  277. //}
  278. err = models.AddCygxMicroRoadshowVideoHistory(&item)
  279. if err != nil {
  280. br.Msg = "操作失败"
  281. br.ErrMsg = "操作失败,Err:" + err.Error()
  282. return
  283. }
  284. err = models.UpdateCygxActivityVideoCounts(videoId)
  285. if err != nil {
  286. br.Msg = "更新失败"
  287. br.ErrMsg = "更新失败,Err:" + err.Error()
  288. return
  289. }
  290. br.Ret = 200
  291. br.Success = true
  292. br.Msg = "操作成功"
  293. return
  294. }