micro_roadshow.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  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. "strings"
  10. "time"
  11. )
  12. // 微路演
  13. type MicroRoadShowController struct {
  14. BaseAuthController
  15. }
  16. // @Title 微路演列表
  17. // @Description 微路演列表接口
  18. // @Param PageSize query int true "每页数据条数"
  19. // @Param CurrentIndex query int true "当前页页码,从1开始"
  20. // @Param KeyWord query string false "搜索关键词"
  21. // @Param AudioId query int false "音频ID"
  22. // @Param VideoId query int false "视频ID"
  23. // @Param AudioIds query string false "活动音频IDs"
  24. // @Param ActivityVideoIds query string false "活动视频IDs"
  25. // @Param VideoIds query string false "视频IDs"
  26. // @Param ActivityVideoId query int false "活动视频ID"
  27. // @Param Filter query string false "筛选条件 为空:全部 1:视频 2:音频 3:逻辑解析 4:路演回放 多个用 , 隔开"
  28. // @Success 200 {object} models.HomeListResp
  29. // @router /list [get]
  30. func (this *MicroRoadShowController) List() {
  31. br := new(models.BaseResponse).Init()
  32. defer func() {
  33. this.Data["json"] = br
  34. this.ServeJSON()
  35. }()
  36. user := this.User
  37. if user == nil {
  38. br.Msg = "请登录"
  39. br.ErrMsg = "请登录,用户信息为空"
  40. br.Ret = 408
  41. return
  42. }
  43. pageSize, _ := this.GetInt("PageSize")
  44. currentIndex, _ := this.GetInt("CurrentIndex")
  45. keywords := this.GetString("KeyWord")
  46. audioId, _ := this.GetInt("AudioId")
  47. videoId, _ := this.GetInt("VideoId")
  48. audioIds := this.GetString("AudioIds")
  49. videoIds := this.GetString("VideoIds")
  50. activityVideoIds := this.GetString("ActivityVideoIds")
  51. activityVideoId, _ := this.GetInt("ActivityVideoId")
  52. filter := this.GetString("Filter")
  53. if pageSize <= 0 {
  54. pageSize = utils.PageSize20
  55. }
  56. if currentIndex <= 0 {
  57. currentIndex = 1
  58. }
  59. var keyWordArr []string
  60. var err error
  61. if keywords != "" {
  62. keyWordArr, err = services.GetIndustryMapNameSliceV3(keywords)
  63. if err != nil {
  64. br.Msg = "获取失败"
  65. br.ErrMsg = "获取分词失败,GetIndustryMapNameSliceV3 Err: " + err.Error()
  66. return
  67. }
  68. keyWordArr = services.RemoveDuplicatesAndEmpty(keyWordArr)
  69. }
  70. var list []*models.MicroRoadShowPageList
  71. var total int
  72. var e error
  73. // 微路演列表
  74. list, total, e = services.GetMicroRoadShowPageListV8(pageSize, currentIndex, audioId, videoId, activityVideoId, filter, keywords, audioIds, videoIds, activityVideoIds)
  75. if e != nil {
  76. br.Msg = "获取失败"
  77. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  78. return
  79. }
  80. if keywords != "" {
  81. var pageSizeIk int
  82. //获取总的数量
  83. totalIk, e := services.CountMicroRoadShowPageListIkWord(audioId, videoId, activityVideoId, keyWordArr, filter, audioIds, videoIds, activityVideoIds)
  84. if e != nil {
  85. br.Msg = "获取失败"
  86. br.ErrMsg = "获取微路演联想词列表失败, Err: " + e.Error()
  87. return
  88. }
  89. pageSizeIk = totalIk - len(list)
  90. //处理IK分词部分的分页获取条数
  91. startSizeIk := utils.StartIndex(currentIndex, pageSize)
  92. startSizeIk = startSizeIk - total
  93. if startSizeIk < 0 {
  94. startSizeIk = 0
  95. }
  96. if pageSizeIk > 0 {
  97. lisIk, e := services.GetMicroRoadShowPageListIkWord(startSizeIk, pageSizeIk, audioId, videoId, activityVideoId, keyWordArr, filter, audioIds, videoIds, activityVideoIds, keywords)
  98. if e != nil {
  99. br.Msg = "获取失败"
  100. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  101. return
  102. }
  103. for _, item := range lisIk {
  104. list = append(list, item)
  105. }
  106. }
  107. total = totalIk
  108. }
  109. userId := user.UserId
  110. listMycollect, err := models.GetUserMicroRoadshowCollectList(userId)
  111. if err != nil {
  112. br.Msg = "获取数据失败"
  113. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  114. return
  115. }
  116. mapaudioIds := make(map[int]int) //活动音频
  117. mapvideoIds := make(map[int]int) // 微路演视频
  118. mapactivityVideoIds := make(map[int]int) // 活动视频
  119. for _, item := range listMycollect {
  120. if item.ActivityVoiceId > 0 {
  121. mapaudioIds[item.ActivityVoiceId] = item.ActivityVoiceId
  122. } else if item.VideoId > 0 {
  123. mapvideoIds[item.VideoId] = item.VideoId
  124. } else if item.ActivityVideoId > 0 {
  125. mapactivityVideoIds[item.ActivityVoiceId] = item.ActivityVoiceId
  126. }
  127. }
  128. for _, item := range list {
  129. if item.Type == 1 {
  130. //音频
  131. if mapaudioIds[item.Id] > 0 {
  132. item.IsCollect = true
  133. }
  134. } else if item.Type == 2 {
  135. //活动视频
  136. if mapactivityVideoIds[item.Id] > 0 {
  137. item.IsCollect = true
  138. }
  139. } else if item.Type == 3 {
  140. //微路演视频
  141. if mapvideoIds[item.Id] > 0 {
  142. item.IsCollect = true
  143. }
  144. }
  145. }
  146. // 用户权限
  147. authInfo, permissionArr, e := services.GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  148. if e != nil {
  149. br.Msg = "获取失败"
  150. br.ErrMsg = "获取用户权限失败, Err: " + e.Error()
  151. return
  152. }
  153. // 获取默认图配置
  154. audioMap, videoMap, audioShareMap, videoShareMap, e := services.GetMicroRoadShowDefaultImgConfig()
  155. if e != nil {
  156. br.Msg = "获取失败"
  157. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  158. return
  159. }
  160. for i := range list {
  161. // 权限
  162. au := new(models.UserPermissionAuthInfo)
  163. au.SellerName = authInfo.SellerName
  164. au.SellerMobile = authInfo.SellerMobile
  165. au.HasPermission = authInfo.HasPermission
  166. au.OperationMode = authInfo.OperationMode
  167. if au.HasPermission == 1 {
  168. // 非宏观权限进一步判断是否有权限
  169. if list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  170. au.HasPermission = 2
  171. }
  172. }
  173. // 无权限的弹框提示
  174. if au.HasPermission != 1 {
  175. if au.OperationMode == services.UserPermissionOperationModeCall {
  176. if list[i].Type == 1 {
  177. au.PopupMsg = services.UserPermissionPopupMsgCallActivity
  178. } else {
  179. au.PopupMsg = services.UserPermissionPopupMsgCallMicroVideo
  180. }
  181. } else {
  182. if list[i].Type == 1 {
  183. au.PopupMsg = services.UserPermissionPopupMsgApplyActivity
  184. } else {
  185. au.PopupMsg = services.UserPermissionPopupMsgApplyMicroVideo
  186. }
  187. }
  188. }
  189. list[i].AuthInfo = au
  190. list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
  191. // 默认图
  192. if list[i].BackgroundImg == "" {
  193. if list[i].Type == 1 {
  194. list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  195. } else {
  196. list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  197. }
  198. }
  199. // 分享图
  200. if list[i].ShareImg == "" {
  201. if list[i].Type == 1 {
  202. list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
  203. } else {
  204. list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
  205. }
  206. }
  207. }
  208. if len(list) == 0 {
  209. list = make([]*models.MicroRoadShowPageList, 0)
  210. }
  211. resp := new(models.MicroRoadShowListResp)
  212. page := paging.GetPaging(currentIndex, pageSize, total)
  213. resp.List = list
  214. resp.Paging = page
  215. br.Ret = 200
  216. br.Success = true
  217. br.Msg = "获取成功"
  218. br.Data = resp
  219. }
  220. // @Title 记录用户浏览音频回放接口
  221. // @Description 记录用户浏览音频回放接口
  222. // @Param request body models.ActivityIdRep true "type json string"
  223. // @Success Ret=200 {object} models.AppointmentResp
  224. // @router /videoHistory/add [post]
  225. func (this *MicroRoadShowController) VideoHistoryAdd() {
  226. br := new(models.BaseResponse).Init()
  227. defer func() {
  228. this.Data["json"] = br
  229. this.ServeJSON()
  230. }()
  231. user := this.User
  232. if user == nil {
  233. br.Msg = "请登录"
  234. br.ErrMsg = "请登录,用户信息为空"
  235. br.Ret = 408
  236. return
  237. }
  238. uid := user.UserId
  239. var req models.AddVideoHistoryReq
  240. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  241. if err != nil {
  242. br.Msg = "参数解析异常!"
  243. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  244. return
  245. }
  246. videoId := req.VideoId
  247. playSeconds := req.PlaySeconds
  248. sourceType := req.SourceType
  249. if sourceType == 0 {
  250. sourceType = 1
  251. }
  252. var sellerName string
  253. sellerName, err = models.GetCompanySellerName(user.CompanyId)
  254. if err != nil {
  255. br.Msg = "报名失败!"
  256. br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
  257. return
  258. }
  259. if sourceType == 1 {
  260. item := models.CygxMicroRoadshowVideoHistory{
  261. VideoId: videoId,
  262. UserId: uid,
  263. Mobile: user.Mobile,
  264. Email: user.Email,
  265. CompanyId: user.CompanyId,
  266. CompanyName: user.CompanyName,
  267. RealName: user.RealName,
  268. SellerName: sellerName,
  269. PlaySeconds: strconv.Itoa(playSeconds),
  270. CreateTime: time.Now(),
  271. ModifyTime: time.Now(),
  272. }
  273. if playSeconds != 0 {
  274. lastItem, err := models.GetLastCygxMicroRoadshowVideoHistory(videoId, user.UserId)
  275. if err != nil {
  276. br.Msg = "操作失败"
  277. br.ErrMsg = "操作失败,GetLastCygxMicroRoadshowVideoHistory Err:" + err.Error()
  278. return
  279. }
  280. err = models.UpdateLastCygxActivityVideoHistory(strconv.Itoa(playSeconds), lastItem.Id)
  281. if err != nil {
  282. br.Msg = "更新失败"
  283. br.ErrMsg = "更新失败,UpdateLastCygxActivityVideoHistory Err:" + err.Error()
  284. return
  285. }
  286. } else {
  287. err = models.AddCygxMicroRoadshowVideoHistory(&item)
  288. if err != nil {
  289. br.Msg = "操作失败"
  290. br.ErrMsg = "操作失败,Err:" + err.Error()
  291. return
  292. }
  293. err = models.UpdateCygxActivityVideoCounts(videoId)
  294. if err != nil {
  295. br.Msg = "更新失败"
  296. br.ErrMsg = "更新失败,Err:" + err.Error()
  297. return
  298. }
  299. }
  300. go services.MicroRoadshowVideoUserRmind(user, videoId)
  301. } else if sourceType == 2 {
  302. err = services.AddActivityVideoHistory(user, videoId)
  303. if err != nil {
  304. br.Msg = "更新失败"
  305. br.ErrMsg = "更新失败,AddActivityVideoHistory Err:" + err.Error()
  306. return
  307. }
  308. }
  309. br.Ret = 200
  310. br.Success = true
  311. br.Msg = "操作成功"
  312. return
  313. }
  314. // @Title 微路演新增留言
  315. // @Description 微路演新增留言接口
  316. // @Param request body models.AddVideoCommnetReq true "type json string"
  317. // @Success Ret=200 {object} models.AppointmentResp
  318. // @router /comment/add [post]
  319. func (this *MicroRoadShowController) CommentAdd() {
  320. br := new(models.BaseResponse).Init()
  321. defer func() {
  322. this.Data["json"] = br
  323. this.ServeJSON()
  324. }()
  325. user := this.User
  326. if user == nil {
  327. br.Msg = "请登录"
  328. br.ErrMsg = "请登录,用户信息为空"
  329. br.Ret = 408
  330. return
  331. }
  332. uid := user.UserId
  333. var req models.AddVideoCommnetReq
  334. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  335. if err != nil {
  336. br.Msg = "参数解析异常!"
  337. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  338. return
  339. }
  340. sourceType := req.SourceType
  341. if sourceType == 0 {
  342. sourceType = 1
  343. }
  344. item := models.CygxArticleComment{
  345. UserId: uid,
  346. CreateTime: time.Now(),
  347. RealName: user.RealName,
  348. Mobile: user.Mobile,
  349. Email: user.Email,
  350. CompanyId: user.CompanyId,
  351. CompanyName: user.CompanyName,
  352. Content: req.Content,
  353. Title: req.Title,
  354. }
  355. var resourceId int
  356. if sourceType == 1 {
  357. activityVoiceInfo, _ := models.GetCygxActivityVoiceByActivityId(req.Id)
  358. if activityVoiceInfo == nil {
  359. br.Msg = "操作失败"
  360. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(req.Id)
  361. return
  362. }
  363. item.ActivityId = req.Id
  364. item.ActivityVoiceId = activityVoiceInfo.ActivityVoiceId
  365. resourceId = activityVoiceInfo.ActivityId
  366. } else if sourceType == 2 {
  367. activityInfo, _ := models.GetCygxActivityVideoByActivityId(req.Id)
  368. if activityInfo == nil {
  369. br.Msg = "操作失败"
  370. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(req.Id)
  371. return
  372. }
  373. item.VideoId = activityInfo.VideoId
  374. item.ActivityId = req.Id
  375. resourceId = activityInfo.ActivityId
  376. } else if sourceType == 3 {
  377. item.VideoId = req.Id
  378. microVideo, e := models.GetMicroRoadshowVideoById(req.Id)
  379. if e != nil {
  380. br.Msg = "操作失败"
  381. br.ErrMsg = "微路演视频信息有误, 不存在的VideoId: " + strconv.Itoa(req.Id)
  382. return
  383. }
  384. item.IndustryId = microVideo.IndustryId
  385. resourceId = microVideo.IndustryId
  386. }
  387. _, err = models.AddArticleComment(&item)
  388. if err != nil {
  389. br.Msg = "提交失败"
  390. br.ErrMsg = "提交留言失败,Err:" + err.Error()
  391. return
  392. }
  393. services.SendWxMsgWithMicroRoadshowAsk(req, user, resourceId)
  394. br.Ret = 200
  395. br.Success = true
  396. br.Msg = "操作成功"
  397. return
  398. }
  399. // @Title 微路演收藏
  400. // @Description 微路演收藏
  401. // @Param request body models.MicroRoadshowCollectReq true "type json string"
  402. // @Success 200 {object} models.FontsCollectResp
  403. // @router /collect [post]
  404. func (this *MicroRoadShowController) Collect() {
  405. br := new(models.BaseResponse).Init()
  406. defer func() {
  407. this.Data["json"] = br
  408. this.ServeJSON()
  409. }()
  410. user := this.User
  411. if user == nil {
  412. br.Msg = "请重新登录"
  413. br.Ret = 408
  414. return
  415. }
  416. uid := user.UserId
  417. var req models.MicroRoadshowCollectReq
  418. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  419. if err != nil {
  420. br.Msg = "参数解析异常!"
  421. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  422. return
  423. }
  424. if req.SourceType == 1 {
  425. _, err := models.GetCygxActivityVoiceById(req.Id)
  426. if err != nil {
  427. br.Msg = "获取信息失败"
  428. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  429. return
  430. }
  431. count, err := models.GetVoiceCollectCount(uid, req.Id)
  432. if err != nil {
  433. br.Msg = "获取数据失败!"
  434. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  435. return
  436. }
  437. resp := new(models.ArticleCollectResp)
  438. if count <= 0 {
  439. item := new(models.CygxArticleCollect)
  440. item.ActivityVoiceId = req.Id
  441. item.UserId = uid
  442. item.CreateTime = time.Now()
  443. item.Mobile = user.Mobile
  444. item.Email = user.Email
  445. item.CompanyId = user.CompanyId
  446. item.CompanyName = user.CompanyName
  447. item.RealName = user.RealName
  448. _, err = models.AddCygxArticleCollect(item)
  449. if err != nil {
  450. br.Msg = "收藏失败"
  451. br.ErrMsg = "收藏失败,Err:" + err.Error()
  452. return
  453. }
  454. br.Msg = "收藏成功"
  455. resp.Status = 1
  456. // 文章收藏消息发送
  457. //go services.ArticleUserRemind(user, detail, 2)
  458. } else {
  459. err = models.RemoveVoiceCollect(uid, req.Id)
  460. if err != nil {
  461. br.Msg = "取消收藏失败"
  462. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  463. return
  464. }
  465. br.Msg = "已取消收藏"
  466. resp.Status = 2
  467. }
  468. collectTotal, err := models.GetVoiceCollectUsersCount(req.Id)
  469. if err != nil {
  470. br.Msg = "获取数据失败"
  471. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  472. return
  473. }
  474. resp.CollectCount = collectTotal
  475. br.Ret = 200
  476. br.Success = true
  477. br.Data = resp
  478. } else if req.SourceType == 2 {
  479. _, err := models.GetCygxActivityVideoById(req.Id)
  480. if err != nil {
  481. br.Msg = "获取信息失败"
  482. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  483. return
  484. }
  485. count, err := models.GetActivityVideoCollectCount(uid, req.Id)
  486. if err != nil {
  487. br.Msg = "获取数据失败!"
  488. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  489. return
  490. }
  491. resp := new(models.ArticleCollectResp)
  492. if count <= 0 {
  493. item := new(models.CygxArticleCollect)
  494. item.ActivityVideoId = req.Id
  495. item.UserId = uid
  496. item.CreateTime = time.Now()
  497. item.Mobile = user.Mobile
  498. item.Email = user.Email
  499. item.CompanyId = user.CompanyId
  500. item.CompanyName = user.CompanyName
  501. item.RealName = user.RealName
  502. _, err = models.AddCygxArticleCollect(item)
  503. if err != nil {
  504. br.Msg = "收藏失败"
  505. br.ErrMsg = "收藏失败,Err:" + err.Error()
  506. return
  507. }
  508. br.Msg = "收藏成功"
  509. resp.Status = 1
  510. // 文章收藏消息发送
  511. //go services.ArticleUserRemind(user, detail, 2)
  512. } else {
  513. err = models.RemoveActivityVideoCollect(uid, req.Id)
  514. if err != nil {
  515. br.Msg = "取消收藏失败"
  516. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  517. return
  518. }
  519. br.Msg = "已取消收藏"
  520. resp.Status = 2
  521. }
  522. collectTotal, err := models.GetActivityVideoCollectUsersCount(req.Id)
  523. if err != nil {
  524. br.Msg = "获取数据失败"
  525. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  526. return
  527. }
  528. resp.CollectCount = collectTotal
  529. br.Ret = 200
  530. br.Success = true
  531. br.Data = resp
  532. } else if req.SourceType == 3 {
  533. _, err := models.GetMicroRoadshowVideoById(req.Id)
  534. if err != nil {
  535. br.Msg = "获取信息失败"
  536. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  537. return
  538. }
  539. count, err := models.GetVideoCollectCount(uid, req.Id)
  540. if err != nil {
  541. br.Msg = "获取数据失败!"
  542. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  543. return
  544. }
  545. resp := new(models.ArticleCollectResp)
  546. if count <= 0 {
  547. item := new(models.CygxArticleCollect)
  548. item.VideoId = req.Id
  549. item.UserId = uid
  550. item.CreateTime = time.Now()
  551. item.Mobile = user.Mobile
  552. item.Email = user.Email
  553. item.CompanyId = user.CompanyId
  554. item.CompanyName = user.CompanyName
  555. item.RealName = user.RealName
  556. _, err = models.AddCygxArticleCollect(item)
  557. if err != nil {
  558. br.Msg = "收藏失败"
  559. br.ErrMsg = "收藏失败,Err:" + err.Error()
  560. return
  561. }
  562. br.Msg = "收藏成功"
  563. resp.Status = 1
  564. // 文章收藏消息发送
  565. //go services.ArticleUserRemind(user, detail, 2)
  566. } else {
  567. err = models.RemoveVideoCollect(uid, req.Id)
  568. if err != nil {
  569. br.Msg = "取消收藏失败"
  570. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  571. return
  572. }
  573. br.Msg = "已取消收藏"
  574. resp.Status = 2
  575. }
  576. collectTotal, err := models.GetVideoCollectUsersCount(req.Id)
  577. if err != nil {
  578. br.Msg = "获取数据失败"
  579. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  580. return
  581. }
  582. resp.CollectCount = collectTotal
  583. br.Ret = 200
  584. br.Success = true
  585. br.Data = resp
  586. }
  587. }
  588. // @Title 我的收藏微路演列表
  589. // @Description 我的收藏微路演列表接口
  590. // @Param PageSize query int true "每页数据条数"
  591. // @Param CurrentIndex query int true "当前页页码,从1开始"
  592. // @Success 200 {object} models.HomeListResp
  593. // @router /mycollect [get]
  594. func (this *MicroRoadShowController) Mycollect() {
  595. br := new(models.BaseResponse).Init()
  596. defer func() {
  597. this.Data["json"] = br
  598. this.ServeJSON()
  599. }()
  600. user := this.User
  601. if user == nil {
  602. br.Msg = "请登录"
  603. br.ErrMsg = "请登录,用户信息为空"
  604. br.Ret = 408
  605. return
  606. }
  607. pageSize, _ := this.GetInt("PageSize")
  608. currentIndex, _ := this.GetInt("CurrentIndex")
  609. if pageSize <= 0 {
  610. pageSize = utils.PageSize20
  611. }
  612. if currentIndex <= 0 {
  613. currentIndex = 1
  614. }
  615. userId := user.UserId
  616. listMycollect, err := models.GetUserMicroRoadshowCollectList(userId)
  617. if err != nil {
  618. br.Msg = "获取数据失败"
  619. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  620. return
  621. }
  622. var audioIds []string
  623. var videoIds []string
  624. var activityVideoIds []string
  625. for _, item := range listMycollect {
  626. if item.ActivityVoiceId > 0 {
  627. audioIds = append(audioIds, strconv.Itoa(item.ActivityVoiceId))
  628. } else if item.VideoId > 0 {
  629. videoIds = append(videoIds, strconv.Itoa(item.VideoId))
  630. } else if item.ActivityVideoId > 0 {
  631. activityVideoIds = append(activityVideoIds, strconv.Itoa(item.ActivityVideoId))
  632. }
  633. }
  634. if len(audioIds) == 0 && len(videoIds) == 0 && len(activityVideoIds) == 0 {
  635. resp := new(models.MicroRoadShowListResp)
  636. page := paging.GetPaging(currentIndex, pageSize, 0)
  637. resp.List = make([]*models.MicroRoadShowPageList, 0)
  638. resp.Paging = page
  639. br.Ret = 200
  640. br.Success = true
  641. br.Msg = "获取成功"
  642. br.Data = resp
  643. return
  644. }
  645. audioIdstr := strings.Join(audioIds, ",")
  646. ideoIdsStr := strings.Join(videoIds, ",")
  647. activityVideoIdsStr := strings.Join(activityVideoIds, ",")
  648. // 微路演列表
  649. list, total, e := services.GetMicroRoadShowMycollect(pageSize, currentIndex, audioIdstr, ideoIdsStr, activityVideoIdsStr)
  650. if e != nil {
  651. br.Msg = "获取失败"
  652. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  653. return
  654. }
  655. for _, item := range list {
  656. if item.Type == 1 {
  657. //音频
  658. count, err := models.GetVoiceCollectCount(user.UserId, item.Id)
  659. if err != nil {
  660. br.Msg = "获取数据失败!"
  661. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  662. return
  663. }
  664. if count > 0 {
  665. item.IsCollect = true
  666. }
  667. } else if item.Type == 2 {
  668. //活动视频
  669. count, err := models.GetActivityVideoCollectCount(user.UserId, item.Id)
  670. if err != nil {
  671. br.Msg = "获取数据失败!"
  672. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  673. return
  674. }
  675. if count > 0 {
  676. item.IsCollect = true
  677. }
  678. } else if item.Type == 3 {
  679. //微路演视频
  680. count, err := models.GetVideoCollectCount(user.UserId, item.Id)
  681. if err != nil {
  682. br.Msg = "获取数据失败!"
  683. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  684. return
  685. }
  686. if count > 0 {
  687. item.IsCollect = true
  688. }
  689. }
  690. }
  691. // 用户权限
  692. authInfo, permissionArr, e := services.GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  693. if e != nil {
  694. br.Msg = "获取失败"
  695. br.ErrMsg = "获取用户权限失败, Err: " + e.Error()
  696. return
  697. }
  698. // 获取默认图配置
  699. audioMap, videoMap, audioShareMap, videoShareMap, e := services.GetMicroRoadShowDefaultImgConfig()
  700. if e != nil {
  701. br.Msg = "获取失败"
  702. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  703. return
  704. }
  705. for i := range list {
  706. // 权限
  707. au := new(models.UserPermissionAuthInfo)
  708. au.SellerName = authInfo.SellerName
  709. au.SellerMobile = authInfo.SellerMobile
  710. au.HasPermission = authInfo.HasPermission
  711. au.OperationMode = authInfo.OperationMode
  712. if au.HasPermission == 1 {
  713. // 非宏观权限进一步判断是否有权限
  714. if list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  715. au.HasPermission = 2
  716. }
  717. }
  718. // 无权限的弹框提示
  719. if au.HasPermission != 1 {
  720. if au.OperationMode == services.UserPermissionOperationModeCall {
  721. if list[i].Type == 1 {
  722. au.PopupMsg = services.UserPermissionPopupMsgCallActivity
  723. } else {
  724. au.PopupMsg = services.UserPermissionPopupMsgCallMicroVideo
  725. }
  726. } else {
  727. if list[i].Type == 1 {
  728. au.PopupMsg = services.UserPermissionPopupMsgApplyActivity
  729. } else {
  730. au.PopupMsg = services.UserPermissionPopupMsgApplyMicroVideo
  731. }
  732. }
  733. }
  734. list[i].AuthInfo = au
  735. list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
  736. // 默认图
  737. if list[i].BackgroundImg == "" {
  738. if list[i].Type == 1 {
  739. list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  740. } else {
  741. list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  742. }
  743. }
  744. // 分享图
  745. if list[i].ShareImg == "" {
  746. if list[i].Type == 1 {
  747. list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
  748. } else {
  749. list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
  750. }
  751. }
  752. }
  753. resp := new(models.MicroRoadShowListResp)
  754. page := paging.GetPaging(currentIndex, pageSize, total)
  755. resp.List = list
  756. resp.Paging = page
  757. br.Ret = 200
  758. br.Success = true
  759. br.Msg = "获取成功"
  760. br.Data = resp
  761. }