复制项目

This commit is contained in:
kim.dev.6789
2026-01-14 22:35:45 +08:00
parent 305d526110
commit b7f8db7d08
297 changed files with 81784 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
// Copyright © 2023 OpenIM open source community. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package chat
import (
"context"
"time"
)
type Account struct {
UserID string `bson:"user_id"`
Password string `bson:"password"`
CreateTime time.Time `bson:"create_time"`
ChangeTime time.Time `bson:"change_time"`
OperatorUserID string `bson:"operator_user_id"`
}
func (Account) TableName() string {
return "accounts"
}
type AccountInterface interface {
Create(ctx context.Context, accounts ...*Account) error
Take(ctx context.Context, userId string) (*Account, error)
Update(ctx context.Context, userID string, data map[string]any) error
UpdatePassword(ctx context.Context, userId string, password string) error
Delete(ctx context.Context, userIDs []string) error
}

View File

@@ -0,0 +1,51 @@
package chat
import (
"context"
"time"
"github.com/openimsdk/tools/db/pagination"
)
type Attribute struct {
UserID string `bson:"user_id"`
Account string `bson:"account"`
PhoneNumber string `bson:"phone_number"`
AreaCode string `bson:"area_code"`
Email string `bson:"email"`
Nickname string `bson:"nickname"`
FaceURL string `bson:"face_url"`
Gender int32 `bson:"gender"`
CreateTime time.Time `bson:"create_time"`
ChangeTime time.Time `bson:"change_time"`
BirthTime time.Time `bson:"birth_time"`
Level int32 `bson:"level"`
UserType int32 `bson:"user_type"` // 用户类型: 0=普通用户, 1=企业用户, 2=机器人, 3=管理员
UserFlag string `bson:"user_flag"` // 用户标签/标识类似UserType的字符串版本
AllowVibration int32 `bson:"allow_vibration"`
AllowBeep int32 `bson:"allow_beep"`
AllowAddFriend int32 `bson:"allow_add_friend"`
GlobalRecvMsgOpt int32 `bson:"global_recv_msg_opt"`
RegisterType int32 `bson:"register_type"`
}
func (Attribute) TableName() string {
return "attributes"
}
type AttributeInterface interface {
// NewTx(tx any) AttributeInterface
Create(ctx context.Context, attribute ...*Attribute) error
Update(ctx context.Context, userID string, data map[string]any) error
Find(ctx context.Context, userIds []string) ([]*Attribute, error)
FindAccount(ctx context.Context, accounts []string) ([]*Attribute, error)
Search(ctx context.Context, keyword string, genders []int32, pagination pagination.Pagination) (int64, []*Attribute, error)
TakePhone(ctx context.Context, areaCode string, phoneNumber string) (*Attribute, error)
TakeEmail(ctx context.Context, email string) (*Attribute, error)
TakeAccount(ctx context.Context, account string) (*Attribute, error)
Take(ctx context.Context, userID string) (*Attribute, error)
SearchNormalUser(ctx context.Context, keyword string, forbiddenID []string, gender int32, startTime, endTime *time.Time, pagination pagination.Pagination) (int64, []*Attribute, error)
SearchNormalUserWithUserIDs(ctx context.Context, keyword string, forbiddenID []string, gender int32, startTime, endTime *time.Time, userIDs []string, pagination pagination.Pagination) (int64, []*Attribute, error) // 按条件搜索用户支持额外的userIDs过滤
SearchUser(ctx context.Context, keyword string, userIDs []string, genders []int32, pagination pagination.Pagination) (int64, []*Attribute, error)
Delete(ctx context.Context, userIDs []string) error
}

View File

@@ -0,0 +1,32 @@
package chat
import (
"context"
"github.com/openimsdk/tools/db/pagination"
)
type Credential struct {
UserID string `bson:"user_id"`
Account string `bson:"account"`
Type int `bson:"type"` // 1:phone;2:email
AllowChange bool `bson:"allow_change"`
}
func (Credential) TableName() string {
return "credentials"
}
type CredentialInterface interface {
Create(ctx context.Context, credential ...*Credential) error
CreateOrUpdateAccount(ctx context.Context, credential *Credential) error
Update(ctx context.Context, userID string, data map[string]any) error
Find(ctx context.Context, userID string) ([]*Credential, error)
FindAccount(ctx context.Context, accounts []string) ([]*Credential, error)
Search(ctx context.Context, keyword string, pagination pagination.Pagination) (int64, []*Credential, error)
TakeAccount(ctx context.Context, account string) (*Credential, error)
Take(ctx context.Context, userID string) (*Credential, error)
SearchNormalUser(ctx context.Context, keyword string, forbiddenID []string, pagination pagination.Pagination) (int64, []*Credential, error)
SearchUser(ctx context.Context, keyword string, userIDs []string, pagination pagination.Pagination) (int64, []*Credential, error)
Delete(ctx context.Context, userIDs []string) error
DeleteByUserIDType(ctx context.Context, credentials ...*Credential) error
}

