1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package dao
- import (
- "server/dao/system"
- "server/global"
- )
- type Notice struct {
- global.GVA_MODEL
- Title string `json:"title" form:"title" gorm:"comment:标题"`
- Content string `json:"content" form:"content" gorm:"comment:内容"`
- Type string `json:"type" form:"type" gorm:"comment:类型"`
- UserId int `json:"userId" form:"userId" gorm:"comment:接收者ID"`
- User system.SysUser `json:"user" form:"user" gorm:"foreignKey:UserId;references:id;"`
- IsRead bool `json:"isRead" form:"isRead" gorm:"default:false;comment:是否已读"`
- }
- func (Notice) TableName() string {
- return "notice"
- }
- // QueryUserUnreadNotice 查询用户未读通知
- func QueryUserUnreadNotice(userId int) (notices []Notice, err error) {
- err = global.GVA_DB.Where("user_id = ? AND is_read = ?", userId, false).Find(¬ices).Error
- return
- }
- func QueryUserAllNotice(userId int) (notices []Notice, err error) {
- err = global.GVA_DB.Where("user_id =?", userId).Order("id").Find(¬ices).Error
- return
- }
- // QueryAllNotices 查询所有通知
- func QueryAllNotices() (notices []Notice, err error) {
- err = global.GVA_DB.Find(¬ices).Error
- return
- }
- func (n Notice) CreateNotice() error {
- return global.GVA_DB.Create(&n).Error
- }
- func ReadNotice(id int) error {
- return global.GVA_DB.Model(&Notice{}).Where("id =?", id).Update("is_read", true).Error
- }
- func (n Notice) UpdateNotice() error {
- return global.GVA_DB.Model(&n).Updates(&n).Error
- }
- func (n Notice) DeleteNotice() error {
- return global.GVA_DB.Unscoped().Delete(&n).Error
- }
|