video.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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, varietyTagId 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 varietyTagId > 0 {
  20. condition["variety_tag_id ="] = varietyTagId
  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. VarietyTagId: v.VarietyTagId,
  40. VarietyTagName: v.VarietyTagName,
  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. ChartPermissionName: v.VarietyTagName,
  49. }
  50. resp = append(resp, item)
  51. }
  52. return
  53. }
  54. // SaveVideoPlayLog 记录用户播放视频日志
  55. func SaveVideoPlayLog(userInfo user.UserInfo, videoId, sourceAgent int) (errMsg string, err error) {
  56. video, e := yb_community_video.GetItemById(videoId)
  57. if e != nil {
  58. errMsg = "视频不存在或未发布"
  59. err = errors.New("获取视频信息失败, Err: " + e.Error())
  60. return
  61. }
  62. companyInfo, e := company_product.GetByCompany2ProductId(userInfo.CompanyID, 1)
  63. if e != nil && e != utils.ErrNoRow {
  64. errMsg = "保存失败"
  65. err = errors.New("获取客户信息失败, Err: " + e.Error())
  66. return
  67. }
  68. companyName := "潜在客户"
  69. companyStatus := "潜在"
  70. if companyInfo != nil && companyInfo.CompanyID > 0 {
  71. companyName = companyInfo.CompanyName
  72. companyStatus = companyInfo.Status
  73. }
  74. item := &yb_community_video_play_log.YbCommunityVideoPlayLog{
  75. CommunityVideoID: video.CommunityVideoID,
  76. UserID: int(userInfo.UserID),
  77. Mobile: userInfo.Mobile,
  78. RealName: userInfo.RealName,
  79. NickName: userInfo.NickName,
  80. CompanyID: int(userInfo.CompanyID),
  81. CompanyName: companyName,
  82. CompanyStatus: companyStatus,
  83. SourceAgent: sourceAgent,
  84. SellerID: companyInfo.SellerID,
  85. CreateTime: time.Now().Local(),
  86. }
  87. if e = item.Create(); e != nil {
  88. errMsg = "操作失败"
  89. err = errors.New("新增播放视频日志失败, Err:" + e.Error())
  90. return
  91. }
  92. return
  93. }