View File

@@ -0,0 +1,69 @@
// Copyright © 2023 OpenIM open source community. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package chat
import (
"context"
"time"
"github.com/openimsdk/tools/db/pagination"
)
// FavoriteType 收藏类型
const (
FavoriteTypeText = 1 // 文本
FavoriteTypeImage = 2 // 图片
FavoriteTypeLink = 3 // 链接
FavoriteTypeFile = 4 // 文件
FavoriteTypeVoice = 5 // 语音
FavoriteTypeVideo = 6 // 视频
FavoriteTypeLocation = 7 // 位置
)
type Favorite struct {
ID string `bson:"_id"` // 收藏IDMongoDB ObjectID
UserID string `bson:"user_id"` // 用户ID收藏者
Type int32 `bson:"type"` // 收藏类型1-文本2-图片3-链接4-文件5-语音6-视频7-位置
Title string `bson:"title"` // 标题(可选)
Content string `bson:"content"` // 内容根据类型不同可能是文本、图片URL、链接URL、文件路径等
Description string `bson:"description"` // 摘要/描述(可选)
Thumbnail string `bson:"thumbnail"` // 缩略图URL用于图片、视频、链接等
LinkURL string `bson:"link_url"` // 链接URL用于链接类型
FileSize int64 `bson:"file_size"` // 文件大小(字节,用于文件、语音、视频等)
Duration int32 `bson:"duration"` // 时长(秒,用于语音、视频等)
Location string `bson:"location"` // 位置信息JSON格式用于位置类型
Tags []string `bson:"tags"` // 标签列表
Remark string `bson:"remark"` // 备注(可选)
Status int32 `bson:"status"` // 状态0-已删除1-正常
CreateTime time.Time `bson:"create_time"` // 创建时间
UpdateTime time.Time `bson:"update_time"` // 更新时间
}
func (Favorite) TableName() string {
return "favorites"
}
type FavoriteInterface interface {
Create(ctx context.Context, favorites ...*Favorite) error
Take(ctx context.Context, favoriteID string) (*Favorite, error)
FindByUserID(ctx context.Context, userID string, pagination pagination.Pagination) (int64, []*Favorite, error)
FindByUserIDAndType(ctx context.Context, userID string, favoriteType int32, pagination pagination.Pagination) (int64, []*Favorite, error)
SearchByKeyword(ctx context.Context, userID string, keyword string, pagination pagination.Pagination) (int64, []*Favorite, error)
Update(ctx context.Context, favoriteID string, data map[string]any) error
Delete(ctx context.Context, favoriteIDs []string) error
DeleteByUserID(ctx context.Context, userID string) error
CountByUserID(ctx context.Context, userID string) (int64, error)
FindByTags(ctx context.Context, userID string, tags []string, pagination pagination.Pagination) (int64, []*Favorite, error)
}

View File

