models

package
v0.0.0-...-ec88339 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2019 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotExist = errors.New("not_exist")

ErrNotExist 数据不存在

Functions

func DisconnectDB

func DisconnectDB() error

DisconnectDB 断开数据库连接

func DisconnectRedis

func DisconnectRedis() error

DisconnectRedis 断开 Redis 连接

func GetCtx

func GetCtx() (context.Context, context.CancelFunc)

GetCtx 获取并发上下文(默认10秒超时)

func InitDB

func InitDB(config *utils.DBConfig) error

InitDB 初始化数据库

func InitRedis

func InitRedis(config *utils.RedisConfig) error

InitRedis 初始化 Redis

Types

type ArticleModel

type ArticleModel struct {
	Collection *mongo.Collection
}

ArticleModel 公告文章数据库

func (*ArticleModel) AddArticle

func (m *ArticleModel) AddArticle(articleID primitive.ObjectID, title string, content string, publisher string, images []primitive.ObjectID) (id primitive.ObjectID, err error)

AddArticle 添加公告文章

func (*ArticleModel) GetArticleByID

func (m *ArticleModel) GetArticleByID(id primitive.ObjectID) (article ArticleSchemas, err error)

GetArticleByID 根据ID获取公告文章详情

func (*ArticleModel) GetArticles

func (m *ArticleModel) GetArticles(skip, limit int64) (articles []ArticleSchemas, count int64, err error)

GetArticles 获取公告列表

func (*ArticleModel) SetArticleByID

func (m *ArticleModel) SetArticleByID(id primitive.ObjectID, title, content, publisher string, images []primitive.ObjectID) (err error)

SetArticleByID 根据ID修改公告文章

type ArticleSchemas

type ArticleSchemas struct {
	ID        primitive.ObjectID   `bson:"_id,omitempty"` // ID
	ViewCount int64                `bson:"view_count"`    // 文章阅读数
	Title     string               // 文章标题
	Content   string               // 文章内容
	Publisher string               // 发布者名字
	Date      int64                // 发布时间
	Images    []primitive.ObjectID // 首页图片
}

ArticleSchemas 公告文章数据结构

type CacheModel

type CacheModel struct {
	Redis *redis.Client
}

CacheModel 缓存数据库

func (*CacheModel) CheckCertification

func (c *CacheModel) CheckCertification(userID primitive.ObjectID, email, code string, use bool) (exist bool, right bool)

CheckCertification 检查认证

func (*CacheModel) GetSessionUser

func (c *CacheModel) GetSessionUser(session string) (primitive.ObjectID, error)

GetSessionUser 获取用户ID

func (*CacheModel) GetUserBaseInfo

func (c *CacheModel) GetUserBaseInfo(id primitive.ObjectID) (UserBaseInfo, error)

GetUserBaseInfo 获取用户基本信息

func (*CacheModel) IsCollectTask

func (c *CacheModel) IsCollectTask(userID, taskID primitive.ObjectID) bool

IsCollectTask 用户是否收藏任务

func (*CacheModel) IsFollowerUser

func (c *CacheModel) IsFollowerUser(userID, otherID primitive.ObjectID) bool

IsFollowerUser 用户是否被某人关注

func (*CacheModel) IsFollowingUser

func (c *CacheModel) IsFollowingUser(userID, otherID primitive.ObjectID) bool

IsFollowingUser 用户是否已关注某人

func (*CacheModel) IsLikeComment

func (c *CacheModel) IsLikeComment(userID, commentID primitive.ObjectID) bool

IsLikeComment 用户是否点赞评论

func (*CacheModel) IsLikeTask

func (c *CacheModel) IsLikeTask(userID, taskID primitive.ObjectID) bool

IsLikeTask 用户是否点赞任务

func (*CacheModel) SetCertification

func (c *CacheModel) SetCertification(userID primitive.ObjectID, code string) error

SetCertification 设置认证

func (*CacheModel) SetSessionUser

func (c *CacheModel) SetSessionUser(session string, userID primitive.ObjectID) error

SetSessionUser 设置会话用户ID

func (*CacheModel) WillUpdate

func (c *CacheModel) WillUpdate(userID primitive.ObjectID, kind DataKind) error

WillUpdate 更新缓存数据

type CertificationStatus

type CertificationStatus string

CertificationStatus 用户认证状态

const (
	CertificationNone       CertificationStatus = "none"        // 未认证
	CertificationTrue       CertificationStatus = "true"        // 认证通过
	CertificationFalse      CertificationStatus = "false"       // 认证失败
	CertificationWait       CertificationStatus = "wait"        // 认证材料已提交,待审核
	CertificationCheckEmail CertificationStatus = "check_email" // 认证邮件已发送,待确认
	CertificationWaitEmail  CertificationStatus = "wait_email"  // 认证邮件已发确认,待审核
	CertificationCancel     CertificationStatus = "cancel"      // 认证已被用户取消
)

CertificationStatus 用户认证状态

type CommentModel

type CommentModel struct {
	Collection *mongo.Collection
}

CommentModel 评论数据库

func (*CommentModel) AddComment

func (m *CommentModel) AddComment(contentID, contentOwn, userID primitive.ObjectID, content string, isReply bool) error

AddComment 添加评论

func (*CommentModel) GetCommentByID

