micro_roadshow.go 24 KB

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