| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- package model
- import (
- "context"
- "time"
- "gorm.io/gorm"
- )
- // PMessage 消息通知
- type Message struct {
- ID int64 `json:"id" gorm:"id"` // 消息通知ID
- SenderUserId int64 `json:"sender_user_id" gorm:"sender_user_id"` // 发送方用户ID
- ReceiverUserId int64 `json:"receiver_user_id" gorm:"receiver_user_id"` // 接收方用户ID
- Type int8 `json:"type" gorm:"type"` // 通知类型,1动态,2评论,3回复,4私信,99系统通知
- Brief string `json:"brief" gorm:"brief"` // 摘要说明
- Content string `json:"content" gorm:"content"` // 详细内容
- PostId int64 `json:"post_id" gorm:"post_id"` // 动态ID
- CommentId int64 `json:"comment_id" gorm:"comment_id"` // 评论ID
- ReplyId int64 `json:"reply_id" gorm:"reply_id"` // 回复ID
- IsRead int8 `json:"is_read" gorm:"is_read"` // 是否已读
- CreatedOn int64 `json:"created_on" gorm:"created_on"` // 创建时间
- ModifiedOn int64 `json:"modified_on" gorm:"modified_on"` // 修改时间
- DeletedOn int64 `json:"deleted_on" gorm:"deleted_on"` // 删除时间
- IsDel int8 `json:"is_del" gorm:"is_del"` // 是否删除 0 为未删除、1 为已删除
- }
- // TableName 表名称
- func (*Message) TableName() string {
- return "p_message"
- }
- // MessageModel 消息模型
- type MessageModel struct {
- conn *gorm.DB
- }
- func NewMessageModel(conn *gorm.DB) *MessageModel {
- return &MessageModel{
- conn: conn,
- }
- }
- // SendMessage 发送站内信
- func (m *MessageModel) SendMessage(ctx context.Context, senderId, receiverId int64, postId int64, content string) error {
- message := &Message{
- SenderUserId: senderId,
- ReceiverUserId: receiverId,
- Type: 1, // 假设1表示动态通知
- Brief: "你被艾特了",
- Content: content,
- PostId: postId,
- IsRead: 0,
- CreatedOn: time.Now().Unix(),
- ModifiedOn: time.Now().Unix(),
- IsDel: 0,
- }
- return m.conn.WithContext(ctx).Create(message).Error
- }
- // SendNotification 发送站内信
- func (m *MessageModel) SendNotification(ctx context.Context, senderId, receiverId int64, messageType int8, brief, content string, postId, commentId, replyId int64) error {
- message := &Message{
- SenderUserId: senderId,
- ReceiverUserId: receiverId,
- Type: messageType,
- Brief: brief,
- Content: content,
- PostId: postId,
- CommentId: commentId,
- ReplyId: replyId,
- IsRead: 0,
- CreatedOn: time.Now().Unix(),
- ModifiedOn: time.Now().Unix(),
- IsDel: 0,
- }
- return m.conn.WithContext(ctx).Create(message).Error
- }
|