micro_roadshow.go 22 KB

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