micro_roadshow.go 25 KB

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