micro_roadshow.go 18 KB

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