micro_roadshow.go 24 KB

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