func (m *CommentModel) GetCommentByID(commentID primitive.ObjectID) (res CommentSchema, err error)

GetCommentByID 获取指定评论

func (*CommentModel) GetCommentsByContent

func (m *CommentModel) GetCommentsByContent(contentID primitive.ObjectID, page, size int64, sort bson.M) (res []CommentSchema, err error)

GetCommentsByContent 分页获取评论

func (*CommentModel) InsertCount

func (m *CommentModel) InsertCount(commentID primitive.ObjectID, name ContentCountType, count int64) error

InsertCount 增加计数

func (*CommentModel) RemoveContentByID

func (m *CommentModel) RemoveContentByID(commentID primitive.ObjectID) error

RemoveContentByID 删除评论

type CommentSchema

type CommentSchema struct {
	ID         primitive.ObjectID `bson:"_id,omitempty" json:"id"`        // 评论 ID
	ContentID  primitive.ObjectID `bson:"content_id" json:"content_id"`   // 被评论内容 ID [索引]
	ContentOwn primitive.ObjectID `bson:"content_own" json:"content_own"` // 被评论内容 用户 ID(冗余)
	UserID     primitive.ObjectID `bson:"user_id" json:"user_id"`         // 评论用户 ID
	ReplyCount int64              `bson:"reply_count"`                    // 回复数
	LikeCount  int64              `bson:"like_count"`                     // 点赞数(冗余)
	Content    string             `bson:"content"`                        // 评论内容
	Time       int64              `bson:"time"`                           // 评论时间
	IsDelete   bool               `bson:"is_delete"`                      // 是否已被删除
	IsReply    bool               `bson:"id_reply" json:"is_reply"`       // 是否为回复
}

CommentSchema 评论数据结构

type ContentCountType

type ContentCountType string

ContentCountType 计数内容类型

const (
	PlayerCount  ContentCountType = "player_count"  // 参与人数
	ViewCount    ContentCountType = "view_count"    // 任务浏览数
	CollectCount ContentCountType = "collect_count" // 收藏数
	CommentCount ContentCountType = "comment_count" // 评论数(冗余)
	LikeCount    ContentCountType = "like_count"    // 点赞数(冗余)
	ReplyCount   ContentCountType = "reply_count"   // 回复数
)

ContentCountType 计数内容类型

type DataKind

type DataKind string

DataKind 数据类型

const (
	KindOfLikeTask    DataKind = "like-task-"
	KindOfLikeComment DataKind = "like-comment-"
	KindOfCollectTask DataKind = "collect-task-"
	KindOfBaseInfo    DataKind = "info-"
	KindOfFollower    DataKind = "follower-"
	KindOfFollowing   DataKind = "following-"
)

DataKind 缓存数据类型

type FileModel

type FileModel struct {
	Collection *mongo.Collection
}

FileModel 文件数据库

func (*FileModel) AddFile

func (m *FileModel) AddFile(data FileSchema) error

AddFile 添加文件

func (*FileModel) BindTask

func (m *FileModel) BindTask(fileID, taskID primitive.ObjectID) error

BindTask 将文件绑定到任务中

func (*FileModel) BindUser

func (m *FileModel) BindUser(fileID primitive.ObjectID) error

BindUser 将文件标记为用户使用

func (*FileModel) GetFile

func (m *FileModel) GetFile(id primitive.ObjectID) (res FileSchema, err error)

GetFile 获取文件信息

func (*FileModel) GetFileByContent

func (m *FileModel) GetFileByContent(id primitive.ObjectID, fileType ...FileType) (res []FileSchema, err error)

GetFileByContent 获取内容相关的文件

func (*FileModel) GetFileByHash

func (m *FileModel) GetFileByHash(hash string) (file FileSchema, err error)

GetFileByHash 根据文件 Hash 值查找

func (*FileModel) GetUselessFile

func (m *FileModel) GetUselessFile(userID ...primitive.ObjectID) (files []FileSchema)

GetUselessFile 获取无用文件

func (*FileModel) RemoveFile

func (m *FileModel) RemoveFile(fileID primitive.ObjectID) error

RemoveFile 删除文件

func (*FileModel) RemoveUselessFile

func (m *FileModel) RemoveUselessFile(userID ...primitive.ObjectID) int64

RemoveUselessFile 删除无用文件

func (*FileModel) SetFileInfo

func (m *FileModel) SetFileInfo(fileID primitive.ObjectID, name, description string, public bool) error

SetFileInfo 设置文件信息

type FileSchema

type FileSchema struct {
	ID          primitive.ObjectID `bson:"_id,omitempty" json:"id"` // 文件ID[索引]
	Time        int64              // 创建时间
	Used        int                `json:"-"`                 // 引用数
	OwnerID     primitive.ObjectID `bson:"owner_id" json:"-"` // 拥有者ID[索引]
	Owner       OwnerType          `json:"-"`                 // 文件归属类型
	Type        FileType           `json:"-"`                 // 文件类型
	Name        string             // 文件名
	Description string             // 文件描述
	Size        int64              // 文件大小
	Public      bool               `json:"-"`   // 公开,非公开文件需要验证权限
	URL         string             `json:"url"` // 下载链接
	COSName     string             `json:"-"`   // 对象存储名字
	Hash        string             `json:"-"`   // 文件哈希值
}

FileSchema 文件数据结构

