timeline_log.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_clpt/models"
  6. "hongze/hongze_clpt/utils"
  7. "time"
  8. )
  9. // 记录产业时间线的点击记录
  10. func AddCygxTimelineLog(user *models.WxUserItem, industrialManagementId int) (err error) {
  11. if user.UserId == 0 {
  12. return
  13. }
  14. defer func() {
  15. if err != nil {
  16. go utils.SendAlarmMsg(fmt.Sprint("记录产业时间线的点击记录 失败 AddCygxTimelineLog Err:"+err.Error(), "userId:", user.UserId, "industrialManagementId:", industrialManagementId), 2)
  17. }
  18. }()
  19. //获取销售信息
  20. sellerItem, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  21. if e != nil && e.Error() != utils.ErrNoRow() {
  22. err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
  23. return
  24. }
  25. if sellerItem == nil {
  26. return
  27. }
  28. //判断一个用户是否阅读过 某一篇研选专栏
  29. totalRecord, e := models.GetCygxTimelineLogCountByUser(user.UserId, industrialManagementId)
  30. if e != nil {
  31. err = errors.New("GetCygxTimelineLogCountByUser, Err: " + e.Error())
  32. return
  33. }
  34. if totalRecord == 0 {
  35. item := new(models.CygxTimelineLog)
  36. item.UserId = user.UserId
  37. item.Mobile = user.Mobile
  38. item.Email = user.Email
  39. item.CompanyId = user.CompanyId
  40. item.CompanyName = user.CompanyName
  41. item.RealName = user.RealName
  42. item.CreateTime = time.Now()
  43. item.ModifyTime = time.Now()
  44. item.IndustrialManagementId = industrialManagementId
  45. _, e = models.AddCygxTimelineLog(item) // 添加历史记录
  46. } else {
  47. //更新时间线下对应产业的阅读时间
  48. e = models.UpdateCygxTimelineLogModifyTime(user.UserId, industrialManagementId)
  49. if e != nil {
  50. err = errors.New("UpdateCygxTimelineLogModifyTime, Err: " + e.Error())
  51. return
  52. }
  53. }
  54. return
  55. }