@@ -0,0 +1,67 @@
package chat
import (
"context"
"time"
)
// LiveKit 表示一台LiveKit服务器配置
type LiveKit struct {
ID string `bson:"_id" json:"id"` // 服务器唯一标识
Name string `bson:"name" json:"name"` // 服务器名称
URL string `bson:"url" json:"url"` // LiveKit服务器地址
Key string `bson:"key" json:"key"` // API Key
Secret string `bson:"secret" json:"secret"` // API Secret
Region string `bson:"region" json:"region"` // 服务器区域
Status int `bson:"status" json:"status"` // 状态0-禁用1-启用
Priority int `bson:"priority" json:"priority"` // 优先级,数字越小优先级越高
MaxRooms int `bson:"max_rooms" json:"max_rooms"` // 最大房间数
MaxUsers int `bson:"max_users" json:"max_users"` // 最大用户数
Description string `bson:"description" json:"description"` // 描述信息
CreateTime time.Time `bson:"create_time" json:"create_time"` // 创建时间
UpdateTime time.Time `bson:"update_time" json:"update_time"` // 更新时间
}
// TableName 返回表名
func (LiveKit) TableName() string {
return "livekits"
}
// LiveKitInterface 定义LiveKit数据库操作接口
type LiveKitInterface interface {
// Create 创建LiveKit服务器配置
Create(ctx context.Context, livekits ...*LiveKit) error
// Delete 删除LiveKit服务器配置
Delete(ctx context.Context, ids []string) error
// Update 更新LiveKit服务器配置
Update(ctx context.Context, livekit *LiveKit) error
// FindByID 根据ID查找LiveKit配置
FindByID(ctx context.Context, id string) (*LiveKit, error)
// FindByStatus 根据状态查找LiveKit配置列表
FindByStatus(ctx context.Context, status int) ([]*LiveKit, error)
// FindAll 查找所有LiveKit配置
FindAll(ctx context.Context) ([]*LiveKit, error)
// FindAvailable 查找可用的LiveKit服务器按优先级排序
FindAvailable(ctx context.Context) ([]*LiveKit, error)
// FindByRegion 根据区域查找LiveKit配置
FindByRegion(ctx context.Context, region string) ([]*LiveKit, error)
// UpdateStatus 更新服务器状态
UpdateStatus(ctx context.Context, id string, status int) error
// UpdatePriority 更新服务器优先级
UpdatePriority(ctx context.Context, id string, priority int) error
// GetNextAvailable 获取下一个可用的LiveKit服务器负载均衡
GetNextAvailable(ctx context.Context) (*LiveKit, error)
}
// 状态常量
const (
LiveKitStatusDisabled = 0 // 禁用
LiveKitStatusEnabled = 1 // 启用
)
// 默认值
const (
DefaultMaxRooms = 1000 // 默认最大房间数
DefaultMaxUsers = 100 // 默认最大用户数
DefaultPriority = 100 // 默认优先级
)

View File

@@ -0,0 +1,42 @@
// Copyright © 2023 OpenIM open source community. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package chat
import (
"context"
"time"
)
type Register struct {
UserID string `bson:"user_id"`
DeviceID string `bson:"device_id"`
IP string `bson:"ip"`
Platform string `bson:"platform"`
AccountType string `bson:"account_type"`
Mode string `bson:"mode"`
CreateTime time.Time `bson:"create_time"`
}
func (Register) TableName() string {
return "registers"
}
type RegisterInterface interface {
// NewTx(tx any) RegisterInterface
Create(ctx context.Context, registers ...*Register) error
CountTotal(ctx context.Context, before *time.Time) (int64, error)
CountToday(ctx context.Context) (int64, error) // 统计今天注册的用户数
Delete(ctx context.Context, userIDs []string) error
}

View File

@@ -0,0 +1,78 @@
// Copyright © 2023 OpenIM open source community. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package chat
import (
"context"
"time"
"github.com/openimsdk/tools/db/pagination"
)
// ScheduledTaskStatus 定时任务状态
const (
ScheduledTaskStatusDisabled = 0 // 已禁用
ScheduledTaskStatusEnabled = 1 // 已启用
)
// MessageType 消息类型
const (
MessageTypeText = 1 // 文本消息
MessageTypeImage = 2 // 图片消息
MessageTypeVideo = 3 // 视频消息
)
// ScheduledTask 定时任务配置
// CronExpression格式分 时 日 月 周
// 例如:"0 9 * * *" 表示每天9点执行
//
// "*/5 * * * *" 表示每5分钟执行
// "0 0 * * 1" 表示每周一0点执行
type ScheduledTask struct {
ID string `bson:"_id"` // 任务ID
UserID string `bson:"user_id"` // 用户ID
Name string `bson:"name"` // 任务名称
CronExpression string `bson:"cron_expression"` // Crontab表达式分 时 日 月 周(例如:"0 9 * * *"
Messages []Message `bson:"messages"` // 消息列表(支持多条消息一起发送)
RecvIDs []string `bson:"recv_ids"` // 接收者ID列表单聊可以多个
GroupIDs []string `bson:"group_ids"` // 群组ID列表群聊可以多个
Status int32 `bson:"status"` // 状态0-已禁用1-已启用
CreateTime time.Time `bson:"create_time"` // 创建时间
UpdateTime time.Time `bson:"update_time"` // 更新时间
}
// Message 消息内容
type Message struct {
Type int32 `bson:"type"` // 消息类型1-文本2-图片3-视频
Content string `bson:"content"` // 消息内容文本内容、图片URL、视频URL等
Thumbnail string `bson:"thumbnail"` // 缩略图URL用于图片和视频
Duration int32 `bson:"duration"` // 时长(秒,用于视频)
FileSize int64 `bson:"file_size"` // 文件大小(字节,用于图片和视频)
Width int32 `bson:"width"` // 宽度(像素,用于图片和视频)
Height int32 `bson:"height"` // 高度(像素,用于图片和视频)
}
func (ScheduledTask) TableName() string {
return "scheduled_tasks"
}
type ScheduledTaskInterface interface {
Create(ctx context.Context, tasks ...*ScheduledTask) error
Take(ctx context.Context, taskID string) (*ScheduledTask, error)
FindByUserID(ctx context.Context, userID string, pagination pagination.Pagination) (int64, []*ScheduledTask, error)
FindAll(ctx context.Context, pagination pagination.Pagination) (int64, []*ScheduledTask, error)
Update(ctx context.Context, taskID string, data map[string]any) error
Delete(ctx context.Context, taskIDs []string) error
}

