micro_roadshow.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  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. "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 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 len(keyWordArr) > 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. sourceType := req.SourceType
  365. title := req.Title
  366. if sourceType == 0 {
  367. sourceType = 1
  368. }
  369. item := models.CygxArticleComment{
  370. UserId: uid,
  371. CreateTime: time.Now(),
  372. RealName: user.RealName,
  373. Mobile: user.Mobile,
  374. Email: user.Email,
  375. CompanyId: user.CompanyId,
  376. CompanyName: user.CompanyName,
  377. Content: req.Content,
  378. Title: req.Title,
  379. }
  380. //var resourceId int
  381. if sourceType == 1 {
  382. activityVoiceInfo, _ := models.GetCygxActivityVoiceById(req.Id)
  383. if activityVoiceInfo == nil {
  384. br.Msg = "操作失败"
  385. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(req.Id)
  386. return
  387. }
  388. item.ActivityId = activityVoiceInfo.ActivityId
  389. item.Title = activityVoiceInfo.VoiceName
  390. item.ActivityVoiceId = activityVoiceInfo.ActivityVoiceId
  391. title = activityVoiceInfo.VoiceName
  392. //resourceId = activityVoiceInfo.ActivityId
  393. } else if sourceType == 2 {
  394. activityInfo, _ := models.GetCygxActivityVideoById(req.Id)
  395. if activityInfo == nil {
  396. br.Msg = "操作失败"
  397. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(req.Id)
  398. return
  399. }
  400. item.Title = activityInfo.Title
  401. item.VideoId = activityInfo.Id
  402. item.ActivityId = activityInfo.ActivityId
  403. title = activityInfo.Title
  404. //resourceId = activityInfo.ActivityId
  405. } else if sourceType == 3 {
  406. item.VideoId = req.Id
  407. microVideo, e := models.GetMicroRoadshowVideoById(req.Id)
  408. if e != nil {
  409. br.Msg = "操作失败"
  410. br.ErrMsg = "微路演视频信息有误, 不存在的VideoId: " + strconv.Itoa(req.Id)
  411. return
  412. }
  413. item.Title = microVideo.VideoName
  414. item.IndustryId = microVideo.IndustryId
  415. title = microVideo.VideoName
  416. //resourceId = microVideo.IndustryId
  417. }
  418. var isResearch bool // 是否属于研选
  419. if sourceType == 2 || sourceType == 3 {
  420. detail, err := models.GetAddActivityInfoById(req.Id)
  421. if err != nil {
  422. br.Msg = "操作失败"
  423. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(req.Id)
  424. return
  425. }
  426. if strings.Contains(detail.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  427. isResearch = true
  428. }
  429. }
  430. msgId, err := models.AddArticleComment(&item)
  431. if err != nil {
  432. br.Msg = "提交失败"
  433. br.ErrMsg = "提交留言失败,Err:" + err.Error()
  434. return
  435. }
  436. services.SendWxMsgWithMicroRoadshowAsk(req, user, sourceType, int(msgId), title, isResearch)
  437. br.Ret = 200
  438. br.Success = true
  439. br.Msg = "操作成功"
  440. return
  441. }
  442. // @Title 微路演收藏
  443. // @Description 微路演收藏
  444. // @Param request body models.MicroRoadshowCollectReq true "type json string"
  445. // @Success 200 {object} models.FontsCollectResp
  446. // @router /collect [post]
  447. func (this *MicroRoadShowController) Collect() {
  448. br := new(models.BaseResponse).Init()
  449. defer func() {
  450. this.Data["json"] = br
  451. this.ServeJSON()
  452. }()
  453. user := this.User
  454. if user == nil {
  455. br.Msg = "请重新登录"
  456. br.Ret = 408
  457. return
  458. }
  459. uid := user.UserId
  460. var req models.MicroRoadshowCollectReq
  461. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  462. if err != nil {
  463. br.Msg = "参数解析异常!"
  464. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  465. return
  466. }
  467. if req.SourceType == 1 {
  468. _, err := models.GetCygxActivityVoiceById(req.Id)
  469. if err != nil {
  470. br.Msg = "获取信息失败"
  471. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  472. return
  473. }
  474. count, err := models.GetVoiceCollectCount(uid, req.Id)
  475. if err != nil {
  476. br.Msg = "获取数据失败!"
  477. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  478. return
  479. }
  480. resp := new(models.ArticleCollectResp)
  481. if count <= 0 {
  482. item := new(models.CygxArticleCollect)
  483. item.ActivityVoiceId = req.Id
  484. item.UserId = uid
  485. item.CreateTime = time.Now()
  486. item.Mobile = user.Mobile
  487. item.Email = user.Email
  488. item.CompanyId = user.CompanyId
  489. item.CompanyName = user.CompanyName
  490. item.RealName = user.RealName
  491. _, err = models.AddCygxArticleCollect(item)
  492. if err != nil {
  493. br.Msg = "收藏失败"
  494. br.ErrMsg = "收藏失败,Err:" + err.Error()
  495. return
  496. }
  497. br.Msg = "收藏成功"
  498. resp.Status = 1
  499. // 文章收藏消息发送
  500. //go services.ArticleUserRemind(user, detail, 2)
  501. } else {
  502. err = models.RemoveVoiceCollect(uid, req.Id)
  503. if err != nil {
  504. br.Msg = "取消收藏失败"
  505. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  506. return
  507. }
  508. br.Msg = "已取消收藏"
  509. resp.Status = 2
  510. }
  511. collectTotal, err := models.GetVoiceCollectUsersCount(req.Id)
  512. if err != nil {
  513. br.Msg = "获取数据失败"
  514. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  515. return
  516. }
  517. resp.CollectCount = collectTotal
  518. br.Ret = 200
  519. br.Success = true
  520. br.Data = resp
  521. } else if req.SourceType == 2 {
  522. _, err := models.GetCygxActivityVideoById(req.Id)
  523. if err != nil {
  524. br.Msg = "获取信息失败"
  525. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  526. return
  527. }
  528. count, err := models.GetActivityVideoCollectCount(uid, req.Id)
  529. if err != nil {
  530. br.Msg = "获取数据失败!"
  531. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  532. return
  533. }
  534. resp := new(models.ArticleCollectResp)
  535. if count <= 0 {
  536. item := new(models.CygxArticleCollect)
  537. item.ActivityVideoId = req.Id
  538. item.UserId = uid
  539. item.CreateTime = time.Now()
  540. item.Mobile = user.Mobile
  541. item.Email = user.Email
  542. item.CompanyId = user.CompanyId
  543. item.CompanyName = user.CompanyName
  544. item.RealName = user.RealName
  545. _, err = models.AddCygxArticleCollect(item)
  546. if err != nil {
  547. br.Msg = "收藏失败"
  548. br.ErrMsg = "收藏失败,Err:" + err.Error()
  549. return
  550. }
  551. br.Msg = "收藏成功"
  552. resp.Status = 1
  553. // 文章收藏消息发送
  554. //go services.ArticleUserRemind(user, detail, 2)
  555. } else {
  556. err = models.RemoveActivityVideoCollect(uid, req.Id)
  557. if err != nil {
  558. br.Msg = "取消收藏失败"
  559. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  560. return
  561. }
  562. br.Msg = "已取消收藏"
  563. resp.Status = 2
  564. }
  565. collectTotal, err := models.GetActivityVideoCollectUsersCount(req.Id)
  566. if err != nil {
  567. br.Msg = "获取数据失败"
  568. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  569. return
  570. }
  571. resp.CollectCount = collectTotal
  572. br.Ret = 200
  573. br.Success = true
  574. br.Data = resp
  575. } else if req.SourceType == 3 {
  576. _, err := models.GetMicroRoadshowVideoById(req.Id)
  577. if err != nil {
  578. br.Msg = "获取信息失败"
  579. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  580. return
  581. }
  582. count, err := models.GetVideoCollectCount(uid, req.Id)
  583. if err != nil {
  584. br.Msg = "获取数据失败!"
  585. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  586. return
  587. }
  588. resp := new(models.ArticleCollectResp)
  589. if count <= 0 {
  590. item := new(models.CygxArticleCollect)
  591. item.VideoId = req.Id
  592. item.UserId = uid
  593. item.CreateTime = time.Now()
  594. item.Mobile = user.Mobile
  595. item.Email = user.Email
  596. item.CompanyId = user.CompanyId
  597. item.CompanyName = user.CompanyName
  598. item.RealName = user.RealName
  599. _, err = models.AddCygxArticleCollect(item)
  600. if err != nil {
  601. br.Msg = "收藏失败"
  602. br.ErrMsg = "收藏失败,Err:" + err.Error()
  603. return
  604. }
  605. br.Msg = "收藏成功"
  606. resp.Status = 1
  607. // 文章收藏消息发送
  608. //go services.ArticleUserRemind(user, detail, 2)
  609. } else {
  610. err = models.RemoveVideoCollect(uid, req.Id)
  611. if err != nil {
  612. br.Msg = "取消收藏失败"
  613. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  614. return
  615. }
  616. br.Msg = "已取消收藏"
  617. resp.Status = 2
  618. }
  619. collectTotal, err := models.GetVideoCollectUsersCount(req.Id)
  620. if err != nil {
  621. br.Msg = "获取数据失败"
  622. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  623. return
  624. }
  625. resp.CollectCount = collectTotal
  626. br.Ret = 200
  627. br.Success = true
  628. br.Data = resp
  629. }
  630. }