type FileType

type FileType string

FileType 文件类型

const (
	FileImage  FileType = "image" // 图片
	FileFile   FileType = "file"  // 文件
	FileQRCode FileType = "code"  // 二维码
)

FileType 文件类型

type FillType

type FillType string

FillType 填空类型

const (
	FillPhone  FillType = "phone"  // 手机号码
	FillNumber FillType = "number" // 数字
	FillDate   FillType = "date"   // 日期
	FillEmail  FillType = "email"  // 电子邮箱
	FillID     FillType = "id"     // 身份证
	FillWeb    FillType = "web"    // 网址
	FillFile   FillType = "file"   // 文件(用于资料征集)
	FillAll    FillType = "all"    // 不限类型
)

Fill 填空类型

type LogModel

type LogModel struct {
	Collection *mongo.Collection
}

LogModel 日志数据库

func (*LogModel) AddLog

func (m *LogModel) AddLog(userID, aboutID primitive.ObjectID, logType LogType) (primitive.ObjectID, error)

func (*LogModel) GetLog

func (m *LogModel) GetLog(userID primitive.ObjectID, logTypes []LogType,
	startDate, endDate int64, skip, limit int64) (logs []LogSchema, count int64, err error)

func (*LogModel) SetMsg

func (m *LogModel) SetMsg(id primitive.ObjectID, msg string) error

func (*LogModel) SetValue

func (m *LogModel) SetValue(id primitive.ObjectID, value int64) error

type LogSchema

type LogSchema struct {
	ID      primitive.ObjectID `bson:"_id,omitempty"` // 日志ID
	Time    int64              // 时间
	Type    LogType            // 日志类型
	UserID  primitive.ObjectID `bson:"user_id"`            // 相关用户 [索引]
	AboutID primitive.ObjectID `bson:"about_id,omitempty"` // 相关事件
	Value   int64              `bson:"value,omitempty"`    // 数值
	Msg     string             `bson:"msg,omitempty"`      // 消息
}

LogSchema 日志数据结构

type LogType

type LogType string

LogType 日志类型

const (
	LogTypeMoney  LogType = "user_money"   // 金钱变动
	LogTypeValue  LogType = "user_value"   // 用户积分变动
	LogTypeCredit LogType = "user_credit"  // 信用变动
	LogTypeLogin  LogType = "user_login"   // 用户登陆
	LogTypeClear  LogType = "system_clear" // 系统清理
	LogTypeStart  LogType = "system_start" // 系统启动
	LogTypeError  LogType = "system_error" // 系统运行时错误
)

LogType 日志类型

type MessageModel

type MessageModel struct {
	Collection *mongo.Collection
}

MessageModel 消息数据库

func (*MessageModel) AddMessage

func (m *MessageModel) AddMessage(recUser primitive.ObjectID, messageType MessageType, data MessageSchema) (primitive.ObjectID, error)

AddMessage 添加信息

func (*MessageModel) GetSessionByID

func (m *MessageModel) GetSessionByID(id primitive.ObjectID) (res SessionSchema, err error)

GetSessionByID 获取指定会话详情

func (*MessageModel) GetSessionWithMsgByID

func (m *MessageModel) GetSessionWithMsgByID(id primitive.ObjectID, page, size int64) (res SessionSchema, err error)

GetSessionWithMsgByID 获取会话详情(附带信息)

func (*MessageModel) GetSessionWithMsgByUserID

func (m *MessageModel) GetSessionWithMsgByUserID(user1, user2 primitive.ObjectID, page, size int64) (res SessionSchema, err error)

GetSessionWithMsgByID 获取会话详情(附带信息)

func (*MessageModel) GetSessionsByUser

func (m *MessageModel) GetSessionsByUser(userID primitive.ObjectID, page, size int64) (res []SessionSchema)

GetSessionsByUser 获取会话列表

func (*MessageModel) ReadMessage

func (m *MessageModel) ReadMessage(sessionID primitive.ObjectID, firstUser bool) error

ReadMessage 标记信息为已读

type MessageSchema

type MessageSchema struct {
	UserID  primitive.ObjectID `bson:"user" json:"user_id"` // 消息发言人ID
	Time    int64              `bson:"time"`                // 发送时间
	Title   string             `bson:"title,omitempty"`     // 消息标题 (系统通知/任务通知)
	Content string             `bson:"content"`             // 消息内容
	About   primitive.ObjectID `bson:"about,omitempty"`     // 相关ID (被评论的任务)
}

MessageSchema 消息数据结构

type MessageType

type MessageType string

MessageType 消息类型

const (
	MessageTypeChat    MessageType = "chat"    // 聊天
	MessageTypeSystem  MessageType = "system"  // 系统通知
	MessageTypeTask    MessageType = "task"    // 任务通知
	MessageTypeComment MessageType = "comment" // 评论通知
)

MessageType 消息类型

type Model

type Model struct {

	// 数据库实例
	Log           *LogModel
	Article       *ArticleModel
	Comment       *CommentModel
	Message       *MessageModel
	Questionnaire *QuestionnaireModel
	Task          *TaskModel
	TaskStatus    *TaskStatusModel
	User          *UserModel
	File          *FileModel
	Set           *SetModel
	System        *SystemModel
	// contains filtered or unexported fields
}

Model 数据库实例