View File

@@ -0,0 +1,144 @@
package chat
import (
"context"
"time"
"github.com/openimsdk/tools/db/pagination"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// 敏感词相关结构体定义
type SensitiveWord struct {
ID string `bson:"_id" json:"id"` // 主键ID
Word string `bson:"word" json:"word"` // 敏感词内容
Level int32 `bson:"level" json:"level"` // 敏感词级别 1:低 2:中 3:高
Type int32 `bson:"type" json:"type"` // 敏感词类型 1:政治 2:色情 3:暴力 4:广告 5:其他
Action int32 `bson:"action" json:"action"` // 处理动作 1:替换为*** 2:拦截不发
Status int32 `bson:"status" json:"status"` // 状态 1:启用 0:禁用
Creator string `bson:"creator" json:"creator"` // 创建者
Updater string `bson:"updater" json:"updater"` // 更新者
CreateTime time.Time `bson:"create_time" json:"create_time"` // 创建时间
UpdateTime time.Time `bson:"update_time" json:"update_time"` // 更新时间
Remark string `bson:"remark" json:"remark"` // 备注
}
func (SensitiveWord) TableName() string {
return "sensitive_words"
}
type SensitiveWordLog struct {
ID primitive.ObjectID `bson:"_id,omitempty"`
UserID string `bson:"user_id"` // 触发用户ID
GroupID string `bson:"group_id"` // 触发群组ID (如果是在群聊中)
Content string `bson:"content"` // 原始消息内容
MatchedWords []string `bson:"matched_words"` // 匹配到的敏感词
Action int32 `bson:"action"` // 采取的动作
ProcessedText string `bson:"processed_text"` // 处理后的文本 (如果被替换)
CreateTime time.Time `bson:"create_time"`
}
func (SensitiveWordLog) TableName() string {
return "sensitive_word_logs"
}
type SensitiveWordGroup struct {
ID primitive.ObjectID `bson:"_id,omitempty"`
Name string `bson:"name"` // 分组名称
Remark string `bson:"remark"` // 备注
CreateTime time.Time `bson:"create_time"`
UpdateTime time.Time `bson:"update_time"`
}
func (SensitiveWordGroup) TableName() string {
return "sensitive_word_groups"
}
type SensitiveWordConfig struct {
ID string `bson:"_id" json:"id"` // 主键ID
EnableFilter bool `bson:"enable_filter" json:"enable_filter"` // 是否启用过滤
FilterMode int32 `bson:"filter_mode" json:"filter_mode"` // 过滤模式
ReplaceChar string `bson:"replace_char" json:"replace_char"` // 替换字符,默认***
WhitelistUsers []string `bson:"whitelist_users" json:"whitelist_users"` // 白名单用户
WhitelistGroups []string `bson:"whitelist_groups" json:"whitelist_groups"` // 白名单群组
LogEnabled bool `bson:"log_enabled" json:"log_enabled"` // 是否记录日志
AutoApprove bool `bson:"auto_approve" json:"auto_approve"` // 是否自动审核
UpdateTime time.Time `bson:"update_time" json:"update_time"` // 更新时间
}
func (SensitiveWordConfig) TableName() string {
return "sensitive_word_configs"
}
// 敏感词级别常量
const (
SensitiveLevelLow = 1 // 低级别
SensitiveLevelMedium = 2 // 中级别
SensitiveLevelHigh = 3 // 高级别
)
// 敏感词类型常量
const (
SensitiveTypePolitical = 1 // 政治
SensitiveTypePorn = 2 // 色情
SensitiveTypeViolence = 3 // 暴力
SensitiveTypeAd = 4 // 广告
SensitiveTypeOther = 5 // 其他
)
// 处理动作常量
const (
SensitiveActionReplace = 1 // 替换为***
SensitiveActionBlock = 2 // 拦截不发
)
// 状态常量
const (
SensitiveStatusDisabled = 0 // 禁用
SensitiveStatusEnabled = 1 // 启用
)
type SensitiveWordInterface interface {
// 敏感词管理
CreateSensitiveWord(ctx context.Context, word *SensitiveWord) error
UpdateSensitiveWord(ctx context.Context, id string, data map[string]any) error
DeleteSensitiveWord(ctx context.Context, ids []string) error
GetSensitiveWord(ctx context.Context, id string) (*SensitiveWord, error)
SearchSensitiveWords(ctx context.Context, keyword string, action int32, status int32, pagination pagination.Pagination) (int64, []*SensitiveWord, error)
GetAllSensitiveWords(ctx context.Context) ([]*SensitiveWord, error)
GetEnabledSensitiveWords(ctx context.Context) ([]*SensitiveWord, error)
// 敏感词检测
CheckSensitiveWords(ctx context.Context, content string) ([]*SensitiveWord, error)
FilterContent(ctx context.Context, content string) (string, []*SensitiveWord, error)
// 敏感词日志
CreateSensitiveWordLog(ctx context.Context, log *SensitiveWordLog) error
GetSensitiveWordLogs(ctx context.Context, userID string, groupID string, pagination pagination.Pagination) (int64, []*SensitiveWordLog, error)
DeleteSensitiveWordLogs(ctx context.Context, ids []string) error
// 敏感词分组管理
CreateSensitiveWordGroup(ctx context.Context, group *SensitiveWordGroup) error
UpdateSensitiveWordGroup(ctx context.Context, id string, data map[string]any) error
DeleteSensitiveWordGroup(ctx context.Context, ids []string) error
GetSensitiveWordGroup(ctx context.Context, id string) (*SensitiveWordGroup, error)
GetAllSensitiveWordGroups(ctx context.Context) ([]*SensitiveWordGroup, error)
// 敏感词配置管理
GetSensitiveWordConfig(ctx context.Context) (*SensitiveWordConfig, error)
UpdateSensitiveWordConfig(ctx context.Context, config *SensitiveWordConfig) error
IsFilterEnabled(ctx context.Context) (bool, error)
GetFilterMode(ctx context.Context) (int32, error)
GetReplaceChar(ctx context.Context) (string, error)
IsUserInWhitelist(ctx context.Context, userID string) (bool, error)
IsGroupInWhitelist(ctx context.Context, groupID string) (bool, error)
// 批量操作
BatchCreateSensitiveWords(ctx context.Context, words []*SensitiveWord) error
BatchUpdateSensitiveWords(ctx context.Context, updates map[string]map[string]any) error
BatchDeleteSensitiveWords(ctx context.Context, ids []string) error
// 统计信息
GetSensitiveWordStats(ctx context.Context) (map[string]int64, error)
GetSensitiveWordLogStats(ctx context.Context, startTime, endTime time.Time) (map[string]int64, error)
}

View File

@@ -0,0 +1,69 @@
// Copyright © 2023 OpenIM open source community. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package chat
import (
"context"
"time"
"github.com/openimsdk/tools/db/pagination"
)
// ConfigValueType 配置值类型
const (
ConfigValueTypeString = 1 // 字符串类型
ConfigValueTypeNumber = 2 // 数字类型
ConfigValueTypeBool = 3 // 布尔类型
ConfigValueTypeJSON = 4 // JSON类型
)
// ConfigKey 常用配置键
const (
// 钱包相关配置
ConfigKeyWalletEnabled = "wallet.enabled" // 是否开启钱包功能
// 注册相关配置
ConfigKeyPhoneRegisterVerifyCodeEnabled = "register.phone.verify_code.enabled" // 手机号注册验证码功能是否开启
)
// SystemConfig 系统配置模型
type SystemConfig struct {
Key string `bson:"key"` // 配置键(唯一标识)
Title string `bson:"title"` // 配置标题
Value string `bson:"value"` // 配置值字符串形式存储根据ValueType解析
ValueType int32 `bson:"value_type"` // 配置值类型1-字符串2-数字3-布尔4-JSON
Description string `bson:"description"` // 配置描述
Enabled bool `bson:"enabled"` // 是否启用(用于开关类配置)
ShowInApp bool `bson:"show_in_app"` // 是否在APP端展示
CreateTime time.Time `bson:"create_time"` // 创建时间
UpdateTime time.Time `bson:"update_time"` // 更新时间
}
func (SystemConfig) TableName() string {
return "system_configs"
}
type SystemConfigInterface interface {
Create(ctx context.Context, configs ...*SystemConfig) error
Take(ctx context.Context, key string) (*SystemConfig, error)
FindByKeys(ctx context.Context, keys []string) ([]*SystemConfig, error)
FindAll(ctx context.Context, pagination pagination.Pagination) (int64, []*SystemConfig, error)
Update(ctx context.Context, key string, data map[string]any) error
UpdateValue(ctx context.Context, key string, value string) error
UpdateEnabled(ctx context.Context, key string, enabled bool) error
Delete(ctx context.Context, keys []string) error
GetEnabledConfigs(ctx context.Context) ([]*SystemConfig, error)
GetAppConfigs(ctx context.Context) ([]*SystemConfig, error) // 获取所有 show_in_app=true 的配置
}

View File

@@ -0,0 +1,43 @@
// Copyright © 2023 OpenIM open source community. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package chat
import (
"context"
"time"
"github.com/openimsdk/tools/db/pagination"
)
type UserLoginRecord struct {
UserID string `bson:"user_id"`
LoginTime time.Time `bson:"login_time"`
IP string `bson:"ip"`
DeviceID string `bson:"device_id"`
Platform string `bson:"platform"`
}
func (UserLoginRecord) TableName() string {
return "user_login_records"
}
type UserLoginRecordInterface interface {
Create(ctx context.Context, records ...*UserLoginRecord) error
CountTotal(ctx context.Context, before *time.Time) (int64, error)
CountRangeEverydayTotal(ctx context.Context, start *time.Time, end *time.Time) (map[string]int64, int64, error)
CountTodayActiveUsers(ctx context.Context) (int64, error) // 统计今天活跃用户数(今天登录的不同用户数)
GetLatestLoginIP(ctx context.Context, userID string) (string, error) // 获取用户最新登录IP
Search(ctx context.Context, userID, ip string, pagination pagination.Pagination) (int64, []*UserLoginRecord, error) // 查询登录记录支持按用户ID或IP查询
}

View File

@@ -0,0 +1,43 @@
// Copyright © 2023 OpenIM open source community. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package chat
import (
"context"
"time"
)
type VerifyCode struct {
ID string `bson:"_id"`
Account string `bson:"account"`
Platform string `bson:"platform"`
Code string `bson:"code"`
Duration uint `bson:"duration"`
Count int `bson:"count"`
Used bool `bson:"used"`
CreateTime time.Time `bson:"create_time"`
}
func (VerifyCode) TableName() string {
return "verify_codes"
}
type VerifyCodeInterface interface {
Add(ctx context.Context, ms []*VerifyCode) error
RangeNum(ctx context.Context, account string, start time.Time, end time.Time) (int64, error)
TakeLast(ctx context.Context, account string) (*VerifyCode, error)
Incr(ctx context.Context, id string) error
Delete(ctx context.Context, id string) error
}

View File

@@ -0,0 +1,116 @@
// Copyright © 2023 OpenIM open source community. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package chat
import (
"context"
"time"
"github.com/openimsdk/tools/db/pagination"
)
// BalanceRecordType 余额变动类型
const (
BalanceRecordTypeRecharge = 1 // 充值
BalanceRecordTypeWithdraw = 2 // 提现/提款
BalanceRecordTypeConsume = 3 // 消费
BalanceRecordTypeRefund = 4 // 退款
BalanceRecordTypeReward = 5 // 奖励
BalanceRecordTypeAdminRecharge = 6 // 后台充值
BalanceRecordTypeSendRedPacket = 7 // 发红包(减少余额)
BalanceRecordTypeGrabRedPacket = 8 // 抢红包(增加余额)
BalanceRecordTypeOther = 99 // 其他
)
// WithdrawAccountType 提现账号类型
const (
WithdrawAccountTypeAlipay = 1 // 支付宝
WithdrawAccountTypeWeChat = 2 // 微信
WithdrawAccountTypeBankCard = 3 // 银行卡
)
// RealNameAuth 实名认证信息
type RealNameAuth struct {
IDCard string `bson:"id_card"` // 身份证号
IDCardPhotoFront string `bson:"id_card_photo_front"` // 身份证正面照片URL
IDCardPhotoBack string `bson:"id_card_photo_back"` // 身份证反面照片URL
Name string `bson:"name"` // 真实姓名
AuditStatus int32 `bson:"audit_status"` // 审核状态0-未审核1-审核通过2-审核拒绝
}
// Wallet 钱包模型
type Wallet struct {
UserID string `bson:"user_id"` // 用户ID
Balance int64 `bson:"balance"` // 用户余额(单位:分)
PaymentPassword string `bson:"payment_password"` // 支付密码(加密存储)
WithdrawAccount string `bson:"withdraw_account"` // 提现账号
WithdrawAccountType int32 `bson:"withdraw_account_type"` // 提现账号类型1-支付宝2-微信3-银行卡
RealNameAuth RealNameAuth `bson:"real_name_auth"` // 实名认证信息
WithdrawReceiveAccount string `bson:"withdraw_receive_account"` // 提现收款账号
CreateTime time.Time `bson:"create_time"` // 创建时间
UpdateTime time.Time `bson:"update_time"` // 更新时间
}
func (Wallet) TableName() string {
return "wallets"
}
type WalletInterface interface {
Create(ctx context.Context, wallets ...*Wallet) error
Take(ctx context.Context, userID string) (*Wallet, error)
Find(ctx context.Context, userIDs []string) ([]*Wallet, error)
Update(ctx context.Context, userID string, data map[string]any) error
UpdateBalance(ctx context.Context, userID string, balance int64) error
IncrementBalance(ctx context.Context, userID string, amount int64) (beforeBalance int64, afterBalance int64, err error) // 原子更新余额,返回更新前后的余额
UpdatePaymentPassword(ctx context.Context, userID string, paymentPassword string) error
UpdateWithdrawAccount(ctx context.Context, userID string, withdrawAccount string) error // 更新提款账号(兼容旧接口)
UpdateWithdrawAccountWithType(ctx context.Context, userID string, withdrawAccount string, accountType int32) error // 更新提款账号(带类型)
UpdateRealNameAuth(ctx context.Context, userID string, realNameAuth RealNameAuth) error // 更新实名认证信息
Delete(ctx context.Context, userIDs []string) error
Page(ctx context.Context, pagination pagination.Pagination) (int64, []*Wallet, error)
PageByRealNameAuthAuditStatus(ctx context.Context, auditStatus int32, userID string, pagination pagination.Pagination) (int64, []*Wallet, error) // 按实名认证审核状态分页查询支持用户ID搜索
SearchByRealNameAuth(ctx context.Context, realNameKeyword string, idCardKeyword string) ([]string, error) // 按实名认证信息搜索钱包返回userIDs
}
// WalletBalanceRecord 钱包余额记录
type WalletBalanceRecord struct {
ID string `bson:"_id"` // 记录ID
UserID string `bson:"user_id"` // 用户ID
Amount int64 `bson:"amount"` // 变动金额(单位:分,正数表示增加,负数表示减少)
Type int32 `bson:"type"` // 变动类型1-充值2-提现/提款3-消费4-退款5-奖励6-后台充值7-发红包8-抢红包99-其他
BeforeBalance int64 `bson:"before_balance"` // 变动前余额(单位:分)
AfterBalance int64 `bson:"after_balance"` // 变动后余额(单位:分)
OrderID string `bson:"order_id"` // 关联订单ID可选
TransactionID string `bson:"transaction_id"` // 交易ID可选
RedPacketID string `bson:"red_packet_id"` // 红包ID用于发红包和抢红包记录关联可选
Remark string `bson:"remark"` // 备注
CreateTime time.Time `bson:"create_time"` // 创建时间
}
func (WalletBalanceRecord) TableName() string {
return "wallet_balance_records"
}
type WalletBalanceRecordInterface interface {
Create(ctx context.Context, records ...*WalletBalanceRecord) error
Take(ctx context.Context, recordID string) (*WalletBalanceRecord, error)
FindByUserID(ctx context.Context, userID string, pagination pagination.Pagination) (int64, []*WalletBalanceRecord, error)
FindByUserIDAndType(ctx context.Context, userID string, recordType int32, pagination pagination.Pagination) (int64, []*WalletBalanceRecord, error)
FindByOrderID(ctx context.Context, orderID string) (*WalletBalanceRecord, error)
FindByTransactionID(ctx context.Context, transactionID string) (*WalletBalanceRecord, error)
FindByRedPacketID(ctx context.Context, redPacketID string) ([]*WalletBalanceRecord, error)
GetUserBalanceHistory(ctx context.Context, userID string, startTime, endTime *time.Time, pagination pagination.Pagination) (int64, []*WalletBalanceRecord, error)
CountByUserID(ctx context.Context, userID string) (int64, error)
}

View File

@@ -0,0 +1,63 @@
// Copyright © 2023 OpenIM open source community. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package chat
import (
"context"
"time"
"github.com/openimsdk/tools/db/pagination"
)
// WithdrawStatus 提现状态
const (
WithdrawStatusPending = 1 // 待审核
WithdrawStatusApproved = 2 // 已通过
WithdrawStatusRejected = 3 // 已拒绝
)
// Withdraw 提现记录
type Withdraw struct {
ID string `bson:"_id"` // 提现ID
UserID string `bson:"user_id"` // 用户ID
Amount int64 `bson:"amount"` // 提现金额(单位:分)
WithdrawAccount string `bson:"withdraw_account"` // 提现账号
Status int32 `bson:"status"` // 审核状态1-待审核2-已通过3-已拒绝
AuditorID string `bson:"auditor_id"` // 审核人ID管理员ID
AuditTime time.Time `bson:"audit_time"` // 审核时间
AuditRemark string `bson:"audit_remark"` // 审核备注
IP string `bson:"ip"` // 提现IP
DeviceID string `bson:"device_id"` // 设备ID
Platform string `bson:"platform"` // 平台iOS、Android、Web等
DeviceModel string `bson:"device_model"` // 设备型号iPhone 14 Pro、Samsung Galaxy S23等
DeviceBrand string `bson:"device_brand"` // 设备品牌Apple、Samsung、Huawei等
OSVersion string `bson:"os_version"` // 操作系统版本iOS 17.0、Android 13等
AppVersion string `bson:"app_version"` // 应用版本
CreateTime time.Time `bson:"create_time"` // 创建时间
UpdateTime time.Time `bson:"update_time"` // 更新时间
}
func (Withdraw) TableName() string {
return "withdraws"
}
type WithdrawInterface interface {
Create(ctx context.Context, withdraws ...*Withdraw) error
Take(ctx context.Context, withdrawID string) (*Withdraw, error)
FindByUserID(ctx context.Context, userID string, pagination pagination.Pagination) (int64, []*Withdraw, error)
FindByStatus(ctx context.Context, status int32, pagination pagination.Pagination) (int64, []*Withdraw, error)
UpdateStatus(ctx context.Context, withdrawID string, status int32, auditorID string, auditRemark string) error
Page(ctx context.Context, pagination pagination.Pagination) (int64, []*Withdraw, error)
}

View File

@@ -0,0 +1,68 @@
// Copyright © 2023 OpenIM open source community. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package chat
import (
"context"
"time"
"github.com/openimsdk/tools/db/pagination"
)
// WithdrawApplicationStatus 提现申请状态
const (
WithdrawApplicationStatusPending = 1 // 待审核
WithdrawApplicationStatusApproved = 2 // 已通过
WithdrawApplicationStatusRejected = 3 // 已拒绝
WithdrawApplicationStatusProcessing = 4 // 处理中
WithdrawApplicationStatusCompleted = 5 // 已完成
)
// WithdrawApplication 提现申请
type WithdrawApplication struct {
ID string `bson:"_id"` // 申请ID
UserID string `bson:"user_id"` // 用户ID
Amount int64 `bson:"amount"` // 提现金额(单位:分)
WithdrawAccount string `bson:"withdraw_account"` // 提现账号
WithdrawAccountType int32 `bson:"withdraw_account_type"` // 提现账号类型1-支付宝2-微信3-银行卡
Status int32 `bson:"status"` // 申请状态1-待审核2-已通过3-已拒绝4-处理中5-已完成
AuditorID string `bson:"auditor_id"` // 审核人ID管理员ID
AuditTime time.Time `bson:"audit_time"` // 审核时间
AuditRemark string `bson:"audit_remark"` // 审核备注
IP string `bson:"ip"` // 申请IP
DeviceID string `bson:"device_id"` // 设备ID
Platform string `bson:"platform"` // 平台iOS、Android、Web等
DeviceModel string `bson:"device_model"` // 设备型号iPhone 14 Pro、Samsung Galaxy S23等
DeviceBrand string `bson:"device_brand"` // 设备品牌Apple、Samsung、Huawei等
OSVersion string `bson:"os_version"` // 操作系统版本iOS 17.0、Android 13等
AppVersion string `bson:"app_version"` // 应用版本
Remark string `bson:"remark"` // 申请备注
CreateTime time.Time `bson:"create_time"` // 创建时间
UpdateTime time.Time `bson:"update_time"` // 更新时间
}
func (WithdrawApplication) TableName() string {
return "withdraw_applications"
}
type WithdrawApplicationInterface interface {
Create(ctx context.Context, applications ...*WithdrawApplication) error
Take(ctx context.Context, applicationID string) (*WithdrawApplication, error)
FindByUserID(ctx context.Context, userID string, pagination pagination.Pagination) (int64, []*WithdrawApplication, error)
FindByStatus(ctx context.Context, status int32, pagination pagination.Pagination) (int64, []*WithdrawApplication, error)
UpdateStatus(ctx context.Context, applicationID string, status int32, auditorID string, auditRemark string) error
Page(ctx context.Context, pagination pagination.Pagination) (int64, []*WithdrawApplication, error)
Update(ctx context.Context, applicationID string, data map[string]any) error
}