video.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package community
  2. import (
  3. "errors"
  4. "hongze/hongze_yb/models/response"
  5. "hongze/hongze_yb/models/tables/company_product"
  6. "hongze/hongze_yb/models/tables/yb_community_video"
  7. "hongze/hongze_yb/models/tables/yb_community_video_play_log"
  8. "hongze/hongze_yb/services/user"
  9. "hongze/hongze_yb/utils"
  10. "time"
  11. )
  12. // GetVideoList 获取视频列表
  13. func GetVideoList(pageIndex, pageSize, videoId, chartPermissionId int, keywords string) (resp []*response.CommunityVideoItem, err error) {
  14. condition := make(map[string]interface{})
  15. // 分享点进来的直接定位到具体视频
  16. if videoId > 0 {
  17. condition["community_video_id ="] = videoId
  18. } else {
  19. if chartPermissionId > 0 {
  20. condition["chart_permission_id ="] = chartPermissionId
  21. }
  22. if keywords != "" {
  23. condition["title like"] = "%" + keywords + "%"
  24. }
  25. }
  26. resp = make([]*response.CommunityVideoItem, 0)
  27. list, e := yb_community_video.GetPageListByCondition(condition, pageIndex, pageSize)
  28. if e != nil {
  29. err = errors.New("获取视频列表失败, Err:" + e.Error())
  30. return
  31. }
  32. if len(list) <= 0 {
  33. return
  34. }
  35. for _, v := range list {
  36. item := &response.CommunityVideoItem{
  37. CommunityVideoID: v.CommunityVideoID,
  38. Title: v.Title,
  39. ChartPermissionID: v.ChartPermissionID,
  40. ChartPermissionName: v.ChartPermissionName,
  41. CoverImgUrl: v.CoverImgURL,
  42. VideoUrl: v.VideoURL,
  43. VideoSeconds: v.VideoSeconds,
  44. PublishState: v.PublishState,
  45. PublishTime: v.PublishTime.Format(utils.FormatDateTime),
  46. CreateTime: v.CreateTime.Format(utils.FormatDateTime),
  47. ModifyTime: v.ModifyTime.Format(utils.FormatDateTime),
  48. }
  49. resp = append(resp, item)
  50. }
  51. return
  52. }
  53. // SaveVideoPlayLog 记录用户播放视频日志
  54. func SaveVideoPlayLog(userInfo user.UserInfo, videoId, sourceAgent int) (errMsg string, err error) {
  55. video, e := yb_community_video.GetItemById(videoId)
  56. if e != nil {
  57. errMsg = "视频不存在或未发布"
  58. err = errors.New("获取视频信息失败, Err: " + e.Error())
  59. return
  60. }
  61. companyInfo, e := company_product.GetByCompany2ProductId(userInfo.CompanyID, 1)
  62. if e != nil && e != utils.ErrNoRow {
  63. errMsg = "保存失败"
  64. err = errors.New("获取客户信息失败, Err: " + e.Error())
  65. return
  66. }
  67. var companyName, companyStatus string
  68. if companyInfo != nil {
  69. companyName = companyInfo.CompanyName
  70. companyStatus = companyInfo.Status
  71. } else {
  72. // 是否是权益用户-视作潜在用户
  73. equityCompany, e := company_product.GetByCompany2ProductId(userInfo.CompanyID, 2)
  74. if e != nil && e != utils.ErrNoRow {
  75. errMsg = "保存失败"
  76. err = errors.New("获取客户权益信息失败, Err: " + e.Error())
  77. return
  78. }
  79. if equityCompany != nil {
  80. companyName = equityCompany.CompanyName
  81. companyStatus = "潜在"
  82. }
  83. }
  84. item := &yb_community_video_play_log.YbCommunityVideoPlayLog{
  85. CommunityVideoID: video.CommunityVideoID,
  86. UserID: int(userInfo.UserID),
  87. Mobile: userInfo.Mobile,
  88. RealName: userInfo.RealName,
  89. NickName: userInfo.NickName,
  90. CompanyID: int(userInfo.CompanyID),
  91. CompanyName: companyName,
  92. CompanyStatus: companyStatus,
  93. SourceAgent: sourceAgent,
  94. CreateTime: time.Now().Local(),
  95. }
  96. if e = item.Create(); e != nil {
  97. errMsg = "操作失败"
  98. err = errors.New("新增播放视频日志失败, Err:" + e.Error())
  99. return
  100. }
  101. return
  102. }