update.go 629 B

12345678910111213141516171819202122232425
  1. package yb_message
  2. import (
  3. "hongze/hongze_yb/global"
  4. )
  5. // Update 更新对应字段数据
  6. func (ym *YbMessage) Update(updateCols []string) (err error) {
  7. err = global.DEFAULT_MYSQL.Model(ym).Select(updateCols).Updates(*ym).Error
  8. return
  9. }
  10. // SetBatchRead 批量设置已读
  11. func SetBatchRead(userId uint64, msgType int)(err error) {
  12. var pars []interface{}
  13. pars = append(pars, userId)
  14. sql := ` UPDATE yb_message set is_read = 1, modify_time=NOW()
  15. WHERE user_id = ? and is_read = 0 `
  16. if msgType > 0 {
  17. sql += " and type= ?"
  18. pars = append(pars, msgType)
  19. }
  20. err = global.DEFAULT_MYSQL.Exec(sql, pars...).Error
  21. return
  22. }