micro_roadshow.go 26 KB

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