12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package models
- import (
- "hongze/hongze_cygx/utils"
- "rdluck_tools/orm"
- "time"
- )
- type CygxReportHistoryRecord struct {
- Id int `orm:"column(id);pk"`
- ArticleId int
- UserId int
- CreateTime time.Time
- Mobile string `description:"手机号"`
- Email string `description:"邮箱"`
- CompanyId int `description:"公司id"`
- CompanyName string `description:"公司名称"`
- ModifyTime time.Time `description:"修改时间"`
- }
- //添加历史信息
- func AddCygxReportHistoryRecord(item *CygxReportHistoryRecord) (lastId int64, err error) {
- o := orm.NewOrm()
- o.Begin()
- defer func() {
- if err == nil {
- o.Commit()
- } else {
- o.Rollback()
- }
- }()
- var count int
- sql := `SELECT COUNT(1) AS count FROM cygx_article_history_record WHERE user_id=? AND article_id=? `
- err = o.Raw(sql, item.UserId, item.ArticleId).QueryRow(&count)
- if err != nil && err.Error() != utils.ErrNoRow() {
- return
- }
- if count > 0 {
- sql := `UPDATE cygx_article_history_record SET modify_time=NOW() WHERE user_id=? AND article_id=? `
- _, err = o.Raw(sql, item.UserId, item.ArticleId).Exec()
- } else {
- item.ModifyTime = time.Now()
- lastId, err = o.Insert(item)
- }
- return
- }
|