初始
This commit is contained in:
57
internal/app/system/model/notifications_func.go
Normal file
57
internal/app/system/model/notifications_func.go
Normal 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
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user