This commit is contained in:
2025-07-07 20:11:59 +08:00
parent ab0fdbc447
commit 06e3aa2eb3
2009 changed files with 193082 additions and 0 deletions

View File

@ -0,0 +1,57 @@
package model
import (
"context"
"github.com/gogf/gf/v2/frame/g"
"github.com/samber/lo"
"github.com/tiger1103/gfast/v3/internal/app/system/dao"
)
func (n *Notifications) ReadNum() int {
// 从 redis 中获取已读人数
count, err := g.Redis().Get(context.Background(), "notification:"+n.Id)
if err != nil {
return 0
}
return count.Int()
}
// 已读人数
func (n *Notifications) ReadPeople() int {
// 如果 n.users 为空则从数据库中查询
if len(n.Users) == 0 {
list := []NotificationsGetRes{}
if err := dao.NotificationRecipients.Ctx(context.Background()).As("nr").
LeftJoin("sys_user as su", "nr.recipient_id = su.id").
Fields("nr.*,su.user_nickname").
Where("nr.notification_id", n.Id).Scan(&list); err != nil {
return 0
}
n.Users = list
}
return lo.CountBy(n.Users, func(item NotificationsGetRes) bool {
return item.NotificationStatus == 1
})
}
// 未读人数
func (n *Notifications) UnreadPeople() int {
// 如果 n.users 为空则从数据库中查询
if len(n.Users) == 0 {
list := []NotificationsGetRes{}
if err := dao.NotificationRecipients.Ctx(context.Background()).As("nr").
LeftJoin("sys_user as su", "nr.recipient_id = su.id").
Fields("nr.*,su.user_nickname").
Where("nr.notification_id", n.Id).Scan(&list); err != nil {
return 0
}
n.Users = list
}
return lo.CountBy(n.Users, func(item NotificationsGetRes) bool {
return item.NotificationStatus == 0
})
}