view_log.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package view_log
  2. import (
  3. "errors"
  4. "gorm.io/gorm"
  5. "hongze/hongze_yb/models/tables/company_product"
  6. "hongze/hongze_yb/models/tables/yb_activity"
  7. "hongze/hongze_yb/models/tables/yb_view_log"
  8. "hongze/hongze_yb/services/user"
  9. "time"
  10. )
  11. func AddViewLog(item *yb_view_log.YbViewLog) (id uint64, err error) {
  12. //查询对应的客户信息
  13. companyProduct, err := company_product.GetByCompany2ProductId(item.CompanyId, 1)
  14. if err != nil {
  15. return
  16. }
  17. //增加记录
  18. item.CompanyName = companyProduct.CompanyName
  19. item.CompanyStatus = companyProduct.Status
  20. item.SellerId = companyProduct.SellerID
  21. err = item.Create()
  22. if err != nil {
  23. return
  24. }
  25. return item.Id, nil
  26. }
  27. func UpdateActivityAudioLog(userinfo user.UserInfo, req yb_view_log.ActivityAudioLogStopReq) (err error) {
  28. viewLog := new(yb_view_log.YbViewLog)
  29. viewLog.Id = req.Id
  30. item, err := viewLog.GetById()
  31. if err != nil {
  32. if err == gorm.ErrRecordNotFound {
  33. return
  34. }
  35. return
  36. }
  37. if item.UserId != userinfo.UserID {
  38. err = errors.New("用户不一致, 更新日志失败")
  39. return
  40. }
  41. //更新音频停止的时间
  42. item.StopSeconds = req.StopSeconds
  43. item.ModifyTime = time.Now()
  44. err = item.Update([]string{"stop_seconds", "modify_time"})
  45. return
  46. }
  47. func AddActivityAudioLog(userinfo user.UserInfo, req yb_view_log.ActivityAudioLogAddReq)(resp yb_view_log.ActivityAudioLogAddResp, err error) {
  48. //查询报告相关
  49. var activityDetail *yb_activity.ActivityDetail
  50. ybViewLog := new(yb_view_log.YbViewLog)
  51. if req.ExtendId <= 0 {
  52. err = errors.New("请输入活动ID")
  53. return
  54. }
  55. //根据活动ID查询报告信息
  56. activityDetail, err = yb_activity.GetDetailById(req.ExtendId)
  57. if err != nil {
  58. if err == gorm.ErrRecordNotFound {
  59. return
  60. }
  61. return
  62. }
  63. if activityDetail.ActivityID == 0 {
  64. err = errors.New("活动不存在")
  65. return
  66. }
  67. ybViewLog.PrimaryId = req.PrimaryId
  68. ybViewLog.ExtendId = activityDetail.ActivityID
  69. ybViewLog.UserId = userinfo.UserID
  70. ybViewLog.Source = req.Source
  71. ybViewLog.FromPage = req.FromPage
  72. ybViewLog.ViewType = 2
  73. if activityDetail.IsNewReport == 1 {
  74. ybViewLog.ReportId = activityDetail.ReportId
  75. }else{
  76. ybViewLog.OldReportId = activityDetail.ReportId
  77. }
  78. ybViewLog.CreateTime = time.Now()
  79. ybViewLog.ModifyTime = time.Now()
  80. ybViewLog.CompanyId = userinfo.CompanyID
  81. id, err := AddViewLog(ybViewLog)
  82. if err != nil {
  83. return
  84. }
  85. resp.Id = id
  86. return
  87. }