micro_roadshow.go 22 KB

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