micro_roadshow.go 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001
  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.ActivityVideoId] = item.ActivityVideoId
  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. go services.AddAllCygxVoiceAndVideoHistory(user, sourceId, sourceType, playSeconds)
  249. br.Ret = 200
  250. br.Success = true
  251. br.Msg = "操作成功"
  252. return
  253. }
  254. // @Title 微路演新增留言
  255. // @Description 微路演新增留言接口
  256. // @Param request body models.AddVideoCommnetReq true "type json string"
  257. // @Success Ret=200 {object} models.AppointmentResp
  258. // @router /comment/add [post]
  259. func (this *MicroRoadShowController) CommentAdd() {
  260. br := new(models.BaseResponse).Init()
  261. defer func() {
  262. this.Data["json"] = br
  263. this.ServeJSON()
  264. }()
  265. user := this.User
  266. if user == nil {
  267. br.Msg = "请登录"
  268. br.ErrMsg = "请登录,用户信息为空"
  269. br.Ret = 408
  270. return
  271. }
  272. uid := user.UserId
  273. var req models.AddVideoCommnetReq
  274. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  275. if err != nil {
  276. br.Msg = "参数解析异常!"
  277. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  278. return
  279. }
  280. var isResearch bool // 是否属于研选
  281. sourceType := req.SourceType
  282. title := req.Title
  283. if sourceType == 0 {
  284. sourceType = 1
  285. }
  286. fmt.Println(sourceType)
  287. item := models.CygxArticleComment{
  288. UserId: uid,
  289. CreateTime: time.Now(),
  290. RealName: user.RealName,
  291. Mobile: user.Mobile,
  292. Email: user.Email,
  293. CompanyId: user.CompanyId,
  294. CompanyName: user.CompanyName,
  295. Content: req.Content,
  296. Title: req.Title,
  297. }
  298. sourceId := req.SourceId
  299. //var resourceId int
  300. if sourceType == 1 {
  301. activityVoiceInfo, _ := models.GetCygxActivityVoiceByActivityId(sourceId)
  302. if activityVoiceInfo == nil {
  303. br.Msg = "操作失败"
  304. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(sourceId)
  305. return
  306. }
  307. item.ActivityId = sourceId
  308. item.ActivityVoiceId = activityVoiceInfo.ActivityVoiceId
  309. err = models.UpdateActivityVoiceCommentNum(sourceId)
  310. if err != nil {
  311. br.Msg = "操作失败"
  312. br.ErrMsg = "操作失败 ,更新活动音频留言次数失败:" + strconv.Itoa(sourceId)
  313. return
  314. }
  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. } else if sourceType == 3 {
  331. item.VideoId = sourceId
  332. microVideo, e := models.GetMicroRoadshowVideoById(sourceId)
  333. if e != nil {
  334. br.Msg = "操作失败"
  335. br.ErrMsg = "微路演视频信息有误, 不存在的VideoId: " + strconv.Itoa(sourceId)
  336. return
  337. }
  338. item.IndustryId = microVideo.IndustryId
  339. //resourceId = microVideo.IndustryId
  340. } else if sourceType == 4 {
  341. item.AskserieVideoId = sourceId
  342. go services.AddCygxAskserieVideoCollection(user, item.AskserieVideoId, req.Content)
  343. }
  344. if sourceType == 1 || sourceType == 2 {
  345. detail, err := models.GetAddActivityInfoById(sourceId)
  346. if err != nil {
  347. br.Msg = "操作失败"
  348. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(sourceId)
  349. return
  350. }
  351. if strings.Contains(detail.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  352. isResearch = true
  353. }
  354. }
  355. msgId, err := models.AddArticleComment(&item)
  356. if err != nil {
  357. br.Msg = "提交失败"
  358. br.ErrMsg = "提交留言失败,Err:" + err.Error()
  359. return
  360. }
  361. services.SendWxMsgWithMicroRoadshowAsk(req, user, sourceType, int(msgId), title, isResearch)
  362. br.Ret = 200
  363. br.Success = true
  364. br.Msg = "操作成功"
  365. return
  366. }
  367. // @Title 微路演收藏
  368. // @Description 微路演收藏
  369. // @Param request body models.MicroRoadshowCollectReq true "type json string"
  370. // @Success 200 {object} models.FontsCollectResp
  371. // @router /collect [post]
  372. func (this *MicroRoadShowController) Collect() {
  373. br := new(models.BaseResponse).Init()
  374. defer func() {
  375. this.Data["json"] = br
  376. this.ServeJSON()
  377. }()
  378. user := this.User
  379. if user == nil {
  380. br.Msg = "请重新登录"
  381. br.Ret = 408
  382. return
  383. }
  384. uid := user.UserId
  385. var req models.MicroRoadshowCollectReq
  386. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  387. if err != nil {
  388. br.Msg = "参数解析异常!"
  389. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  390. return
  391. }
  392. sourceId := req.SourceId
  393. if req.SourceType == 1 {
  394. detail, err := models.GetCygxActivityVoiceByActivityId(sourceId)
  395. if err != nil {
  396. br.Msg = "获取信息失败"
  397. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  398. return
  399. }
  400. count, err := models.GetVoiceCollectCount(uid, detail.ActivityVoiceId)
  401. if err != nil {
  402. br.Msg = "获取数据失败!"
  403. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  404. return
  405. }
  406. resp := new(models.ArticleCollectResp)
  407. if count <= 0 {
  408. item := new(models.CygxArticleCollect)
  409. item.ActivityVoiceId = detail.ActivityVoiceId
  410. item.UserId = uid
  411. item.CreateTime = time.Now()
  412. item.Mobile = user.Mobile
  413. item.Email = user.Email
  414. item.CompanyId = user.CompanyId
  415. item.CompanyName = user.CompanyName
  416. item.RealName = user.RealName
  417. _, err = models.AddCygxArticleCollect(item)
  418. if err != nil {
  419. br.Msg = "收藏失败"
  420. br.ErrMsg = "收藏失败,Err:" + err.Error()
  421. return
  422. }
  423. br.Msg = "收藏成功"
  424. resp.Status = 1
  425. // 文章收藏消息发送
  426. //go services.ArticleUserRemind(user, detail, 2)
  427. } else {
  428. err = models.RemoveVoiceCollect(uid, detail.ActivityVoiceId)
  429. if err != nil {
  430. br.Msg = "取消收藏失败"
  431. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  432. return
  433. }
  434. br.Msg = "已取消收藏"
  435. resp.Status = 2
  436. }
  437. collectTotal, err := models.GetVoiceCollectUsersCount(detail.ActivityVoiceId)
  438. if err != nil {
  439. br.Msg = "获取数据失败"
  440. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  441. return
  442. }
  443. resp.CollectCount = collectTotal
  444. br.Ret = 200
  445. br.Success = true
  446. br.Data = resp
  447. } else if req.SourceType == 2 {
  448. detail, err := models.GetCygxActivityVideoByActivityIdInfo(sourceId)
  449. if err != nil {
  450. br.Msg = "获取信息失败"
  451. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  452. return
  453. }
  454. count, err := models.GetActivityVideoCollectCount(uid, detail.Id)
  455. if err != nil {
  456. br.Msg = "获取数据失败!"
  457. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  458. return
  459. }
  460. resp := new(models.ArticleCollectResp)
  461. if count <= 0 {
  462. item := new(models.CygxArticleCollect)
  463. item.ActivityVideoId = detail.Id
  464. item.UserId = uid
  465. item.CreateTime = time.Now()
  466. item.ModifyTime = time.Now()
  467. item.Mobile = user.Mobile
  468. item.Email = user.Email
  469. item.CompanyId = user.CompanyId
  470. item.CompanyName = user.CompanyName
  471. item.RealName = user.RealName
  472. _, err = models.AddCygxArticleCollect(item)
  473. if err != nil {
  474. br.Msg = "收藏失败"
  475. br.ErrMsg = "收藏失败,Err:" + err.Error()
  476. return
  477. }
  478. br.Msg = "收藏成功"
  479. resp.Status = 1
  480. // 文章收藏消息发送
  481. //go services.ArticleUserRemind(user, detail, 2)
  482. } else {
  483. err = models.RemoveActivityVideoCollect(uid, detail.Id)
  484. if err != nil {
  485. br.Msg = "取消收藏失败"
  486. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  487. return
  488. }
  489. br.Msg = "已取消收藏"
  490. resp.Status = 2
  491. }
  492. collectTotal, err := models.GetActivityVideoCollectUsersCount(detail.Id)
  493. if err != nil {
  494. br.Msg = "获取数据失败"
  495. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  496. return
  497. }
  498. resp.CollectCount = collectTotal
  499. br.Ret = 200
  500. br.Success = true
  501. br.Data = resp
  502. } else if req.SourceType == 3 {
  503. _, err := models.GetMicroRoadshowVideoById(sourceId)
  504. if err != nil {
  505. br.Msg = "获取信息失败"
  506. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  507. return
  508. }
  509. count, err := models.GetVideoCollectCount(uid, sourceId)
  510. if err != nil {
  511. br.Msg = "获取数据失败!"
  512. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  513. return
  514. }
  515. resp := new(models.ArticleCollectResp)
  516. if count <= 0 {
  517. item := new(models.CygxArticleCollect)
  518. item.VideoId = sourceId
  519. item.UserId = uid
  520. item.CreateTime = time.Now()
  521. item.Mobile = user.Mobile
  522. item.Email = user.Email
  523. item.CompanyId = user.CompanyId
  524. item.CompanyName = user.CompanyName
  525. item.RealName = user.RealName
  526. _, err = models.AddCygxArticleCollect(item)
  527. if err != nil {
  528. br.Msg = "收藏失败"
  529. br.ErrMsg = "收藏失败,Err:" + err.Error()
  530. return
  531. }
  532. br.Msg = "收藏成功"
  533. resp.Status = 1
  534. // 文章收藏消息发送
  535. //go services.ArticleUserRemind(user, detail, 2)
  536. } else {
  537. err = models.RemoveVideoCollect(uid, sourceId)
  538. if err != nil {
  539. br.Msg = "取消收藏失败"
  540. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  541. return
  542. }
  543. br.Msg = "已取消收藏"
  544. resp.Status = 2
  545. }
  546. collectTotal, err := models.GetVideoCollectUsersCount(sourceId)
  547. if err != nil {
  548. br.Msg = "获取数据失败"
  549. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  550. return
  551. }
  552. resp.CollectCount = collectTotal
  553. br.Ret = 200
  554. br.Success = true
  555. br.Data = resp
  556. } else if req.SourceType == 4 {
  557. // 系列问答视频收藏
  558. count, err := models.GetAskserieVideoCount(uid, sourceId)
  559. if err != nil {
  560. br.Msg = "获取数据失败!"
  561. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  562. return
  563. }
  564. resp := new(models.ArticleCollectResp)
  565. if count <= 0 {
  566. item := new(models.CygxAskserieVideoCollect)
  567. item.AskserieVideoId = sourceId
  568. item.UserId = uid
  569. item.CreateTime = time.Now()
  570. item.Mobile = user.Mobile
  571. item.Email = user.Email
  572. item.CompanyId = user.CompanyId
  573. item.CompanyName = user.CompanyName
  574. item.RealName = user.RealName
  575. item.RegisterPlatform = utils.REGISTER_PLATFORM
  576. err = models.AddCygxAskserieVideoCollect(item)
  577. if err != nil {
  578. br.Msg = "收藏失败"
  579. br.ErrMsg = "收藏失败,Err:" + err.Error()
  580. return
  581. }
  582. br.Msg = "收藏成功"
  583. resp.Status = 1
  584. // 文章收藏消息发送
  585. //go services.ArticleUserRemind(user, detail, 2)
  586. } else {
  587. err = models.RemoveAskserieVideoCollect(uid, sourceId)
  588. if err != nil {
  589. br.Msg = "取消收藏失败"
  590. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  591. return
  592. }
  593. br.Msg = "已取消收藏"
  594. resp.Status = 2
  595. }
  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. listAskserieVideoCollect, err := models.GetUserCygxAskserieVideoCollectList(userId)
  636. if err != nil {
  637. br.Msg = "获取数据失败"
  638. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  639. return
  640. }
  641. var audioIds []string
  642. var videoIds []string
  643. var activityVideoIds []string
  644. var askserieVideoIds []string //问答系列视频
  645. for _, item := range listMycollect {
  646. if item.ActivityVoiceId > 0 {
  647. audioIds = append(audioIds, strconv.Itoa(item.ActivityVoiceId))
  648. } else if item.VideoId > 0 {
  649. videoIds = append(videoIds, strconv.Itoa(item.VideoId))
  650. } else if item.ActivityVideoId > 0 {
  651. activityVideoIds = append(activityVideoIds, strconv.Itoa(item.ActivityVideoId))
  652. }
  653. }
  654. for _, item := range listAskserieVideoCollect {
  655. askserieVideoIds = append(askserieVideoIds, strconv.Itoa(item.AskserieVideoId))
  656. }
  657. if len(audioIds) == 0 && len(videoIds) == 0 && len(activityVideoIds) == 0 && len(askserieVideoIds) == 0 {
  658. resp := new(models.MicroRoadShowListResp)
  659. page := paging.GetPaging(currentIndex, pageSize, 0)
  660. resp.List = make([]*models.MicroRoadShowPageList, 0)
  661. resp.Paging = page
  662. br.Ret = 200
  663. br.Success = true
  664. br.Msg = "获取成功"
  665. br.Data = resp
  666. return
  667. }
  668. audioIdstr := strings.Join(audioIds, ",")
  669. ideoIdsStr := strings.Join(videoIds, ",")
  670. activityVideoIdsStr := strings.Join(activityVideoIds, ",")
  671. askserieVideoIdsStr := strings.Join(askserieVideoIds, ",")
  672. // 微路演列表
  673. list, total, e := services.GetMicroRoadShowMycollectV12(pageSize, currentIndex, audioIdstr, activityVideoIdsStr, ideoIdsStr, askserieVideoIdsStr, user)
  674. if e != nil {
  675. br.Msg = "获取失败"
  676. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  677. return
  678. }
  679. for _, item := range list {
  680. //if item.Type == 1 {
  681. // //音频
  682. // count, err := models.GetVoiceCollectCount(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 == 2 {
  692. // //活动视频
  693. // count, err := models.GetActivityVideoCollectCount(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. //} else if item.Type == 3 {
  703. // //微路演视频
  704. // count, err := models.GetVideoCollectCount(user.UserId, item.Id)
  705. // if err != nil {
  706. // br.Msg = "获取数据失败!"
  707. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  708. // return
  709. // }
  710. // if count > 0 {
  711. // item.IsCollect = true
  712. // }
  713. //}
  714. item.IsCollect = true
  715. }
  716. // 用户权限
  717. authInfo, permissionArr, e := services.GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  718. if e != nil {
  719. br.Msg = "获取失败"
  720. br.ErrMsg = "获取用户权限失败, Err: " + e.Error()
  721. return
  722. }
  723. // 获取默认图配置
  724. audioMap, videoMap, audioShareMap, videoShareMap, e := services.GetMicroRoadShowDefaultImgConfig()
  725. if e != nil {
  726. br.Msg = "获取失败"
  727. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  728. return
  729. }
  730. for i := range list {
  731. // 权限
  732. au := new(models.UserPermissionAuthInfo)
  733. au.SellerName = authInfo.SellerName
  734. au.SellerMobile = authInfo.SellerMobile
  735. au.HasPermission = authInfo.HasPermission
  736. au.OperationMode = authInfo.OperationMode
  737. if au.HasPermission == 1 {
  738. // 非宏观权限进一步判断是否有权限
  739. if list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  740. au.HasPermission = 2
  741. }
  742. }
  743. // 无权限的弹框提示
  744. if au.HasPermission != 1 {
  745. if au.OperationMode == services.UserPermissionOperationModeCall {
  746. if list[i].Type == 1 {
  747. au.PopupMsg = services.UserPermissionPopupMsgCallActivity
  748. } else {
  749. au.PopupMsg = services.UserPermissionPopupMsgCallMicroVideo
  750. }
  751. } else {
  752. if list[i].Type == 1 {
  753. au.PopupMsg = services.UserPermissionPopupMsgApplyActivity
  754. } else {
  755. au.PopupMsg = services.UserPermissionPopupMsgApplyMicroVideo
  756. }
  757. }
  758. }
  759. list[i].AuthInfo = au
  760. list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
  761. // 默认图
  762. if list[i].BackgroundImg == "" {
  763. if list[i].Type == 1 {
  764. list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  765. } else {
  766. list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  767. }
  768. }
  769. // 分享图
  770. if list[i].ShareImg == "" {
  771. if list[i].Type == 1 {
  772. list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
  773. } else {
  774. list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
  775. }
  776. }
  777. }
  778. resp := new(models.MicroRoadShowListResp)
  779. page := paging.GetPaging(currentIndex, pageSize, total)
  780. resp.List = list
  781. resp.Paging = page
  782. br.Ret = 200
  783. br.Success = true
  784. br.Msg = "获取成功"
  785. br.Data = resp
  786. }
  787. // @Title 模版消息留言详情
  788. // @Description 模版消息留言详情接口
  789. // @Param SourceId query int true "资源ID"
  790. // @Param SourceType query int true "留言类型,1:文章、2:活动、3:微路演视频、4:活动视频、5:活动音频"
  791. // @Success Ret=200 {object} models.CygxArticleCommentWxResp
  792. // @router /comment/detail [get]
  793. func (this *MicroRoadShowController) CommentDetail() {
  794. br := new(models.BaseResponse).Init()
  795. defer func() {
  796. this.Data["json"] = br
  797. this.ServeJSON()
  798. }()
  799. user := this.User
  800. if user == nil {
  801. br.Msg = "请登录"
  802. br.ErrMsg = "请登录,用户信息为空"
  803. br.Ret = 408
  804. return
  805. }
  806. sourceId, _ := this.GetInt("SourceId")
  807. sourceType, _ := this.GetInt("SourceType")
  808. resp := new(models.CygxArticleCommentWxResp)
  809. if sourceType == 1 || sourceType == 3 || sourceType == 4 || sourceType == 5 {
  810. detail, err := models.GetArticleCommentById(sourceId)
  811. if err != nil {
  812. br.Msg = "获取失败"
  813. br.ErrMsg = "获取用户权限失败, Err: " + err.Error()
  814. return
  815. }
  816. resp.Content = detail.Content
  817. if sourceType == 1 {
  818. resp.SourceId = detail.ArticleId
  819. resp.RedirectType = 1
  820. } else if sourceType == 3 {
  821. resp.SourceId = detail.IndustryId
  822. resp.RedirectType = 3
  823. } else {
  824. resp.SourceId = detail.ActivityId
  825. resp.RedirectType = 2
  826. }
  827. } else {
  828. detail, err := models.GetCygxActivityHelpAskById(sourceId)
  829. if err != nil {
  830. br.Msg = "获取失败"
  831. br.ErrMsg = "获取用户权限失败, Err: " + err.Error()
  832. return
  833. }
  834. resp.Content = detail.Content
  835. resp.SourceId = detail.ActivityId
  836. resp.RedirectType = 2
  837. }
  838. br.Ret = 200
  839. br.Success = true
  840. br.Data = resp
  841. br.Msg = "操作成功"
  842. return
  843. }
  844. // @Title 策略系列培训视频
  845. // @Description 策略系列培训视频接口
  846. // @Param PageSize query int true "每页数据条数"
  847. // @Param CurrentIndex query int true "当前页页码,从1开始"
  848. // @Success 200 {object} models.HomeListResp
  849. // @router /training/list [get]
  850. func (this *MicroRoadShowController) TrainingList() {
  851. br := new(models.BaseResponse).Init()
  852. defer func() {
  853. this.Data["json"] = br
  854. this.ServeJSON()
  855. }()
  856. user := this.User
  857. if user == nil {
  858. br.Msg = "请登录"
  859. br.ErrMsg = "请登录,用户信息为空"
  860. br.Ret = 408
  861. return
  862. }
  863. pageSize, _ := this.GetInt("PageSize")
  864. currentIndex, _ := this.GetInt("CurrentIndex")
  865. if pageSize <= 0 {
  866. pageSize = utils.PageSize20
  867. }
  868. if currentIndex <= 0 {
  869. currentIndex = 1
  870. }
  871. var audioIds []string
  872. var videoIds []string
  873. var activityVideoIds []string
  874. var askserieVideoIds []string //问答系列视频
  875. activityVideoIds = []string{"461", "462", "463", "464", "465", "466"} // 系列培训视频,固定的六个,这里先写死
  876. activityVideoTitle := []string{"第一期_A股运行特征探讨", "第二期_行业比较研究", "第三期_市场风格观察与我们的研究方法", "第四期_市场估值指标追踪", "第五期_宏观经济研究", "第六期_市场回顾专题"} // 系列培训视频,固定的六个,这里先写死
  877. audioIdstr := strings.Join(audioIds, ",")
  878. ideoIdsStr := strings.Join(videoIds, ",")
  879. activityVideoIdsStr := strings.Join(activityVideoIds, ",")
  880. askserieVideoIdsStr := strings.Join(askserieVideoIds, ",")
  881. // 微路演列表
  882. list, total, e := services.GetMicroRoadShowMycollectV12(pageSize, currentIndex, audioIdstr, activityVideoIdsStr, ideoIdsStr, askserieVideoIdsStr, user)
  883. if e != nil {
  884. br.Msg = "获取失败"
  885. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  886. return
  887. }
  888. //存储反转数据
  889. reversed := []*models.MicroRoadShowPageList{}
  890. for i := range list {
  891. n := list[len(list)-1-i]
  892. reversed = append(reversed, n)
  893. }
  894. list = reversed
  895. // 用户权限
  896. authInfo, permissionArr, e := services.GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  897. if e != nil {
  898. br.Msg = "获取失败"
  899. br.ErrMsg = "获取用户权限失败, Err: " + e.Error()
  900. return
  901. }
  902. // 获取默认图配置
  903. audioMap, videoMap, audioShareMap, videoShareMap, e := services.GetMicroRoadShowDefaultImgConfig()
  904. if e != nil {
  905. br.Msg = "获取失败"
  906. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  907. return
  908. }
  909. for i := range list {
  910. // 权限
  911. au := new(models.UserPermissionAuthInfo)
  912. au.SellerName = authInfo.SellerName
  913. au.SellerMobile = authInfo.SellerMobile
  914. au.HasPermission = authInfo.HasPermission
  915. au.OperationMode = authInfo.OperationMode
  916. if au.HasPermission == 1 {
  917. // 非宏观权限进一步判断是否有权限
  918. if list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  919. au.HasPermission = 2
  920. }
  921. }
  922. // 无权限的弹框提示
  923. if au.HasPermission != 1 {
  924. if au.OperationMode == services.UserPermissionOperationModeCall {
  925. if list[i].Type == 1 {
  926. au.PopupMsg = services.UserPermissionPopupMsgCallActivity
  927. } else {
  928. au.PopupMsg = services.UserPermissionPopupMsgCallMicroVideo
  929. }
  930. } else {
  931. if list[i].Type == 1 {
  932. au.PopupMsg = services.UserPermissionPopupMsgApplyActivity
  933. } else {
  934. au.PopupMsg = services.UserPermissionPopupMsgApplyMicroVideo
  935. }
  936. }
  937. }
  938. list[i].AuthInfo = au
  939. list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
  940. // 默认图
  941. if list[i].BackgroundImg == "" {
  942. if list[i].Type == 1 {
  943. list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  944. } else {
  945. list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  946. }
  947. }
  948. list[i].BackgroundImg = "https://hzstatic.hzinsights.com/cygx/micro_roadshow_default_cl_video.png" //前端小程序忘记添加音视频图标,先手动替换
  949. // 分享图
  950. if list[i].ShareImg == "" {
  951. if list[i].Type == 1 {
  952. list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
  953. } else {
  954. list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
  955. }
  956. }
  957. if i <= len(activityVideoTitle)-1 {
  958. list[i].Title = activityVideoTitle[i]
  959. }
  960. }
  961. resp := new(models.MicroRoadShowListResp)
  962. page := paging.GetPaging(currentIndex, pageSize, total)
  963. resp.List = list
  964. resp.Paging = page
  965. resp.Describe = "弘则策略首席 马冬凡 主讲"
  966. br.Ret = 200
  967. br.Success = true
  968. br.Msg = "获取成功"
  969. br.Data = resp
  970. }