micro_roadshow.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908
  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. } else if sourceType == 3 {
  256. item := models.CygxMicroRoadshowVideoHistory{
  257. VideoId: sourceId,
  258. UserId: uid,
  259. Mobile: user.Mobile,
  260. Email: user.Email,
  261. CompanyId: user.CompanyId,
  262. CompanyName: user.CompanyName,
  263. RealName: user.RealName,
  264. SellerName: sellerName,
  265. PlaySeconds: strconv.Itoa(playSeconds),
  266. CreateTime: time.Now(),
  267. ModifyTime: time.Now(),
  268. }
  269. if playSeconds != 0 {
  270. lastItem, err := models.GetLastCygxMicroRoadshowVideoHistory(sourceId, user.UserId)
  271. if err != nil {
  272. br.Msg = "操作失败"
  273. br.ErrMsg = "操作失败,GetLastCygxMicroRoadshowVideoHistory Err:" + err.Error()
  274. return
  275. }
  276. err = models.UpdateLastCygxActivityVideoHistory(strconv.Itoa(playSeconds), lastItem.Id)
  277. if err != nil {
  278. br.Msg = "更新失败"
  279. br.ErrMsg = "更新失败,UpdateLastCygxActivityVideoHistory Err:" + err.Error()
  280. return
  281. }
  282. } else {
  283. err = models.AddCygxMicroRoadshowVideoHistory(&item)
  284. if err != nil {
  285. br.Msg = "操作失败"
  286. br.ErrMsg = "操作失败,Err:" + err.Error()
  287. return
  288. }
  289. err = models.UpdateCygxActivityVideoCounts(sourceId)
  290. if err != nil {
  291. br.Msg = "更新失败"
  292. br.ErrMsg = "更新失败,Err:" + err.Error()
  293. return
  294. }
  295. }
  296. go services.MicroRoadshowVideoUserRmind(user, sourceId)
  297. } else if sourceType == 4 {
  298. go services.AddAskserieVideoHistoryRecord(user, sourceId, playSeconds)
  299. }
  300. br.Ret = 200
  301. br.Success = true
  302. br.Msg = "操作成功"
  303. return
  304. }
  305. // @Title 微路演新增留言
  306. // @Description 微路演新增留言接口
  307. // @Param request body models.AddVideoCommnetReq true "type json string"
  308. // @Success Ret=200 {object} models.AppointmentResp
  309. // @router /comment/add [post]
  310. func (this *MicroRoadShowController) CommentAdd() {
  311. br := new(models.BaseResponse).Init()
  312. defer func() {
  313. this.Data["json"] = br
  314. this.ServeJSON()
  315. }()
  316. user := this.User
  317. if user == nil {
  318. br.Msg = "请登录"
  319. br.ErrMsg = "请登录,用户信息为空"
  320. br.Ret = 408
  321. return
  322. }
  323. uid := user.UserId
  324. var req models.AddVideoCommnetReq
  325. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  326. if err != nil {
  327. br.Msg = "参数解析异常!"
  328. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  329. return
  330. }
  331. var isResearch bool // 是否属于研选
  332. sourceType := req.SourceType
  333. title := req.Title
  334. if sourceType == 0 {
  335. sourceType = 1
  336. }
  337. item := models.CygxArticleComment{
  338. UserId: uid,
  339. CreateTime: time.Now(),
  340. RealName: user.RealName,
  341. Mobile: user.Mobile,
  342. Email: user.Email,
  343. CompanyId: user.CompanyId,
  344. CompanyName: user.CompanyName,
  345. Content: req.Content,
  346. Title: req.Title,
  347. }
  348. sourceId := req.SourceId
  349. //var resourceId int
  350. if sourceType == 1 {
  351. activityVoiceInfo, _ := models.GetCygxActivityVoiceByActivityId(sourceId)
  352. if activityVoiceInfo == nil {
  353. br.Msg = "操作失败"
  354. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(sourceId)
  355. return
  356. }
  357. item.ActivityId = sourceId
  358. item.ActivityVoiceId = activityVoiceInfo.ActivityVoiceId
  359. //resourceId = activityVoiceInfo.ActivityId
  360. } else if sourceType == 2 {
  361. activityInfo, _ := models.GetCygxActivityVideoByActivityId(sourceId)
  362. if activityInfo == nil {
  363. br.Msg = "操作失败"
  364. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(sourceId)
  365. return
  366. }
  367. item.VideoId = activityInfo.VideoId
  368. item.ActivityId = sourceId
  369. //resourceId = activityInfo.ActivityId
  370. } else if sourceType == 3 {
  371. item.VideoId = sourceId
  372. microVideo, e := models.GetMicroRoadshowVideoById(sourceId)
  373. if e != nil {
  374. br.Msg = "操作失败"
  375. br.ErrMsg = "微路演视频信息有误, 不存在的VideoId: " + strconv.Itoa(sourceId)
  376. return
  377. }
  378. item.IndustryId = microVideo.IndustryId
  379. //resourceId = microVideo.IndustryId
  380. } else if sourceType == 4 {
  381. item.AskserieVideoId = sourceId
  382. go services.AddCygxAskserieVideoCollection(user, item.AskserieVideoId, req.Content)
  383. }
  384. if sourceType == 2 || sourceType == 3 {
  385. detail, err := models.GetAddActivityInfoById(sourceId)
  386. if err != nil {
  387. br.Msg = "操作失败"
  388. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(sourceId)
  389. return
  390. }
  391. if strings.Contains(detail.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  392. isResearch = true
  393. }
  394. }
  395. msgId, err := models.AddArticleComment(&item)
  396. if err != nil {
  397. br.Msg = "提交失败"
  398. br.ErrMsg = "提交留言失败,Err:" + err.Error()
  399. return
  400. }
  401. services.SendWxMsgWithMicroRoadshowAsk(req, user, sourceType, int(msgId), title, isResearch)
  402. br.Ret = 200
  403. br.Success = true
  404. br.Msg = "操作成功"
  405. return
  406. }
  407. // @Title 微路演收藏
  408. // @Description 微路演收藏
  409. // @Param request body models.MicroRoadshowCollectReq true "type json string"
  410. // @Success 200 {object} models.FontsCollectResp
  411. // @router /collect [post]
  412. func (this *MicroRoadShowController) Collect() {
  413. br := new(models.BaseResponse).Init()
  414. defer func() {
  415. this.Data["json"] = br
  416. this.ServeJSON()
  417. }()
  418. user := this.User
  419. if user == nil {
  420. br.Msg = "请重新登录"
  421. br.Ret = 408
  422. return
  423. }
  424. uid := user.UserId
  425. var req models.MicroRoadshowCollectReq
  426. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  427. if err != nil {
  428. br.Msg = "参数解析异常!"
  429. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  430. return
  431. }
  432. sourceId := req.SourceId
  433. if req.SourceType == 1 {
  434. _, err := models.GetCygxActivityVoiceById(sourceId)
  435. if err != nil {
  436. br.Msg = "获取信息失败"
  437. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  438. return
  439. }
  440. count, err := models.GetVoiceCollectCount(uid, sourceId)
  441. if err != nil {
  442. br.Msg = "获取数据失败!"
  443. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  444. return
  445. }
  446. resp := new(models.ArticleCollectResp)
  447. if count <= 0 {
  448. item := new(models.CygxArticleCollect)
  449. item.ActivityVoiceId = sourceId
  450. item.UserId = uid
  451. item.CreateTime = time.Now()
  452. item.Mobile = user.Mobile
  453. item.Email = user.Email
  454. item.CompanyId = user.CompanyId
  455. item.CompanyName = user.CompanyName
  456. item.RealName = user.RealName
  457. _, err = models.AddCygxArticleCollect(item)
  458. if err != nil {
  459. br.Msg = "收藏失败"
  460. br.ErrMsg = "收藏失败,Err:" + err.Error()
  461. return
  462. }
  463. br.Msg = "收藏成功"
  464. resp.Status = 1
  465. // 文章收藏消息发送
  466. //go services.ArticleUserRemind(user, detail, 2)
  467. } else {
  468. err = models.RemoveVoiceCollect(uid, sourceId)
  469. if err != nil {
  470. br.Msg = "取消收藏失败"
  471. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  472. return
  473. }
  474. br.Msg = "已取消收藏"
  475. resp.Status = 2
  476. }
  477. collectTotal, err := models.GetVoiceCollectUsersCount(sourceId)
  478. if err != nil {
  479. br.Msg = "获取数据失败"
  480. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  481. return
  482. }
  483. resp.CollectCount = collectTotal
  484. br.Ret = 200
  485. br.Success = true
  486. br.Data = resp
  487. } else if req.SourceType == 2 {
  488. _, err := models.GetCygxActivityVideoById(sourceId)
  489. if err != nil {
  490. br.Msg = "获取信息失败"
  491. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  492. return
  493. }
  494. count, err := models.GetActivityVideoCollectCount(uid, sourceId)
  495. if err != nil {
  496. br.Msg = "获取数据失败!"
  497. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  498. return
  499. }
  500. resp := new(models.ArticleCollectResp)
  501. if count <= 0 {
  502. item := new(models.CygxArticleCollect)
  503. item.ActivityVideoId = sourceId
  504. item.UserId = uid
  505. item.CreateTime = time.Now()
  506. item.ModifyTime = time.Now()
  507. item.Mobile = user.Mobile
  508. item.Email = user.Email
  509. item.CompanyId = user.CompanyId
  510. item.CompanyName = user.CompanyName
  511. item.RealName = user.RealName
  512. _, err = models.AddCygxArticleCollect(item)
  513. if err != nil {
  514. br.Msg = "收藏失败"
  515. br.ErrMsg = "收藏失败,Err:" + err.Error()
  516. return
  517. }
  518. br.Msg = "收藏成功"
  519. resp.Status = 1
  520. // 文章收藏消息发送
  521. //go services.ArticleUserRemind(user, detail, 2)
  522. } else {
  523. err = models.RemoveActivityVideoCollect(uid, sourceId)
  524. if err != nil {
  525. br.Msg = "取消收藏失败"
  526. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  527. return
  528. }
  529. br.Msg = "已取消收藏"
  530. resp.Status = 2
  531. }
  532. collectTotal, err := models.GetActivityVideoCollectUsersCount(sourceId)
  533. if err != nil {
  534. br.Msg = "获取数据失败"
  535. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  536. return
  537. }
  538. resp.CollectCount = collectTotal
  539. br.Ret = 200
  540. br.Success = true
  541. br.Data = resp
  542. } else if req.SourceType == 3 {
  543. _, err := models.GetMicroRoadshowVideoById(sourceId)
  544. if err != nil {
  545. br.Msg = "获取信息失败"
  546. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  547. return
  548. }
  549. count, err := models.GetVideoCollectCount(uid, sourceId)
  550. if err != nil {
  551. br.Msg = "获取数据失败!"
  552. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  553. return
  554. }
  555. resp := new(models.ArticleCollectResp)
  556. if count <= 0 {
  557. item := new(models.CygxArticleCollect)
  558. item.VideoId = sourceId
  559. item.UserId = uid
  560. item.CreateTime = time.Now()
  561. item.Mobile = user.Mobile
  562. item.Email = user.Email
  563. item.CompanyId = user.CompanyId
  564. item.CompanyName = user.CompanyName
  565. item.RealName = user.RealName
  566. _, err = models.AddCygxArticleCollect(item)
  567. if err != nil {
  568. br.Msg = "收藏失败"
  569. br.ErrMsg = "收藏失败,Err:" + err.Error()
  570. return
  571. }
  572. br.Msg = "收藏成功"
  573. resp.Status = 1
  574. // 文章收藏消息发送
  575. //go services.ArticleUserRemind(user, detail, 2)
  576. } else {
  577. err = models.RemoveVideoCollect(uid, sourceId)
  578. if err != nil {
  579. br.Msg = "取消收藏失败"
  580. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  581. return
  582. }
  583. br.Msg = "已取消收藏"
  584. resp.Status = 2
  585. }
  586. collectTotal, err := models.GetVideoCollectUsersCount(sourceId)
  587. if err != nil {
  588. br.Msg = "获取数据失败"
  589. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  590. return
  591. }
  592. resp.CollectCount = collectTotal
  593. br.Ret = 200
  594. br.Success = true
  595. br.Data = resp
  596. } else if req.SourceType == 4 {
  597. // 系列问答视频收藏
  598. count, err := models.GetAskserieVideoCount(uid, sourceId)
  599. if err != nil {
  600. br.Msg = "获取数据失败!"
  601. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  602. return
  603. }
  604. resp := new(models.ArticleCollectResp)
  605. if count <= 0 {
  606. item := new(models.CygxAskserieVideoCollect)
  607. item.AskserieVideoId = sourceId
  608. item.UserId = uid
  609. item.CreateTime = time.Now()
  610. item.Mobile = user.Mobile
  611. item.Email = user.Email
  612. item.CompanyId = user.CompanyId
  613. item.CompanyName = user.CompanyName
  614. item.RealName = user.RealName
  615. item.RegisterPlatform = utils.REGISTER_PLATFORM
  616. err = models.AddCygxAskserieVideoCollect(item)
  617. if err != nil {
  618. br.Msg = "收藏失败"
  619. br.ErrMsg = "收藏失败,Err:" + err.Error()
  620. return
  621. }
  622. br.Msg = "收藏成功"
  623. resp.Status = 1
  624. // 文章收藏消息发送
  625. //go services.ArticleUserRemind(user, detail, 2)
  626. } else {
  627. err = models.RemoveAskserieVideoCollect(uid, sourceId)
  628. if err != nil {
  629. br.Msg = "取消收藏失败"
  630. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  631. return
  632. }
  633. br.Msg = "已取消收藏"
  634. resp.Status = 2
  635. }
  636. br.Ret = 200
  637. br.Success = true
  638. br.Data = resp
  639. }
  640. }
  641. // @Title 我的收藏微路演列表
  642. // @Description 我的收藏微路演列表接口
  643. // @Param PageSize query int true "每页数据条数"
  644. // @Param CurrentIndex query int true "当前页页码,从1开始"
  645. // @Success 200 {object} models.HomeListResp
  646. // @router /mycollect [get]
  647. func (this *MicroRoadShowController) Mycollect() {
  648. br := new(models.BaseResponse).Init()
  649. defer func() {
  650. this.Data["json"] = br
  651. this.ServeJSON()
  652. }()
  653. user := this.User
  654. if user == nil {
  655. br.Msg = "请登录"
  656. br.ErrMsg = "请登录,用户信息为空"
  657. br.Ret = 408
  658. return
  659. }
  660. pageSize, _ := this.GetInt("PageSize")
  661. currentIndex, _ := this.GetInt("CurrentIndex")
  662. if pageSize <= 0 {
  663. pageSize = utils.PageSize20
  664. }
  665. if currentIndex <= 0 {
  666. currentIndex = 1
  667. }
  668. userId := user.UserId
  669. listMycollect, err := models.GetUserMicroRoadshowCollectList(userId)
  670. if err != nil {
  671. br.Msg = "获取数据失败"
  672. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  673. return
  674. }
  675. listAskserieVideoCollect, err := models.GetUserCygxAskserieVideoCollectList(userId)
  676. if err != nil {
  677. br.Msg = "获取数据失败"
  678. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  679. return
  680. }
  681. var audioIds []string
  682. var videoIds []string
  683. var activityVideoIds []string
  684. var askserieVideoIds []string //问答系列视频
  685. for _, item := range listMycollect {
  686. if item.ActivityVoiceId > 0 {
  687. audioIds = append(audioIds, strconv.Itoa(item.ActivityVoiceId))
  688. } else if item.VideoId > 0 {
  689. videoIds = append(videoIds, strconv.Itoa(item.VideoId))
  690. } else if item.ActivityVideoId > 0 {
  691. activityVideoIds = append(activityVideoIds, strconv.Itoa(item.ActivityVideoId))
  692. }
  693. }
  694. for _, item := range listAskserieVideoCollect {
  695. askserieVideoIds = append(askserieVideoIds, strconv.Itoa(item.AskserieVideoId))
  696. }
  697. if len(audioIds) == 0 && len(videoIds) == 0 && len(activityVideoIds) == 0 && len(askserieVideoIds) == 0 {
  698. resp := new(models.MicroRoadShowListResp)
  699. page := paging.GetPaging(currentIndex, pageSize, 0)
  700. resp.List = make([]*models.MicroRoadShowPageList, 0)
  701. resp.Paging = page
  702. br.Ret = 200
  703. br.Success = true
  704. br.Msg = "获取成功"
  705. br.Data = resp
  706. return
  707. }
  708. audioIdstr := strings.Join(audioIds, ",")
  709. ideoIdsStr := strings.Join(videoIds, ",")
  710. activityVideoIdsStr := strings.Join(activityVideoIds, ",")
  711. askserieVideoIdsStr := strings.Join(askserieVideoIds, ",")
  712. // 微路演列表
  713. list, total, e := services.GetMicroRoadShowMycollectV12(pageSize, currentIndex, audioIdstr, activityVideoIdsStr, ideoIdsStr, askserieVideoIdsStr, user)
  714. if e != nil {
  715. br.Msg = "获取失败"
  716. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  717. return
  718. }
  719. for _, item := range list {
  720. //if item.Type == 1 {
  721. // //音频
  722. // count, err := models.GetVoiceCollectCount(user.UserId, item.Id)
  723. // if err != nil {
  724. // br.Msg = "获取数据失败!"
  725. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  726. // return
  727. // }
  728. // if count > 0 {
  729. // item.IsCollect = true
  730. // }
  731. //} else if item.Type == 2 {
  732. // //活动视频
  733. // count, err := models.GetActivityVideoCollectCount(user.UserId, item.Id)
  734. // if err != nil {
  735. // br.Msg = "获取数据失败!"
  736. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  737. // return
  738. // }
  739. // if count > 0 {
  740. // item.IsCollect = true
  741. // }
  742. //} else if item.Type == 3 {
  743. // //微路演视频
  744. // count, err := models.GetVideoCollectCount(user.UserId, item.Id)
  745. // if err != nil {
  746. // br.Msg = "获取数据失败!"
  747. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  748. // return
  749. // }
  750. // if count > 0 {
  751. // item.IsCollect = true
  752. // }
  753. //}
  754. item.IsCollect = true
  755. }
  756. // 用户权限
  757. authInfo, permissionArr, e := services.GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  758. if e != nil {
  759. br.Msg = "获取失败"
  760. br.ErrMsg = "获取用户权限失败, Err: " + e.Error()
  761. return
  762. }
  763. // 获取默认图配置
  764. audioMap, videoMap, audioShareMap, videoShareMap, e := services.GetMicroRoadShowDefaultImgConfig()
  765. if e != nil {
  766. br.Msg = "获取失败"
  767. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  768. return
  769. }
  770. for i := range list {
  771. // 权限
  772. au := new(models.UserPermissionAuthInfo)
  773. au.SellerName = authInfo.SellerName
  774. au.SellerMobile = authInfo.SellerMobile
  775. au.HasPermission = authInfo.HasPermission
  776. au.OperationMode = authInfo.OperationMode
  777. if au.HasPermission == 1 {
  778. // 非宏观权限进一步判断是否有权限
  779. if list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  780. au.HasPermission = 2
  781. }
  782. }
  783. // 无权限的弹框提示
  784. if au.HasPermission != 1 {
  785. if au.OperationMode == services.UserPermissionOperationModeCall {
  786. if list[i].Type == 1 {
  787. au.PopupMsg = services.UserPermissionPopupMsgCallActivity
  788. } else {
  789. au.PopupMsg = services.UserPermissionPopupMsgCallMicroVideo
  790. }
  791. } else {
  792. if list[i].Type == 1 {
  793. au.PopupMsg = services.UserPermissionPopupMsgApplyActivity
  794. } else {
  795. au.PopupMsg = services.UserPermissionPopupMsgApplyMicroVideo
  796. }
  797. }
  798. }
  799. list[i].AuthInfo = au
  800. list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
  801. // 默认图
  802. if list[i].BackgroundImg == "" {
  803. if list[i].Type == 1 {
  804. list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  805. } else {
  806. list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  807. }
  808. }
  809. // 分享图
  810. if list[i].ShareImg == "" {
  811. if list[i].Type == 1 {
  812. list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
  813. } else {
  814. list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
  815. }
  816. }
  817. }
  818. resp := new(models.MicroRoadShowListResp)
  819. page := paging.GetPaging(currentIndex, pageSize, total)
  820. resp.List = list
  821. resp.Paging = page
  822. br.Ret = 200
  823. br.Success = true
  824. br.Msg = "获取成功"
  825. br.Data = resp
  826. }
  827. // @Title 模版消息留言详情
  828. // @Description 模版消息留言详情接口
  829. // @Param SourceId query int true "资源ID"
  830. // @Param SourceType query int true "留言类型,1:文章、2:活动、3:微路演视频、4:活动视频、5:活动音频"
  831. // @Success Ret=200 {object} models.CygxArticleCommentWxResp
  832. // @router /comment/detail [get]
  833. func (this *MicroRoadShowController) CommentDetail() {
  834. br := new(models.BaseResponse).Init()
  835. defer func() {
  836. this.Data["json"] = br
  837. this.ServeJSON()
  838. }()
  839. user := this.User
  840. if user == nil {
  841. br.Msg = "请登录"
  842. br.ErrMsg = "请登录,用户信息为空"
  843. br.Ret = 408
  844. return
  845. }
  846. sourceId, _ := this.GetInt("SourceId")
  847. sourceType, _ := this.GetInt("SourceType")
  848. resp := new(models.CygxArticleCommentWxResp)
  849. if sourceType == 1 || sourceType == 3 || sourceType == 4 || sourceType == 5 {
  850. detail, err := models.GetArticleCommentById(sourceId)
  851. if err != nil {
  852. br.Msg = "获取失败"
  853. br.ErrMsg = "获取用户权限失败, Err: " + err.Error()
  854. return
  855. }
  856. resp.Content = detail.Content
  857. if sourceType == 1 {
  858. resp.SourceId = detail.ArticleId
  859. resp.RedirectType = 1
  860. } else if sourceType == 3 {
  861. resp.SourceId = detail.IndustryId
  862. resp.RedirectType = 3
  863. } else {
  864. resp.SourceId = detail.ActivityId
  865. resp.RedirectType = 2
  866. }
  867. } else {
  868. detail, err := models.GetCygxActivityHelpAskById(sourceId)
  869. if err != nil {
  870. br.Msg = "获取失败"
  871. br.ErrMsg = "获取用户权限失败, Err: " + err.Error()
  872. return
  873. }
  874. resp.Content = detail.Content
  875. resp.SourceId = detail.ActivityId
  876. resp.RedirectType = 2
  877. }
  878. br.Ret = 200
  879. br.Success = true
  880. br.Data = resp
  881. br.Msg = "操作成功"
  882. return
  883. }