func GetModel

func GetModel() *Model

GetModel 获取 Model 实例

type OwnerType

type OwnerType string

OwnerType 文件归属类型

const (
	FileForUser OwnerType = "user" // 用户文件,非公开内容仅用户本人查看[认证材料、问卷/数据征集提交内容]
	FileForTask OwnerType = "task" // 任务文件,非公开内容仅任务参与者查看[任务附件/图片]
)

OwnerType 文件归属类型

type PlayerStatus

type PlayerStatus string

PlayerStatus 参与用户状态

const (
	PlayerWait    PlayerStatus = "wait"    // 等待同意加入
	PlayerRefuse  PlayerStatus = "refuse"  // 拒绝加入
	PlayerClose   PlayerStatus = "close"   // 发布者关闭任务
	PlayerRunning PlayerStatus = "running" // 用户进行中
	PlayerFinish  PlayerStatus = "finish"  // 用户已完成
	PlayerGiveUp  PlayerStatus = "give_up" // 用户已放弃
	PlayerFailure PlayerStatus = "failure" // 任务失败
)

PlayerStatus 参与用户状态

type ProblemDataSchema

type ProblemDataSchema struct {
	ProblemIndex int                `bson:"problem_index" json:"problem_index"`                   // 题目序号
	StringValue  string             `bson:"string_value,omitempty" json:"string_value,omitempty"` // 填空题
	ChooseValue  []int              `bson:"choose_value,omitempty" json:"choose_value,omitempty"` // 选择题、矩阵题、排序题数据
	ScoreValue   int                `bson:"score_value,omitempty" json:"score_value,omitempty"`   // 评分题数据
	FileValue    primitive.ObjectID `bson:"file_value,omitempty" json:"file_value,omitempty"`     // 文件题数据
}

ProblemDataSchema 问题数据

type ProblemSchema

type ProblemSchema struct {
	Index   int64       // 题号
	Content string      // 问题本体
	Note    string      // 问题备注
	Type    ProblemType // 问题类型

	// 选择题数据
	ChooseProblem struct {
		Options []struct {
			Index   int64  // 选项序号
			Content string // 选项内容
		} // 问题选项
		MaxChoose int64 `bson:"max_choose" json:"max_choose"` // 最大可选项
	} `bson:"choose_problem,omitempty" json:"choose_problem,omitempty"`

	// 填空题数据
	FillProblem struct {
		Type      FillType `bson:"type"`                                    // 填空类型
		MultiLine bool     `bson:"multi_line, omitempty" json:"multi_line"` // 是否多行
		MaxWord   int64    `bson:"max_word, omitempty" json:"max_word"`     // 最大字数
	} `bson:"fill_problem, omitempty" json:"fill_problem,omitempty"`

	// 评分题
	ScoreProblem struct {
		MinText string `bson:"min_text" json:"min_text"` // 低分描述(如:不满意,不重要,不愿意)
		MaxText string `bson:"max_text" json:"max_text"` // 高分描述
		Score   int64  `bson:"score"`                    // 评分级别 1-x (最高为10)
	} `bson:"score_problem, omitempty" json:"score_problem,omitempty"`

	// 矩阵题
	MatrixProblem struct {
		Content []string // 题目
		Options []string // 选项
	} `bson:"matrix_problem, omitempty" json:"matrix_problem,omitempty"`

	// 排序题
	SortProblem struct {
		SortItem []struct {
			Index   int64  // 选项序号
			Content string // 选项内容
		} `bson:"sort_item" json:"sort_item"`
	} `bson:"sort_problem, omitempty" json:"sort_problem,omitempty"`
}

ProblemSchema 问卷问题

type ProblemType

type ProblemType string

ProblemType 问题类型

const (
	ProblemNone   ProblemType = "none"   // 纯文字描述
	ProblemChoose ProblemType = "choose" // 选择题
	ProblemMatrix ProblemType = "matrix" // 矩阵题
	ProblemFill   ProblemType = "fill"   // 填空题
	ProblemScore  ProblemType = "score"  // 评分题
	ProblemSort   ProblemType = "sort"   // 排序题
)

ProblemType 问题类型

type QuestionnaireModel

type QuestionnaireModel struct {
	Collection *mongo.Collection
}

QuestionnaireModel 问卷数据库

func (*QuestionnaireModel) AddAnswer

func (model *QuestionnaireModel) AddAnswer(id primitive.ObjectID, statistics StatisticsSchema) (err error)

AddAnswer 添加新回答

func (*QuestionnaireModel) AddQuestionnaire

func (model *QuestionnaireModel) AddQuestionnaire(info QuestionnaireSchema) (primitive.ObjectID, error)

AddQuestionnaire 添加问卷

func (*QuestionnaireModel) GetAnswerByUserID

func (model *QuestionnaireModel) GetAnswerByUserID(id, userID primitive.ObjectID) (StatisticsSchema, error)

GetAnswerByUserID 根据用户获取答案

func (*QuestionnaireModel) GetQuestionnaireAnswersByID

func (model *QuestionnaireModel) GetQuestionnaireAnswersByID(id primitive.ObjectID) (answers []StatisticsSchema, err error)

GetQuestionnaireAnswersByID 获取问卷答案数据

func (*QuestionnaireModel) GetQuestionnaireInfoByID

