micro_roadshow.go 22 KB

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