video.go 3.4 KB

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