func (model *QuestionnaireModel) GetQuestionnaireInfoByID(id primitive.ObjectID) (questionnaire QuestionnaireSchema, err error)

GetQuestionnaireInfoByID 获取问卷信息

func (*QuestionnaireModel) GetQuestionnaireQuestionsByID

func (model *QuestionnaireModel) GetQuestionnaireQuestionsByID(id primitive.ObjectID) (problems []ProblemSchema, err error)

GetQuestionnaireQuestionsByID 获取问卷问题

func (*QuestionnaireModel) SetQuestionnaireInfoByID

func (model *QuestionnaireModel) SetQuestionnaireInfoByID(id primitive.ObjectID, info QuestionnaireSchema) (err error)

SetQuestionnaireInfoByID 设置问卷信息

func (*QuestionnaireModel) SetQuestionnaireQuestionsByID

func (model *QuestionnaireModel) SetQuestionnaireQuestionsByID(id primitive.ObjectID, questions []ProblemSchema) (err error)

SetQuestionnaireQuestionsByID 修改问卷问题

type QuestionnaireSchema

type QuestionnaireSchema struct {
	TaskID primitive.ObjectID `bson:"_id"` // 问卷所属任务ID [索引]

	Title       string             `bson:"title"`       // 问卷标题
	Description string             `bson:"description"` // 问卷描述
	Owner       primitive.ObjectID `bson:"owner"`       // 问卷创建者(冗余)
	Anonymous   bool               `bson:"anonymous"`   // 匿名收集
	Problems    []ProblemSchema    `bson:"problems"`    // 问卷问题
	Data        []StatisticsSchema `bson:"data"`        // 问题统计数据
}

QuestionnaireSchema 问卷数据结构

type Redis

type Redis struct {
	Client *redis.Client
	Cache  *CacheModel
}

Redis 缓存

func GetRedis

func GetRedis() *Redis

GetRedis 获取缓存实例

type RewardType

type RewardType string

RewardType 酬劳类型

const (
	RewardMoney  RewardType = "money"  // 闲钱币酬劳
	RewardRMB    RewardType = "rmb"    // 人民币酬劳
	RewardObject RewardType = "object" // 实物酬劳
)

RewardType 酬劳类型

type SessionSchema

type SessionSchema struct {
	ID          primitive.ObjectID `bson:"_id,omitempty" json:"id"`  // 消息会话ID
	User1       primitive.ObjectID `bson:"user_1" json:"user_1"`     // 用户1 [索引]
	User2       primitive.ObjectID `bson:"user_2" json:"user_2"`     // 用户2/任务ID [索引]
	Unread1     int64              `bson:"unread_1" json:"unread_1"` // 用户1 未读消息数量
	Unread2     int64              `bson:"unread_2" json:"unread_2"` // 用户2 未读消息数量
	Type        MessageType        `bson:"type"`                     // 会话类型
	LastMessage MessageSchema      `bson:"last_message"`             // 最新的消息[冗余]
	Messages    []MessageSchema    `bson:"messages" json:"messages"` // 消息内容
}

SessionSchema Session 数据结构 bson 默认为名字小写

type SetKind

type SetKind string

SetKind 集合类型

const (
	SetOfLikeTask      SetKind = "like_task_id"
	SetOfLikeComment   SetKind = "like_comment_id"
	SetOfCollectTask   SetKind = "collect_task_id"
	SetOfFollowingUser SetKind = "following_user_id"
	SetOfFollowerUser  SetKind = "follower_user_id"
)

SetKind 集合类型

type SetModel

type SetModel struct {
	Collection *mongo.Collection
}

SetModel 集合数据库

func (*SetModel) AddToSet

func (m *SetModel) AddToSet(userID, targetID primitive.ObjectID, kind SetKind) error

AddToSet 添加到集合

func (*SetModel) GetSets

func (m *SetModel) GetSets(userID primitive.ObjectID, kind SetKind) (set SetSchemas)

GetSets 获取集合

func (*SetModel) RemoveFromSet

func (m *SetModel) RemoveFromSet(userID, targetID primitive.ObjectID, kind SetKind) error

RemoveFromSet 从集合中移除

type SetSchemas

type SetSchemas struct {
	UserID          primitive.ObjectID   `bson:"_id"`               // 用户 ID
	LikeTaskID      []primitive.ObjectID `bson:"like_task_id"`      // 点赞的任务 ID
	LikeCommentID   []primitive.ObjectID `bson:"like_comment_id"`   // 点赞的评论 ID
	CollectTaskID   []primitive.ObjectID `bson:"collect_task_id"`   // 收藏的任务 ID
	FollowingUserID []primitive.ObjectID `bson:"following_user_id"` // 关注用户 ID
	FollowerUserID  []primitive.ObjectID `bson:"follower_user_id"`  // 粉丝用户 ID
}

SetSchemas 集合数据结构

type StatisticsSchema

type StatisticsSchema struct {
	UserID   primitive.ObjectID  `bson:"user_id" json:"user_id"` // 填写用户ID
	Data     []ProblemDataSchema // 问题答案
	Time     int64               // 提交时间
	Duration int64               // 花费时间(秒)
	IP       string              `bson:"ip" json:"ip"` // 提交 IP 地址
}

StatisticsSchema 用户填写数据

type SystemModel

