article_history_record.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package models
  2. import (
  3. "hongze/hongze_cygx/utils"
  4. "rdluck_tools/orm"
  5. "time"
  6. )
  7. type CygxArticleHistoryRecord struct {
  8. Id int `orm:"column(id);pk"`
  9. ArticleId int
  10. UserId int
  11. CreateTime time.Time
  12. Mobile string `description:"手机号"`
  13. Email string `description:"邮箱"`
  14. CompanyId int `description:"公司id"`
  15. CompanyName string `description:"公司名称"`
  16. ModifyTime time.Time `description:"修改时间"`
  17. }
  18. //添加历史信息
  19. func AddCygxArticleHistoryRecord(item *CygxArticleHistoryRecord) (lastId int64, err error) {
  20. o := orm.NewOrm()
  21. o.Begin()
  22. defer func() {
  23. if err == nil {
  24. o.Commit()
  25. } else {
  26. o.Rollback()
  27. }
  28. }()
  29. var count int
  30. sql := `SELECT COUNT(1) AS count FROM cygx_article_history_record WHERE user_id=? AND article_id=? `
  31. err = o.Raw(sql, item.UserId, item.ArticleId).QueryRow(&count)
  32. if err != nil && err.Error() != utils.ErrNoRow() {
  33. return
  34. }
  35. if count > 0 {
  36. sql := `UPDATE cygx_article_history_record SET modify_time=NOW() WHERE user_id=? AND article_id=? `
  37. _, err = o.Raw(sql, item.UserId, item.ArticleId).Exec()
  38. } else {
  39. item.ModifyTime = time.Now()
  40. lastId, err = o.Insert(item)
  41. }
  42. return
  43. }