micro_roadshow.go 22 KB

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