type SystemModel struct {
	Collection *mongo.Collection
}

SystemModel 系统 数据库

func (*SystemModel) AddAutoEmail

func (m *SystemModel) AddAutoEmail(email, data string) error

AddAutoEmail 添加自动认证

func (*SystemModel) ExistAutoEmail

func (m *SystemModel) ExistAutoEmail(email string) string

ExistAutoEmail 是否存在自动认证

func (*SystemModel) GetAutoEmail

func (m *SystemModel) GetAutoEmail(page, size int64) (res []SystemSchemas, err error)

GetAutoEmail 获取自动认证后缀

func (*SystemModel) RemoveAutoEmail

func (m *SystemModel) RemoveAutoEmail(email string) error

RemoveAutoEmail 移除自动认证

type SystemSchemas

type SystemSchemas struct {
	ID    primitive.ObjectID `bson:"_id,omitempty"` // ID
	Key   string             // 信息名称
	Value string             // 信息内容
}

SystemSchemas 系统数据 存储一些系统信息,管理信息 键值对

type TaskModel

type TaskModel struct {
	Collection *mongo.Collection
}

TaskModel Task 任务 数据库

func (*TaskModel) AddTask

func (m *TaskModel) AddTask(taskID, publisherID primitive.ObjectID, status TaskStatus) (primitive.ObjectID, error)

AddTask 添加任务

func (*TaskModel) GetTaskByID

func (m *TaskModel) GetTaskByID(id primitive.ObjectID) (task TaskSchema, err error)

GetTaskByID 获取用户

func (*TaskModel) GetTasks

func (m *TaskModel) GetTasks(sort string, taskIDs []primitive.ObjectID, taskTypes []TaskType,
	statuses []TaskStatus, rewards []RewardType, keywords []string, user string, skip, limit int64) (tasks []TaskSchema, count int64, err error)

GetTasks 获取任务列表,需要按类型/状态/酬劳类型筛选,按关键词搜索,按不同规则排序

func (*TaskModel) GetTasksByIDs

func (m *TaskModel) GetTasksByIDs(taskIDs []primitive.ObjectID) (tasks []TaskSchema, err error)

GetTasksByIDs 根据多个ID获取任务列表

func (*TaskModel) InsertCount

func (m *TaskModel) InsertCount(taskID primitive.ObjectID, name ContentCountType, count int) error

InsertCount 增加计数

func (*TaskModel) RemoveTask

func (m *TaskModel) RemoveTask(taskID primitive.ObjectID) error

RemoveTask 删除任务

func (*TaskModel) SetTaskInfoByID

func (m *TaskModel) SetTaskInfoByID(id primitive.ObjectID, info TaskSchema) error

SetTaskInfoByID 设置任务信息

type TaskSchema

type TaskSchema struct {
	ID        primitive.ObjectID `bson:"_id,omitempty" json:"id"` // 任务ID
	Publisher primitive.ObjectID `bson:"publisher"`               // 任务发布者 [索引]

	Title    string     `bson:"title"`    // 任务名称
	Type     TaskType   `bson:"type"`     // 任务类型
	Content  string     `bson:"content"`  // 任务内容
	Status   TaskStatus `bson:"status"`   // 任务状态
	Location []string   `bson:"location"` // 任务地点 (非问卷类任务)
	Tags     []string   `bson:"tags"`     // 标签 (作为关键词,改进搜索体验)
	TopTime  int64      `bson:"top_time"` // 置顶时间(默认为0),如果当前时间小于置顶时间,即将任务置顶

	Reward       RewardType `bson:"reward"`        // 酬劳类型
	RewardValue  float32    `bson:"reward_value"`  // 酬劳数值
	RewardObject string     `bson:"reward_object"` // 酬劳物体

	PublishDate int64 `bson:"publish_date"` // 任务发布时间
	StartDate   int64 `bson:"start_date"`   // 任务开始时间
	EndDate     int64 `bson:"end_date"`     // 任务结束时间

	PlayerCount int64 `bson:"player_count"` // 参与的用户(冗余)
	MaxPlayer   int64 `bson:"max_player"`   // 参与用户上限, -1为无限制
	AutoAccept  bool  `bson:"auto_accept"`  // 自动同意领取任务

	ViewCount    int64 `bson:"view_count"`    // 任务浏览数
	CollectCount int64 `bson:"collect_count"` // 收藏数(冗余)
	CommentCount int64 `bson:"comment_count"` // 评论数(冗余)
	LikeCount    int64 `bson:"like_count"`    // 点赞数(冗余)

	// 由[浏览量、评论数、收藏数、参与人数、时间、置顶、酬劳、发布者粉丝、信用]等数据加权计算,10分钟更新一次,用于排序
	Hot int64 `bson:"hot"` // 任务热度
}

TaskSchema Task 基本数据结构

type TaskStatus

type TaskStatus string

TaskStatus 任务状态

const (
	TaskStatusDraft  TaskStatus = "draft"  // 草稿
	TaskStatusWait   TaskStatus = "wait"   // 等待接受
	TaskStatusClose  TaskStatus = "close"  // 已关闭
	TaskStatusFinish TaskStatus = "finish" // 已完成
)

TaskStatus 任务状态

type TaskStatusModel

type TaskStatusModel struct {
	Collection *mongo.Collection
}

