micro_roadshow.go 25 KB

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