micro_roadshow.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hongze_clpt/models"
  6. "hongze/hongze_clpt/services"
  7. "hongze/hongze_clpt/utils"
  8. "strconv"
  9. "time"
  10. )
  11. // 微路演
  12. type MicroRoadShowController struct {
  13. BaseAuthController
  14. }
  15. // @Title 微路演列表
  16. // @Description 微路演列表接口
  17. // @Param PageSize query int true "每页数据条数"
  18. // @Param CurrentIndex query int true "当前页页码,从1开始"
  19. // @Param KeyWord query string false "搜索关键词"
  20. // @Param AudioId query int false "音频ID"
  21. // @Param VideoId query int false "视频ID"
  22. // @Param ActivityVideoId query int false "活动视频ID"
  23. // @Param Filter query string false "筛选条件 为空:全部 1:视频 2:音频 3:逻辑解析 4:路演回放 多个用 , 隔开"
  24. // @Success 200 {object} models.HomeListResp
  25. // @router /list [get]
  26. func (this *MicroRoadShowController) List() {
  27. br := new(models.BaseResponse).Init()
  28. defer func() {
  29. this.Data["json"] = br
  30. this.ServeJSON()
  31. }()
  32. user := this.User
  33. if user == nil {
  34. br.Msg = "请登录"
  35. br.ErrMsg = "请登录,用户信息为空"
  36. br.Ret = 408
  37. return
  38. }
  39. pageSize, _ := this.GetInt("PageSize")
  40. currentIndex, _ := this.GetInt("CurrentIndex")
  41. keywords := this.GetString("KeyWord")
  42. audioId, _ := this.GetInt("AudioId")
  43. videoId, _ := this.GetInt("VideoId")
  44. activityVideoId, _ := this.GetInt("ActivityVideoId")
  45. filter := this.GetString("Filter")
  46. if pageSize <= 0 {
  47. pageSize = utils.PageSize20
  48. }
  49. if currentIndex <= 0 {
  50. currentIndex = 1
  51. }
  52. var keyWordArr []string
  53. var err error
  54. if keywords != "" {
  55. keyWordArr, err = services.GetIndustryMapNameSliceV3(keywords)
  56. if err != nil {
  57. br.Msg = "获取失败"
  58. br.ErrMsg = "获取分词失败,GetIndustryMapNameSliceV3 Err: " + err.Error()
  59. return
  60. }
  61. keyWordArr = services.RemoveDuplicatesAndEmpty(keyWordArr)
  62. }
  63. var list []*models.MicroRoadShowPageList
  64. var total int
  65. var e error
  66. // 微路演列表
  67. list, total, e = services.GetMicroRoadShowPageListV8(pageSize, currentIndex, audioId, videoId, activityVideoId, filter, keywords)
  68. if e != nil {
  69. br.Msg = "获取失败"
  70. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  71. return
  72. }
  73. var pageSizeIk int
  74. //获取总的数量
  75. totalIk, e := services.CountMicroRoadShowPageListIkWord(audioId, videoId, activityVideoId, keyWordArr, filter)
  76. if e != nil {
  77. br.Msg = "获取失败"
  78. br.ErrMsg = "获取微路演联想词列表失败, Err: " + e.Error()
  79. return
  80. }
  81. //return
  82. pageSizeIk = totalIk - len(list)
  83. //处理IK分词部分的分页获取条数
  84. startSizeIk := utils.StartIndex(currentIndex, pageSize)
  85. startSizeIk = startSizeIk - total
  86. if startSizeIk < 0 {
  87. startSizeIk = 0
  88. }
  89. if pageSizeIk > 0 {
  90. lisIk, e := services.GetMicroRoadShowPageListIkWord(startSizeIk, pageSizeIk, audioId, videoId, activityVideoId, keyWordArr, filter, keywords)
  91. if e != nil {
  92. br.Msg = "获取失败"
  93. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  94. return
  95. }
  96. for _, item := range lisIk {
  97. list = append(list, item)
  98. }
  99. }
  100. userId := user.UserId
  101. listMycollect, err := models.GetUserMicroRoadshowCollectList(userId)
  102. if err != nil {
  103. br.Msg = "获取数据失败"
  104. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  105. return
  106. }
  107. mapaudioIds := make(map[int]int) //活动音频
  108. mapvideoIds := make(map[int]int) // 微路演视频
  109. mapactivityVideoIds := make(map[int]int) // 活动视频
  110. for _, item := range listMycollect {
  111. if item.ActivityVoiceId > 0 {
  112. mapaudioIds[item.ActivityVoiceId] = item.ActivityVoiceId
  113. } else if item.VideoId > 0 {
  114. mapvideoIds[item.VideoId] = item.VideoId
  115. } else if item.ActivityVideoId > 0 {
  116. mapactivityVideoIds[item.ActivityVoiceId] = item.ActivityVoiceId
  117. }
  118. }
  119. for _, item := range list {
  120. if item.Type == 1 {
  121. //音频
  122. if mapaudioIds[item.Id] > 0 {
  123. item.IsCollect = true
  124. }
  125. } else if item.Type == 2 {
  126. //活动视频
  127. if mapactivityVideoIds[item.Id] > 0 {
  128. item.IsCollect = true
  129. }
  130. } else if item.Type == 3 {
  131. //微路演视频
  132. if mapvideoIds[item.Id] > 0 {
  133. item.IsCollect = true
  134. }
  135. }
  136. }
  137. // 用户权限
  138. authInfo, permissionArr, e := services.GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  139. if e != nil {
  140. br.Msg = "获取失败"
  141. br.ErrMsg = "获取用户权限失败, Err: " + e.Error()
  142. return
  143. }
  144. // 获取默认图配置
  145. audioMap, videoMap, audioShareMap, videoShareMap, e := services.GetMicroRoadShowDefaultImgConfig()
  146. if e != nil {
  147. br.Msg = "获取失败"
  148. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  149. return
  150. }
  151. for i := range list {
  152. // 权限
  153. au := new(models.UserPermissionAuthInfo)
  154. au.SellerName = authInfo.SellerName
  155. au.SellerMobile = authInfo.SellerMobile
  156. au.HasPermission = authInfo.HasPermission
  157. au.OperationMode = authInfo.OperationMode
  158. if au.HasPermission == 1 {
  159. // 非宏观权限进一步判断是否有权限
  160. if list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  161. au.HasPermission = 2
  162. }
  163. }
  164. // 无权限的弹框提示
  165. if au.HasPermission != 1 {
  166. if au.OperationMode == services.UserPermissionOperationModeCall {
  167. if list[i].Type == 1 {
  168. au.PopupMsg = services.UserPermissionPopupMsgCallActivity
  169. } else {
  170. au.PopupMsg = services.UserPermissionPopupMsgCallMicroVideo
  171. }
  172. } else {
  173. if list[i].Type == 1 {
  174. au.PopupMsg = services.UserPermissionPopupMsgApplyActivity
  175. } else {
  176. au.PopupMsg = services.UserPermissionPopupMsgApplyMicroVideo
  177. }
  178. }
  179. }
  180. list[i].AuthInfo = au
  181. list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
  182. // 默认图
  183. if list[i].BackgroundImg == "" {
  184. if list[i].Type == 1 {
  185. list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  186. } else {
  187. list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  188. }
  189. }
  190. // 分享图
  191. if list[i].ShareImg == "" {
  192. if list[i].Type == 1 {
  193. list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
  194. } else {
  195. list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
  196. }
  197. }
  198. }
  199. resp := new(models.MicroRoadShowListResp)
  200. page := paging.GetPaging(currentIndex, pageSize, totalIk)
  201. resp.List = list
  202. resp.Paging = page
  203. br.Ret = 200
  204. br.Success = true
  205. br.Msg = "获取成功"
  206. br.Data = resp
  207. }
  208. // @Title 视频详情
  209. // @Description 时间线接口
  210. // @Param VideoId query int true "视频ID"
  211. // @Success 200 {object} models.IndustryVideoDetailResp
  212. // @router /detail [get]
  213. func (this *MicroRoadShowController) Detail() {
  214. br := new(models.BaseResponse).Init()
  215. defer func() {
  216. this.Data["json"] = br
  217. this.ServeJSON()
  218. }()
  219. user := this.User
  220. if user == nil {
  221. br.Msg = "请重新登录"
  222. br.Ret = 408
  223. return
  224. }
  225. videoId, _ := this.GetInt("VideoId")
  226. videoSimple, au, err := services.GetindustryVideoDetailById(user, videoId)
  227. if err != nil {
  228. br.Msg = "获取失败"
  229. br.ErrMsg = "获取用户权限失败, Err: " + err.Error()
  230. return
  231. }
  232. resp := new(models.IndustryVideoDetailResp)
  233. resp.IndustryVideo = videoSimple
  234. resp.AuthInfo = au
  235. br.Ret = 200
  236. br.Success = true
  237. br.Msg = "获取成功"
  238. br.Data = resp
  239. }
  240. // @Title 记录用户浏览音频回放接口
  241. // @Description 记录用户浏览音频回放接口
  242. // @Param request body models.ActivityIdRep true "type json string"
  243. // @Success Ret=200 {object} models.AddVideoHistoryReq
  244. // @router /videoHistory/add [post]
  245. func (this *MicroRoadShowController) VideoHistoryAdd() {
  246. br := new(models.BaseResponse).Init()
  247. defer func() {
  248. this.Data["json"] = br
  249. this.ServeJSON()
  250. }()
  251. user := this.User
  252. if user == nil {
  253. br.Msg = "请登录"
  254. br.ErrMsg = "请登录,用户信息为空"
  255. br.Ret = 408
  256. return
  257. }
  258. uid := user.UserId
  259. var req models.AddVideoHistoryReq
  260. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  261. if err != nil {
  262. br.Msg = "参数解析异常!"
  263. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  264. return
  265. }
  266. videoId := req.VideoId
  267. playSeconds := req.PlaySeconds
  268. var sellerName string
  269. sellerName, err = models.GetCompanySellerName(user.CompanyId)
  270. if err != nil {
  271. br.Msg = "报名失败!"
  272. br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
  273. return
  274. }
  275. item := models.CygxMicroRoadshowVideoHistory{
  276. VideoId: videoId,
  277. UserId: uid,
  278. Mobile: user.Mobile,
  279. Email: user.Email,
  280. CompanyId: user.CompanyId,
  281. CompanyName: user.CompanyName,
  282. RealName: user.RealName,
  283. SellerName: sellerName,
  284. PlaySeconds: strconv.Itoa(playSeconds),
  285. CreateTime: time.Now(),
  286. ModifyTime: time.Now(),
  287. }
  288. //if playSeconds != 0 {
  289. // lastItem, err := models.GetLastCygxMicroRoadshowVideoHistory(videoId, user.UserId)
  290. // if err != nil {
  291. // br.Msg = "操作失败"
  292. // br.ErrMsg = "操作失败,GetLastCygxMicroRoadshowVideoHistory Err:" + err.Error()
  293. // return
  294. // }
  295. // err = models.UpdateLastCygxActivityVideoHistory(strconv.Itoa(playSeconds), lastItem.Id)
  296. // if err != nil {
  297. // br.Msg = "更新失败"
  298. // br.ErrMsg = "更新失败,UpdateLastCygxActivityVideoHistory Err:" + err.Error()
  299. // return
  300. // }
  301. //} else {
  302. // err = models.AddCygxMicroRoadshowVideoHistory(&item)
  303. // if err != nil {
  304. // br.Msg = "操作失败"
  305. // br.ErrMsg = "操作失败,Err:" + err.Error()
  306. // return
  307. // }
  308. // err = models.UpdateCygxActivityVideoCounts(videoId)
  309. // if err != nil {
  310. // br.Msg = "更新失败"
  311. // br.ErrMsg = "更新失败,Err:" + err.Error()
  312. // return
  313. // }
  314. //}
  315. err = models.AddCygxMicroRoadshowVideoHistory(&item)
  316. if err != nil {
  317. br.Msg = "操作失败"
  318. br.ErrMsg = "操作失败,Err:" + err.Error()
  319. return
  320. }
  321. err = models.UpdateCygxActivityVideoCounts(videoId)
  322. if err != nil {
  323. br.Msg = "更新失败"
  324. br.ErrMsg = "更新失败,Err:" + err.Error()
  325. return
  326. }
  327. br.Ret = 200
  328. br.Success = true
  329. br.Msg = "操作成功"
  330. return
  331. }
  332. // @Title 微路演新增留言
  333. // @Description 微路演新增留言接口
  334. // @Param request body models.AddVideoCommnetReq true "type json string"
  335. // @Success Ret=200 {object} models.AppointmentResp
  336. // @router /comment/add [post]
  337. func (this *MicroRoadShowController) CommentAdd() {
  338. br := new(models.BaseResponse).Init()
  339. defer func() {
  340. this.Data["json"] = br
  341. this.ServeJSON()
  342. }()
  343. user := this.User
  344. if user == nil {
  345. br.Msg = "请登录"
  346. br.ErrMsg = "请登录,用户信息为空"
  347. br.Ret = 408
  348. return
  349. }
  350. uid := user.UserId
  351. var req models.AddVideoCommnetReq
  352. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  353. if err != nil {
  354. br.Msg = "参数解析异常!"
  355. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  356. return
  357. }
  358. content := req.Content
  359. if content == "" {
  360. br.Msg = "留言内容不能为空!"
  361. return
  362. }
  363. //itemToken, err := services.WxGetToken()
  364. //if err != nil {
  365. // br.Msg = "GetWxAccessToken Err:" + err.Error()
  366. // return
  367. //}
  368. //if itemToken.AccessToken == "" {
  369. // br.Msg = "accessToken is empty"
  370. // return
  371. //}
  372. //commerr, err := weapp.MSGSecCheck(itemToken.AccessToken, content)
  373. //if err != nil {
  374. // br.Msg = "内容校验失败!"
  375. // br.ErrMsg = "内容校验失败,Err:" + err.Error()
  376. // return
  377. //}
  378. //if commerr.ErrCode != 0 {
  379. // br.Msg = "内容违规,请重新提交!"
  380. // br.ErrMsg = "内容违规,Err:" + commerr.ErrMSG
  381. // return
  382. //}
  383. sourceType := req.SourceType
  384. if sourceType == 0 {
  385. sourceType = 1
  386. }
  387. item := models.CygxArticleComment{
  388. UserId: uid,
  389. CreateTime: time.Now(),
  390. RealName: user.RealName,
  391. Mobile: user.Mobile,
  392. Email: user.Email,
  393. CompanyId: user.CompanyId,
  394. CompanyName: user.CompanyName,
  395. Content: req.Content,
  396. Title: req.Title,
  397. }
  398. var resourceId int
  399. if sourceType == 1 {
  400. activityVoiceInfo, _ := models.GetCygxActivityVoiceById(req.Id)
  401. if activityVoiceInfo == nil {
  402. br.Msg = "操作失败"
  403. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(req.Id)
  404. return
  405. }
  406. item.ActivityId = activityVoiceInfo.ActivityId
  407. item.Title = activityVoiceInfo.VoiceName
  408. item.ActivityVoiceId = activityVoiceInfo.ActivityVoiceId
  409. resourceId = activityVoiceInfo.ActivityId
  410. } else if sourceType == 2 {
  411. activityInfo, _ := models.GetCygxActivityVideoById(req.Id)
  412. if activityInfo == nil {
  413. br.Msg = "操作失败"
  414. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(req.Id)
  415. return
  416. }
  417. item.Title = activityInfo.Title
  418. item.VideoId = activityInfo.Id
  419. item.ActivityId = activityInfo.ActivityId
  420. resourceId = activityInfo.ActivityId
  421. } else if sourceType == 3 {
  422. item.VideoId = req.Id
  423. microVideo, e := models.GetMicroRoadshowVideoById(req.Id)
  424. if e != nil {
  425. br.Msg = "操作失败"
  426. br.ErrMsg = "微路演视频信息有误, 不存在的VideoId: " + strconv.Itoa(req.Id)
  427. return
  428. }
  429. item.Title = microVideo.VideoName
  430. item.IndustryId = microVideo.IndustryId
  431. resourceId = microVideo.IndustryId
  432. }
  433. _, err = models.AddArticleComment(&item)
  434. if err != nil {
  435. br.Msg = "提交失败"
  436. br.ErrMsg = "提交留言失败,Err:" + err.Error()
  437. return
  438. }
  439. services.SendWxMsgWithMicroRoadshowAsk(req, user, resourceId)
  440. br.Ret = 200
  441. br.Success = true
  442. br.Msg = "操作成功"
  443. return
  444. }
  445. // @Title 微路演收藏
  446. // @Description 微路演收藏
  447. // @Param request body models.MicroRoadshowCollectReq true "type json string"
  448. // @Success 200 {object} models.FontsCollectResp
  449. // @router /collect [post]
  450. func (this *MicroRoadShowController) Collect() {
  451. br := new(models.BaseResponse).Init()
  452. defer func() {
  453. this.Data["json"] = br
  454. this.ServeJSON()
  455. }()
  456. user := this.User
  457. if user == nil {
  458. br.Msg = "请重新登录"
  459. br.Ret = 408
  460. return
  461. }
  462. uid := user.UserId
  463. var req models.MicroRoadshowCollectReq
  464. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  465. if err != nil {
  466. br.Msg = "参数解析异常!"
  467. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  468. return
  469. }
  470. if req.SourceType == 1 {
  471. _, err := models.GetCygxActivityVoiceById(req.Id)
  472. if err != nil {
  473. br.Msg = "获取信息失败"
  474. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  475. return
  476. }
  477. count, err := models.GetVoiceCollectCount(uid, req.Id)
  478. if err != nil {
  479. br.Msg = "获取数据失败!"
  480. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  481. return
  482. }
  483. resp := new(models.ArticleCollectResp)
  484. if count <= 0 {
  485. item := new(models.CygxArticleCollect)
  486. item.ActivityVoiceId = req.Id
  487. item.UserId = uid
  488. item.CreateTime = time.Now()
  489. item.Mobile = user.Mobile
  490. item.Email = user.Email
  491. item.CompanyId = user.CompanyId
  492. item.CompanyName = user.CompanyName
  493. item.RealName = user.RealName
  494. _, err = models.AddCygxArticleCollect(item)
  495. if err != nil {
  496. br.Msg = "收藏失败"
  497. br.ErrMsg = "收藏失败,Err:" + err.Error()
  498. return
  499. }
  500. br.Msg = "收藏成功"
  501. resp.Status = 1
  502. // 文章收藏消息发送
  503. //go services.ArticleUserRemind(user, detail, 2)
  504. } else {
  505. err = models.RemoveVoiceCollect(uid, req.Id)
  506. if err != nil {
  507. br.Msg = "取消收藏失败"
  508. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  509. return
  510. }
  511. br.Msg = "已取消收藏"
  512. resp.Status = 2
  513. }
  514. collectTotal, err := models.GetVoiceCollectUsersCount(req.Id)
  515. if err != nil {
  516. br.Msg = "获取数据失败"
  517. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  518. return
  519. }
  520. resp.CollectCount = collectTotal
  521. br.Ret = 200
  522. br.Success = true
  523. br.Data = resp
  524. } else if req.SourceType == 2 {
  525. _, err := models.GetCygxActivityVideoById(req.Id)
  526. if err != nil {
  527. br.Msg = "获取信息失败"
  528. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  529. return
  530. }
  531. count, err := models.GetActivityVideoCollectCount(uid, req.Id)
  532. if err != nil {
  533. br.Msg = "获取数据失败!"
  534. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  535. return
  536. }
  537. resp := new(models.ArticleCollectResp)
  538. if count <= 0 {
  539. item := new(models.CygxArticleCollect)
  540. item.ActivityVideoId = req.Id
  541. item.UserId = uid
  542. item.CreateTime = time.Now()
  543. item.Mobile = user.Mobile
  544. item.Email = user.Email
  545. item.CompanyId = user.CompanyId
  546. item.CompanyName = user.CompanyName
  547. item.RealName = user.RealName
  548. _, err = models.AddCygxArticleCollect(item)
  549. if err != nil {
  550. br.Msg = "收藏失败"
  551. br.ErrMsg = "收藏失败,Err:" + err.Error()
  552. return
  553. }
  554. br.Msg = "收藏成功"
  555. resp.Status = 1
  556. // 文章收藏消息发送
  557. //go services.ArticleUserRemind(user, detail, 2)
  558. } else {
  559. err = models.RemoveActivityVideoCollect(uid, req.Id)
  560. if err != nil {
  561. br.Msg = "取消收藏失败"
  562. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  563. return
  564. }
  565. br.Msg = "已取消收藏"
  566. resp.Status = 2
  567. }
  568. collectTotal, err := models.GetActivityVideoCollectUsersCount(req.Id)
  569. if err != nil {
  570. br.Msg = "获取数据失败"
  571. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  572. return
  573. }
  574. resp.CollectCount = collectTotal
  575. br.Ret = 200
  576. br.Success = true
  577. br.Data = resp
  578. } else if req.SourceType == 3 {
  579. _, err := models.GetMicroRoadshowVideoById(req.Id)
  580. if err != nil {
  581. br.Msg = "获取信息失败"
  582. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  583. return
  584. }
  585. count, err := models.GetVideoCollectCount(uid, req.Id)
  586. if err != nil {
  587. br.Msg = "获取数据失败!"
  588. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  589. return
  590. }
  591. resp := new(models.ArticleCollectResp)
  592. if count <= 0 {
  593. item := new(models.CygxArticleCollect)
  594. item.VideoId = req.Id
  595. item.UserId = uid
  596. item.CreateTime = time.Now()
  597. item.Mobile = user.Mobile
  598. item.Email = user.Email
  599. item.CompanyId = user.CompanyId
  600. item.CompanyName = user.CompanyName
  601. item.RealName = user.RealName
  602. _, err = models.AddCygxArticleCollect(item)
  603. if err != nil {
  604. br.Msg = "收藏失败"
  605. br.ErrMsg = "收藏失败,Err:" + err.Error()
  606. return
  607. }
  608. br.Msg = "收藏成功"
  609. resp.Status = 1
  610. // 文章收藏消息发送
  611. //go services.ArticleUserRemind(user, detail, 2)
  612. } else {
  613. err = models.RemoveVideoCollect(uid, req.Id)
  614. if err != nil {
  615. br.Msg = "取消收藏失败"
  616. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  617. return
  618. }
  619. br.Msg = "已取消收藏"
  620. resp.Status = 2
  621. }
  622. collectTotal, err := models.GetVideoCollectUsersCount(req.Id)
  623. if err != nil {
  624. br.Msg = "获取数据失败"
  625. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  626. return
  627. }
  628. resp.CollectCount = collectTotal
  629. br.Ret = 200
  630. br.Success = true
  631. br.Data = resp
  632. }
  633. }