TaskStatusModel 接受的任务状态数据库

func (*TaskStatusModel) AddTaskStatus

func (m *TaskStatusModel) AddTaskStatus(taskID, userID primitive.ObjectID, status PlayerStatus, note string) error

AddTaskStatus 添加任务状态

func (*TaskStatusModel) DeleteTaskStatus

func (m *TaskStatusModel) DeleteTaskStatus(id primitive.ObjectID) error

DeleteTaskStatus 删除任务状态

func (*TaskStatusModel) GetTaskStatus

func (m *TaskStatusModel) GetTaskStatus(userID, taskID primitive.ObjectID) (taskStatus TaskStatusSchema, err error)

GetTaskStatus 获取任务状态

func (*TaskStatusModel) GetTaskStatusListByTaskID

func (m *TaskStatusModel) GetTaskStatusListByTaskID(taskID primitive.ObjectID, status []PlayerStatus, skip, limit int64) (taskStatusList []TaskStatusSchema, count int64, err error)

GetTaskStatusListByTaskID 获取任务状态列表

func (*TaskStatusModel) GetTaskStatusListByUserID

func (m *TaskStatusModel) GetTaskStatusListByUserID(userID primitive.ObjectID, status []PlayerStatus, skip, limit int64) (taskStatusList []TaskStatusSchema, count int64, err error)

GetTaskStatusListByUserID 获取用户任务状态列表

func (*TaskStatusModel) SetTaskStatus

func (m *TaskStatusModel) SetTaskStatus(id primitive.ObjectID, info TaskStatusSchema) error

SetTaskStatus 设置任务状态

type TaskStatusSchema

type TaskStatusSchema struct {
	ID     primitive.ObjectID `bson:"_id,omitempty" json:"id"` // 任务状态ID
	Task   primitive.ObjectID `bson:"task"`                    // 任务 ID [索引]
	Player primitive.ObjectID `bson:"player"`                  // 用户 ID [索引]
	Status PlayerStatus       `bson:"status"`                  // 状态
	Note   string             `bson:"note"`                    // 申请备注
	// 完成后的评价
	Degree int    `bson:"degree"` // 完成度
	Remark string `bson:"remark"` // 评语
	// 用户的反馈
	Score    int    `bson:"score"`    // 五星好评
	Feedback string `bson:"feedback"` // 反馈
}

TaskStatusSchema 接受的任务状态 基本数据结构 bson 默认为名字小写

type TaskType

type TaskType string

TaskType 任务类型

const (
	TaskTypeRunning       TaskType = "run"           // 跑腿任务
	TaskTypeQuestionnaire TaskType = "questionnaire" // 问卷任务
	TaskTypeInfo          TaskType = "info"          // 信息任务
)

TaskType 任务类型

type UserBaseInfo

type UserBaseInfo struct {
	ID       string `json:"id"`
	Nickname string
	Avatar   string
	Gender   UserGender
	Type     UserType
}

UserBaseInfo 用户基本信息数据

type UserCertificationSchema

type UserCertificationSchema struct {
	Identity UserIdentity         `bson:"identity"` // 认证身份类型
	Data     string               `bson:"data"`     // 认证内容
	Status   CertificationStatus  `bson:"status"`   // 认证状态
	Date     int64                `bson:"date"`     // 认证时间
	Material []primitive.ObjectID `bson:"material"` // 人工认证材料
	Feedback string               `bson:"feedback"` // 审核不通过后的反馈
	Email    string               `bson:"email"`    // 邮箱认证
}

UserCertificationSchema 用户认证信息

type UserDataCount

type UserDataCount struct {
	Money           int64 `bson:"money"`             // 当前持有闲币
	Value           int64 `bson:"value"`             // 用户积分
	Credit          int64 `bson:"credit"`            // 个人信誉
	PublishCount    int64 `bson:"publish_count"`     // 发布任务数
	PublishRunCount int64 `bson:"publish_run_count"` // 发布并进行中任务数
	ReceiveCount    int64 `bson:"receive_count"`     // 领取任务数
	ReceiveRunCount int64 `bson:"receive_run_count"` // 领取并进行中任务数
	FollowingCount  int64 `bson:"following_count"`   // 关注人数量
	FollowerCount   int64 `bson:"follower_count"`    // 粉丝数量
}

UserDataCount 用户数据更新

type UserDataSchema

type UserDataSchema struct {
	Money  int64    // 当前持有闲币
	Value  int64    // 用户积分
	Credit int64    // 个人信誉
	Type   UserType // 用户类型

	AttendanceDate int64    `bson:"attendance_date"` // 签到时间戳
	SearchHistory  []string `bson:"search_history"`  // 搜索历史(仅保留最近的 20 条)
	// 冗余数据
	PublishCount    int64 `bson:"publish_count"`     // 发布任务数
	PublishRunCount int64 `bson:"publish_run_count"` // 发布并进行中任务数
	ReceiveCount    int64 `bson:"receive_count"`     // 领取任务数
	ReceiveRunCount int64 `bson:"receive_run_count"` // 领取并进行中任务数
	FollowingCount  int64 `bson:"following_count"`   // 关注人数量
	FollowerCount   int64 `bson:"follower_count"`    // 粉丝数量
}

UserDataSchema 用户数据结构

type UserGender

type UserGender string

UserGender 用户性别

