micro_roadshow.go 22 KB

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