Initial commit

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-15 13:57:10 +08:00
co-authored by Claude Opus 5
commit 8679200f41
1897 changed files with 257900 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
package immod
import "time"
// AppRes app端消息响应
type MsgAppRes struct {
MsgID uint64 `json:"msgID" bson:"msgID"` //通知ID
Title string `json:"title" bson:"title"` //标题
Content string `json:"content" bson:"content"` //内容
Operate Action `json:"operate" bson:"operate"` //操作类型
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"`
CreatedAt time.Time `json:"createdAt" bson:"createdAt"`
}
+152
View File
@@ -0,0 +1,152 @@
package immod
import (
"fmt"
"time"
"91porn-server/common/db"
"91porn-server/common/log"
"91porn-server/models"
"91porn-server/models/commod"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
var mdb *db.MongoDB
const table = models.Msg
func coll(t *db.MongoTool) *db.MongoTool {
if t == nil {
return mdb.Coll(table)
}
return t.Coll(table)
}
// ActInitIndex 索引设置
func initIndex() {
coll := coll(nil)
many := []mongo.IndexModel{ //batch set indexes //value is the type 1 or -1
{
Keys: bson.D{{Key: "msgID", Value: -1}},
Options: options.Index().SetUnique(true),
},
{
Keys: bson.D{{Key: "toUserId", Value: 1}},
},
{
Keys: bson.D{{Key: "content", Value: 1}},
},
{
Keys: bson.D{{Key: "operate", Value: 1}},
},
{
Keys: bson.D{{Key: "createdAt", Value: 1}},
},
{
Keys: bson.D{{Key: "updatedAt", Value: 1}},
},
}
if _, err := coll.CreateIndex(many); err != nil {
panic(fmt.Sprintf("%s model set index err ==>[%+v]", table, err))
}
}
// 保存消息
func InsertOne(msg Msg) (err error) {
if _, err = coll(nil).InsertOne(msg); err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "InsertOne", table, "InsertOne", err))
return
}
return
}
// MsgList 消息列表
func MsgList(uid uint64, stdQuery commod.StdQuery) (msg []MsgAppRes, err error) {
query := bson.M{"$or": bson.A{bson.M{"operate": bson.M{"$in": []Action{System}}}, bson.M{"toUserId": uid}}}
opts := commod.ConvertToListQuery(stdQuery).SetSort(bson.D{{Key: "updatedAt", Value: -1}})
if err = coll(nil).Find(&msg, query, opts); err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "MsgList", table, "Find", err), log.Any("uid", uid))
return
}
return
}
// 根据uid获取个人消息
func FindMsgAndCountByUID(uid uint64, stdQuery commod.StdQuery) (data []Msg, total int64, err error) {
*stdQuery.Order = append(*stdQuery.Order, commod.OrderBy{Key: "createdAt", Desc: true})
query := bson.M{"toUserId": uid, "operate": Private}
if err = coll(nil).Find(&data, query, commod.ConvertToListQuery(stdQuery)); err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "FindMsgAndCountByUID", table, "Find", err), log.Any("uid", uid))
return
}
total, err = coll(nil).Count(query)
if err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "FindMsgAndCountByUID", table, "Count", err), log.Any("uid", uid))
return
}
return
}
// 根据消息行为获取消息
func FindMsgAndCountByAction(action Action, stdQuery commod.StdQuery) (data []Msg, total int64, err error) {
*stdQuery.Order = append(*stdQuery.Order, commod.OrderBy{Key: "createdAt", Desc: true})
query := bson.M{"operate": action}
if err = coll(nil).Find(&data, query, commod.ConvertToListQuery(stdQuery)); err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "FindMsgAndCountByAction", table, "Find", err), log.Any("action", action))
return
}
total, err = coll(nil).Count(query)
if err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "FindMsgAndCountByAction", table, "Count", err), log.Any("action", action))
return
}
return
}
// MsgWebList 消息列表
func MsgWebList(uid, msgID, operater *uint64, title *string, start, end *time.Time, stdQuery commod.StdQuery) (res WebMsgRes, err error) {
query := bson.M{}
if uid != nil {
query["uid"] = uid
}
if msgID != nil {
query["msgID"] = msgID
}
if operater != nil {
query["operater"] = operater
}
if title != nil {
query["title"] = title
}
if start != nil {
query["created"] = bson.M{"$gte": start}
}
if end != nil {
query["created"] = bson.M{"$lt": end}
}
opts := commod.ConvertToListQuery(stdQuery).SetSort(bson.D{{Key: "updatedAt", Value: -1}})
total, err := coll(nil).Count(query)
if err != nil {
log.Warn(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "MsgWebList", table, "Count", err))
return
}
m := []Msg{}
if err = coll(nil).Find(&m, query, opts); err != nil {
log.Warn(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "MsgWebList", table, "find", err))
return
}
res.List = m
res.Total = total
return
}
func DeleteOneByMsgID(msgID uint64) (err error) {
if _, err = coll(nil).DeleteOne(bson.M{"msgID": msgID}); err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "DeleteOneByMsgID", table, "DeleteOne", err), log.Any("msgID", msgID))
return
}
return
}
+94
View File
@@ -0,0 +1,94 @@
package immod
import (
"time"
"91porn-server/common/db"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// MsgType 消息类型
type MsgType int
const (
Single MsgType = (1001 + iota) //单条消息
Batch //批量消息
Group //群聊消息
)
// Action 消息行为
type Action string
const (
BannedUser Action = "BANNED_USER" //封禁用户
Placard Action = "PLACARD" //公告
System Action = "SYSTEM" //系统消息
Private Action = "PRIVATE" //个人消息
)
// Message 消息结构体
type Message struct {
FromUID int64 `json:"fromUID"` //发送用户ID
GroupID int64 `json:"chatID"` //群聊ID
MsgType MsgType `json:"msgType"` //消息类型
Data string `json:"data"` //消息体
}
// SingleMsg 单条消息结构体
type SingleMsg struct {
ToUserID int64 `json:"toUserId" binding:"required"` //接收用户ID
Content string `json:"content" binding:"required"` //内容
Operate Action `json:"operate" binding:"required"` //操作类型
}
// BatchMsg 批量消息结构体
type BatchMsg struct {
ToUserIDs []int64 `json:"toUserId"` //接收用户ID数组
Content string `json:"content" binding:"required"` //内容
Operate Action `json:"operate" binding:"required"` //操作类型
}
// GroupMsg 群聊消息
type GroupMsg struct {
GroupIDs []int64 `json:"toGroupIds" binding:"required"` //接收用户ID数组
Content string `json:"content" binding:"required"` //内容
Operate Action `json:"operate" binding:"required"` //操作类型
}
// ImSign 客服聊天签名结构体
type ImSign struct {
ID string `json:"id" binding:"required"`
AppID string `json:"appId"`
PlatName string `json:"platName"`
UserName string `json:"userName"`
IsVip bool `json:"isVip"`
Avatar string `json:"avatar"`
}
// 发送消息
type Msg struct {
ID primitive.ObjectID `bson:"_id,omitempty"`
ToUserID []uint64 `json:"toUserId" bson:"toUserId"` //接收用户ID数组
MsgID uint64 `json:"msgID" bson:"msgID"` //通知ID
TaskName string `json:"taskName" bson:"taskName"` //任务名称
Title string `json:"title" bson:"title"` //标题
Content string `json:"content" bson:"content"` //内容
Operate Action `json:"operate" bson:"operate"` //操作类型
Operator string `json:"operator" bson:"operator"` //操作人员
TaskExecute time.Time `json:"taskExecute" bson:"taskExecute"` //任务开始执行的时间
DurationAct string `json:"durationAct" bson:"durationAct"` //单位 天/周
Interval uint64 `json:"interval"` //时间间隔
Count uint64 `json:"count" bson:"count"` //执行几次
NextTaskExecute time.Time `json:"nextTaskExecute" bson:"nextTaskExecute"` //下次执行任务的时间
SpecifyTaskExecutes []time.Time `json:"specifyTaskExecutes" bson:"specifyTaskExecutes"` //指定执行的时间数组
Status uint64 `json:"status" bson:"status"` //消息状态
Remark string `json:"remark" bson:"remark"` //备注
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"`
CreatedAt time.Time `json:"createdAt" bson:"createdAt"`
}
func Init() {
mdb = db.Init(table)
initIndex()
}
+7
View File
@@ -0,0 +1,7 @@
package immod
// WebMsgRes web响应
type WebMsgRes struct {
Total int64 `json:"total" bson:"total"`
List []Msg `json:"list" bson:"list"`
}