const (
	GenderMan   UserGender = "man"   // 男
	GenderWoman UserGender = "woman" // 女
	GenderOther UserGender = "other" // 其他
)

UserGender 用户性别

type UserIdentity

type UserIdentity string

UserIdentity 用户认证身份

const (
	IdentityNone    UserIdentity = "none"    // 未认证
	IdentityStudent UserIdentity = "student" // 目前仅支持学生认证
)

UserIdentity 用户认证身份

type UserInfoSchema

type UserInfoSchema struct {
	Email    string     `bson:"email"`    // 联系邮箱
	Phone    string     `bson:"phone"`    // 联系手机
	Avatar   string     `bson:"avatar"`   // 头像
	School   string     `bson:"school"`   // 学校
	Nickname string     `bson:"nickname"` // 用户昵称
	Bio      string     `bson:"bio"`      // 个人简介
	Gender   UserGender `bson:"gender"`   // 性别
	Location string     `bson:"location"` // 具体位置
	Birthday int64      `bson:"birthday"` // 生日
}

UserInfoSchema 用户信息结构

type UserModel

type UserModel struct {
	Collection *mongo.Collection
}

UserModel User 数据库

func (*UserModel) AddSearchHistory

func (m *UserModel) AddSearchHistory(id primitive.ObjectID, key string) error

AddSearchHistory 添加搜索历史

func (*UserModel) AddUserByViolet

func (m *UserModel) AddUserByViolet(id string) (primitive.ObjectID, error)

AddUserByViolet 通过 Violet 增加用户

func (*UserModel) AddUserByWechat

func (m *UserModel) AddUserByWechat(openid string) (primitive.ObjectID, error)

AddUserByWechat 通过微信添加用户

func (*UserModel) CheckCertificationEmail

func (m *UserModel) CheckCertificationEmail(email string) bool

CheckCertificationEmail 该邮箱是否存在认证

func (*UserModel) ClearSearchHistory

func (m *UserModel) ClearSearchHistory(id primitive.ObjectID) error

ClearSearchHistory 清空搜索历史

func (*UserModel) GetAllUser

func (m *UserModel) GetAllUser() (res []primitive.ObjectID)

GetAllUser 获取所有用户ID

func (*UserModel) GetCertification

func (m *UserModel) GetCertification(status []CertificationStatus, page, size int64) (res []UserSchema, err error)

GetCertification 获取认证

func (*UserModel) GetSearchHistory

func (m *UserModel) GetSearchHistory(id primitive.ObjectID) ([]string, error)

GetSearchHistory 获取用户搜索历史

func (*UserModel) GetUserByID

func (m *UserModel) GetUserByID(id primitive.ObjectID) (user UserSchema, err error)

GetUserByID 通过 ID 查找用户

func (*UserModel) GetUserByViolet

func (m *UserModel) GetUserByViolet(id string) (user UserSchema, err error)

GetUserByViolet 通过 VioletID 查找用户

func (*UserModel) GetUserByWechat

func (m *UserModel) GetUserByWechat(id string) (user UserSchema, err error)

GetUserByWechat 通过 Wechat OpenID 查找用户

func (*UserModel) GetUsers

func (m *UserModel) GetUsers(key string, page, size int64) (res []UserSchema)

GetUsers 按关键字搜索用户

func (*UserModel) SetUserAttend

func (m *UserModel) SetUserAttend(id primitive.ObjectID) error

SetUserAttend 用户签到

func (*UserModel) SetUserCertification

func (m *UserModel) SetUserCertification(id primitive.ObjectID, data UserCertificationSchema) error

SetUserCertification 设置用户认证信息

func (*UserModel) SetUserInfoByID

func (m *UserModel) SetUserInfoByID(id primitive.ObjectID, info UserInfoSchema) error

SetUserInfoByID 更新用户个人信息

func (*UserModel) SetUserType

func (m *UserModel) SetUserType(id primitive.ObjectID, userType UserType) error

SetUserType 设置用户类型

func (*UserModel) UpdateUserDataCount

func (m *UserModel) UpdateUserDataCount(id primitive.ObjectID, data UserDataCount) error

UpdateUserDataCount 更新用户数值数据(偏移值)

type UserSchema

type UserSchema struct {
	ID            primitive.ObjectID      `bson:"_id,omitempty"` // 用户ID [索引]
	WechatID      string                  `bson:"wechat_id"`     // 微信OpenID
	WechatName    string                  `bson:"wechat_name"`   // 微信名
	VioletID      string                  `bson:"violet_id"`     // VioletID
	VioletName    string                  `bson:"violet_name"`   // Violet 用户名
	RegisterTime  int64                   `bson:"register_time"` // 用户注册时间
	Info          UserInfoSchema          `bson:"info"`          // 用户个性信息
	Data          UserDataSchema          `bson:"data"`          // 用户数据
	Certification UserCertificationSchema `bson:"certification"` // 用户认证信息
}

UserSchema User 基本数据结构

type UserType

type UserType string

UserType 用户类型

const (
	UserTypeBan    UserType = "ban"    // 禁封用户
	UserTypeNormal UserType = "normal" // 正式用户
	UserTypeAdmin  UserType = "admin"  // 管理员
	UserTypeRoot   UserType = "root"   // 超级管理员
)

UserType 用户类型

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL